libvhost-user: fix crash when rings aren't ready
[qemu/ar7.git] / tcg / sparc / tcg-target.inc.c
blob3785d77f627f0602507e633d7a768cf33a1a7001
1 /*
2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "tcg-be-null.h"
27 #ifdef CONFIG_DEBUG_TCG
28 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
29 "%g0",
30 "%g1",
31 "%g2",
32 "%g3",
33 "%g4",
34 "%g5",
35 "%g6",
36 "%g7",
37 "%o0",
38 "%o1",
39 "%o2",
40 "%o3",
41 "%o4",
42 "%o5",
43 "%o6",
44 "%o7",
45 "%l0",
46 "%l1",
47 "%l2",
48 "%l3",
49 "%l4",
50 "%l5",
51 "%l6",
52 "%l7",
53 "%i0",
54 "%i1",
55 "%i2",
56 "%i3",
57 "%i4",
58 "%i5",
59 "%i6",
60 "%i7",
62 #endif
64 #ifdef __arch64__
65 # define SPARC64 1
66 #else
67 # define SPARC64 0
68 #endif
70 /* Note that sparcv8plus can only hold 64 bit quantities in %g and %o
71 registers. These are saved manually by the kernel in full 64-bit
72 slots. The %i and %l registers are saved by the register window
73 mechanism, which only allocates space for 32 bits. Given that this
74 window spill/fill can happen on any signal, we must consider the
75 high bits of the %i and %l registers garbage at all times. */
76 #if SPARC64
77 # define ALL_64 0xffffffffu
78 #else
79 # define ALL_64 0xffffu
80 #endif
82 /* Define some temporary registers. T2 is used for constant generation. */
83 #define TCG_REG_T1 TCG_REG_G1
84 #define TCG_REG_T2 TCG_REG_O7
86 #ifndef CONFIG_SOFTMMU
87 # define TCG_GUEST_BASE_REG TCG_REG_I5
88 #endif
90 static const int tcg_target_reg_alloc_order[] = {
91 TCG_REG_L0,
92 TCG_REG_L1,
93 TCG_REG_L2,
94 TCG_REG_L3,
95 TCG_REG_L4,
96 TCG_REG_L5,
97 TCG_REG_L6,
98 TCG_REG_L7,
100 TCG_REG_I0,
101 TCG_REG_I1,
102 TCG_REG_I2,
103 TCG_REG_I3,
104 TCG_REG_I4,
105 TCG_REG_I5,
107 TCG_REG_G2,
108 TCG_REG_G3,
109 TCG_REG_G4,
110 TCG_REG_G5,
112 TCG_REG_O0,
113 TCG_REG_O1,
114 TCG_REG_O2,
115 TCG_REG_O3,
116 TCG_REG_O4,
117 TCG_REG_O5,
120 static const int tcg_target_call_iarg_regs[6] = {
121 TCG_REG_O0,
122 TCG_REG_O1,
123 TCG_REG_O2,
124 TCG_REG_O3,
125 TCG_REG_O4,
126 TCG_REG_O5,
129 static const int tcg_target_call_oarg_regs[] = {
130 TCG_REG_O0,
131 TCG_REG_O1,
132 TCG_REG_O2,
133 TCG_REG_O3,
136 #define INSN_OP(x) ((x) << 30)
137 #define INSN_OP2(x) ((x) << 22)
138 #define INSN_OP3(x) ((x) << 19)
139 #define INSN_OPF(x) ((x) << 5)
140 #define INSN_RD(x) ((x) << 25)
141 #define INSN_RS1(x) ((x) << 14)
142 #define INSN_RS2(x) (x)
143 #define INSN_ASI(x) ((x) << 5)
145 #define INSN_IMM10(x) ((1 << 13) | ((x) & 0x3ff))
146 #define INSN_IMM11(x) ((1 << 13) | ((x) & 0x7ff))
147 #define INSN_IMM13(x) ((1 << 13) | ((x) & 0x1fff))
148 #define INSN_OFF16(x) ((((x) >> 2) & 0x3fff) | ((((x) >> 16) & 3) << 20))
149 #define INSN_OFF19(x) (((x) >> 2) & 0x07ffff)
150 #define INSN_COND(x) ((x) << 25)
152 #define COND_N 0x0
153 #define COND_E 0x1
154 #define COND_LE 0x2
155 #define COND_L 0x3
156 #define COND_LEU 0x4
157 #define COND_CS 0x5
158 #define COND_NEG 0x6
159 #define COND_VS 0x7
160 #define COND_A 0x8
161 #define COND_NE 0x9
162 #define COND_G 0xa
163 #define COND_GE 0xb
164 #define COND_GU 0xc
165 #define COND_CC 0xd
166 #define COND_POS 0xe
167 #define COND_VC 0xf
168 #define BA (INSN_OP(0) | INSN_COND(COND_A) | INSN_OP2(0x2))
170 #define RCOND_Z 1
171 #define RCOND_LEZ 2
172 #define RCOND_LZ 3
173 #define RCOND_NZ 5
174 #define RCOND_GZ 6
175 #define RCOND_GEZ 7
177 #define MOVCC_ICC (1 << 18)
178 #define MOVCC_XCC (1 << 18 | 1 << 12)
180 #define BPCC_ICC 0
181 #define BPCC_XCC (2 << 20)
182 #define BPCC_PT (1 << 19)
183 #define BPCC_PN 0
184 #define BPCC_A (1 << 29)
186 #define BPR_PT BPCC_PT
188 #define ARITH_ADD (INSN_OP(2) | INSN_OP3(0x00))
189 #define ARITH_ADDCC (INSN_OP(2) | INSN_OP3(0x10))
190 #define ARITH_AND (INSN_OP(2) | INSN_OP3(0x01))
191 #define ARITH_ANDN (INSN_OP(2) | INSN_OP3(0x05))
192 #define ARITH_OR (INSN_OP(2) | INSN_OP3(0x02))
193 #define ARITH_ORCC (INSN_OP(2) | INSN_OP3(0x12))
194 #define ARITH_ORN (INSN_OP(2) | INSN_OP3(0x06))
195 #define ARITH_XOR (INSN_OP(2) | INSN_OP3(0x03))
196 #define ARITH_SUB (INSN_OP(2) | INSN_OP3(0x04))
197 #define ARITH_SUBCC (INSN_OP(2) | INSN_OP3(0x14))
198 #define ARITH_ADDC (INSN_OP(2) | INSN_OP3(0x08))
199 #define ARITH_SUBC (INSN_OP(2) | INSN_OP3(0x0c))
200 #define ARITH_UMUL (INSN_OP(2) | INSN_OP3(0x0a))
201 #define ARITH_SMUL (INSN_OP(2) | INSN_OP3(0x0b))
202 #define ARITH_UDIV (INSN_OP(2) | INSN_OP3(0x0e))
203 #define ARITH_SDIV (INSN_OP(2) | INSN_OP3(0x0f))
204 #define ARITH_MULX (INSN_OP(2) | INSN_OP3(0x09))
205 #define ARITH_UDIVX (INSN_OP(2) | INSN_OP3(0x0d))
206 #define ARITH_SDIVX (INSN_OP(2) | INSN_OP3(0x2d))
207 #define ARITH_MOVCC (INSN_OP(2) | INSN_OP3(0x2c))
208 #define ARITH_MOVR (INSN_OP(2) | INSN_OP3(0x2f))
210 #define ARITH_ADDXC (INSN_OP(2) | INSN_OP3(0x36) | INSN_OPF(0x11))
211 #define ARITH_UMULXHI (INSN_OP(2) | INSN_OP3(0x36) | INSN_OPF(0x16))
213 #define SHIFT_SLL (INSN_OP(2) | INSN_OP3(0x25))
214 #define SHIFT_SRL (INSN_OP(2) | INSN_OP3(0x26))
215 #define SHIFT_SRA (INSN_OP(2) | INSN_OP3(0x27))
217 #define SHIFT_SLLX (INSN_OP(2) | INSN_OP3(0x25) | (1 << 12))
218 #define SHIFT_SRLX (INSN_OP(2) | INSN_OP3(0x26) | (1 << 12))
219 #define SHIFT_SRAX (INSN_OP(2) | INSN_OP3(0x27) | (1 << 12))
221 #define RDY (INSN_OP(2) | INSN_OP3(0x28) | INSN_RS1(0))
222 #define WRY (INSN_OP(2) | INSN_OP3(0x30) | INSN_RD(0))
223 #define JMPL (INSN_OP(2) | INSN_OP3(0x38))
224 #define RETURN (INSN_OP(2) | INSN_OP3(0x39))
225 #define SAVE (INSN_OP(2) | INSN_OP3(0x3c))
226 #define RESTORE (INSN_OP(2) | INSN_OP3(0x3d))
227 #define SETHI (INSN_OP(0) | INSN_OP2(0x4))
228 #define CALL INSN_OP(1)
229 #define LDUB (INSN_OP(3) | INSN_OP3(0x01))
230 #define LDSB (INSN_OP(3) | INSN_OP3(0x09))
231 #define LDUH (INSN_OP(3) | INSN_OP3(0x02))
232 #define LDSH (INSN_OP(3) | INSN_OP3(0x0a))
233 #define LDUW (INSN_OP(3) | INSN_OP3(0x00))
234 #define LDSW (INSN_OP(3) | INSN_OP3(0x08))
235 #define LDX (INSN_OP(3) | INSN_OP3(0x0b))
236 #define STB (INSN_OP(3) | INSN_OP3(0x05))
237 #define STH (INSN_OP(3) | INSN_OP3(0x06))
238 #define STW (INSN_OP(3) | INSN_OP3(0x04))
239 #define STX (INSN_OP(3) | INSN_OP3(0x0e))
240 #define LDUBA (INSN_OP(3) | INSN_OP3(0x11))
241 #define LDSBA (INSN_OP(3) | INSN_OP3(0x19))
242 #define LDUHA (INSN_OP(3) | INSN_OP3(0x12))
243 #define LDSHA (INSN_OP(3) | INSN_OP3(0x1a))
244 #define LDUWA (INSN_OP(3) | INSN_OP3(0x10))
245 #define LDSWA (INSN_OP(3) | INSN_OP3(0x18))
246 #define LDXA (INSN_OP(3) | INSN_OP3(0x1b))
247 #define STBA (INSN_OP(3) | INSN_OP3(0x15))
248 #define STHA (INSN_OP(3) | INSN_OP3(0x16))
249 #define STWA (INSN_OP(3) | INSN_OP3(0x14))
250 #define STXA (INSN_OP(3) | INSN_OP3(0x1e))
252 #define MEMBAR (INSN_OP(2) | INSN_OP3(0x28) | INSN_RS1(15) | (1 << 13))
254 #ifndef ASI_PRIMARY_LITTLE
255 #define ASI_PRIMARY_LITTLE 0x88
256 #endif
258 #define LDUH_LE (LDUHA | INSN_ASI(ASI_PRIMARY_LITTLE))
259 #define LDSH_LE (LDSHA | INSN_ASI(ASI_PRIMARY_LITTLE))
260 #define LDUW_LE (LDUWA | INSN_ASI(ASI_PRIMARY_LITTLE))
261 #define LDSW_LE (LDSWA | INSN_ASI(ASI_PRIMARY_LITTLE))
262 #define LDX_LE (LDXA | INSN_ASI(ASI_PRIMARY_LITTLE))
264 #define STH_LE (STHA | INSN_ASI(ASI_PRIMARY_LITTLE))
265 #define STW_LE (STWA | INSN_ASI(ASI_PRIMARY_LITTLE))
266 #define STX_LE (STXA | INSN_ASI(ASI_PRIMARY_LITTLE))
268 #ifndef use_vis3_instructions
269 bool use_vis3_instructions;
270 #endif
272 static inline int check_fit_i64(int64_t val, unsigned int bits)
274 return val == sextract64(val, 0, bits);
277 static inline int check_fit_i32(int32_t val, unsigned int bits)
279 return val == sextract32(val, 0, bits);
282 #define check_fit_tl check_fit_i64
283 #if SPARC64
284 # define check_fit_ptr check_fit_i64
285 #else
286 # define check_fit_ptr check_fit_i32
287 #endif
289 static void patch_reloc(tcg_insn_unit *code_ptr, int type,
290 intptr_t value, intptr_t addend)
292 uint32_t insn;
294 tcg_debug_assert(addend == 0);
295 value = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr);
297 switch (type) {
298 case R_SPARC_WDISP16:
299 if (!check_fit_ptr(value >> 2, 16)) {
300 tcg_abort();
302 insn = *code_ptr;
303 insn &= ~INSN_OFF16(-1);
304 insn |= INSN_OFF16(value);
305 *code_ptr = insn;
306 break;
307 case R_SPARC_WDISP19:
308 if (!check_fit_ptr(value >> 2, 19)) {
309 tcg_abort();
311 insn = *code_ptr;
312 insn &= ~INSN_OFF19(-1);
313 insn |= INSN_OFF19(value);
314 *code_ptr = insn;
315 break;
316 default:
317 tcg_abort();
321 /* parse target specific constraints */
322 static const char *target_parse_constraint(TCGArgConstraint *ct,
323 const char *ct_str, TCGType type)
325 switch (*ct_str++) {
326 case 'r':
327 ct->ct |= TCG_CT_REG;
328 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
329 break;
330 case 'R':
331 ct->ct |= TCG_CT_REG;
332 tcg_regset_set32(ct->u.regs, 0, ALL_64);
333 break;
334 case 'A': /* qemu_ld/st address constraint */
335 ct->ct |= TCG_CT_REG;
336 tcg_regset_set32(ct->u.regs, 0,
337 TARGET_LONG_BITS == 64 ? ALL_64 : 0xffffffff);
338 reserve_helpers:
339 tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0);
340 tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1);
341 tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2);
342 break;
343 case 's': /* qemu_st data 32-bit constraint */
344 ct->ct |= TCG_CT_REG;
345 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
346 goto reserve_helpers;
347 case 'S': /* qemu_st data 64-bit constraint */
348 ct->ct |= TCG_CT_REG;
349 tcg_regset_set32(ct->u.regs, 0, ALL_64);
350 goto reserve_helpers;
351 case 'I':
352 ct->ct |= TCG_CT_CONST_S11;
353 break;
354 case 'J':
355 ct->ct |= TCG_CT_CONST_S13;
356 break;
357 case 'Z':
358 ct->ct |= TCG_CT_CONST_ZERO;
359 break;
360 default:
361 return NULL;
363 return ct_str;
366 /* test if a constant matches the constraint */
367 static inline int tcg_target_const_match(tcg_target_long val, TCGType type,
368 const TCGArgConstraint *arg_ct)
370 int ct = arg_ct->ct;
372 if (ct & TCG_CT_CONST) {
373 return 1;
376 if (type == TCG_TYPE_I32) {
377 val = (int32_t)val;
380 if ((ct & TCG_CT_CONST_ZERO) && val == 0) {
381 return 1;
382 } else if ((ct & TCG_CT_CONST_S11) && check_fit_tl(val, 11)) {
383 return 1;
384 } else if ((ct & TCG_CT_CONST_S13) && check_fit_tl(val, 13)) {
385 return 1;
386 } else {
387 return 0;
391 static inline void tcg_out_arith(TCGContext *s, TCGReg rd, TCGReg rs1,
392 TCGReg rs2, int op)
394 tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) | INSN_RS2(rs2));
397 static inline void tcg_out_arithi(TCGContext *s, TCGReg rd, TCGReg rs1,
398 int32_t offset, int op)
400 tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) | INSN_IMM13(offset));
403 static void tcg_out_arithc(TCGContext *s, TCGReg rd, TCGReg rs1,
404 int32_t val2, int val2const, int op)
406 tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1)
407 | (val2const ? INSN_IMM13(val2) : INSN_RS2(val2)));
410 static inline void tcg_out_mov(TCGContext *s, TCGType type,
411 TCGReg ret, TCGReg arg)
413 if (ret != arg) {
414 tcg_out_arith(s, ret, arg, TCG_REG_G0, ARITH_OR);
418 static inline void tcg_out_sethi(TCGContext *s, TCGReg ret, uint32_t arg)
420 tcg_out32(s, SETHI | INSN_RD(ret) | ((arg & 0xfffffc00) >> 10));
423 static inline void tcg_out_movi_imm13(TCGContext *s, TCGReg ret, int32_t arg)
425 tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR);
428 static void tcg_out_movi(TCGContext *s, TCGType type,
429 TCGReg ret, tcg_target_long arg)
431 tcg_target_long hi, lo = (int32_t)arg;
433 /* Make sure we test 32-bit constants for imm13 properly. */
434 if (type == TCG_TYPE_I32) {
435 arg = lo;
438 /* A 13-bit constant sign-extended to 64-bits. */
439 if (check_fit_tl(arg, 13)) {
440 tcg_out_movi_imm13(s, ret, arg);
441 return;
444 /* A 32-bit constant, or 32-bit zero-extended to 64-bits. */
445 if (type == TCG_TYPE_I32 || arg == (uint32_t)arg) {
446 tcg_out_sethi(s, ret, arg);
447 if (arg & 0x3ff) {
448 tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
450 return;
453 /* A 32-bit constant sign-extended to 64-bits. */
454 if (arg == lo) {
455 tcg_out_sethi(s, ret, ~arg);
456 tcg_out_arithi(s, ret, ret, (arg & 0x3ff) | -0x400, ARITH_XOR);
457 return;
460 /* A 64-bit constant decomposed into 2 32-bit pieces. */
461 if (check_fit_i32(lo, 13)) {
462 hi = (arg - lo) >> 32;
463 tcg_out_movi(s, TCG_TYPE_I32, ret, hi);
464 tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX);
465 tcg_out_arithi(s, ret, ret, lo, ARITH_ADD);
466 } else {
467 hi = arg >> 32;
468 tcg_out_movi(s, TCG_TYPE_I32, ret, hi);
469 tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T2, lo);
470 tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX);
471 tcg_out_arith(s, ret, ret, TCG_REG_T2, ARITH_OR);
475 static inline void tcg_out_ldst_rr(TCGContext *s, TCGReg data, TCGReg a1,
476 TCGReg a2, int op)
478 tcg_out32(s, op | INSN_RD(data) | INSN_RS1(a1) | INSN_RS2(a2));
481 static void tcg_out_ldst(TCGContext *s, TCGReg ret, TCGReg addr,
482 intptr_t offset, int op)
484 if (check_fit_ptr(offset, 13)) {
485 tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) |
486 INSN_IMM13(offset));
487 } else {
488 tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_T1, offset);
489 tcg_out_ldst_rr(s, ret, addr, TCG_REG_T1, op);
493 static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg ret,
494 TCGReg arg1, intptr_t arg2)
496 tcg_out_ldst(s, ret, arg1, arg2, (type == TCG_TYPE_I32 ? LDUW : LDX));
499 static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg,
500 TCGReg arg1, intptr_t arg2)
502 tcg_out_ldst(s, arg, arg1, arg2, (type == TCG_TYPE_I32 ? STW : STX));
505 static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
506 TCGReg base, intptr_t ofs)
508 if (val == 0) {
509 tcg_out_st(s, type, TCG_REG_G0, base, ofs);
510 return true;
512 return false;
515 static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, uintptr_t arg)
517 tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ff);
518 tcg_out_ld(s, TCG_TYPE_PTR, ret, ret, arg & 0x3ff);
521 static inline void tcg_out_sety(TCGContext *s, TCGReg rs)
523 tcg_out32(s, WRY | INSN_RS1(TCG_REG_G0) | INSN_RS2(rs));
526 static inline void tcg_out_rdy(TCGContext *s, TCGReg rd)
528 tcg_out32(s, RDY | INSN_RD(rd));
531 static void tcg_out_div32(TCGContext *s, TCGReg rd, TCGReg rs1,
532 int32_t val2, int val2const, int uns)
534 /* Load Y with the sign/zero extension of RS1 to 64-bits. */
535 if (uns) {
536 tcg_out_sety(s, TCG_REG_G0);
537 } else {
538 tcg_out_arithi(s, TCG_REG_T1, rs1, 31, SHIFT_SRA);
539 tcg_out_sety(s, TCG_REG_T1);
542 tcg_out_arithc(s, rd, rs1, val2, val2const,
543 uns ? ARITH_UDIV : ARITH_SDIV);
546 static inline void tcg_out_nop(TCGContext *s)
548 tcg_out_sethi(s, TCG_REG_G0, 0);
551 static const uint8_t tcg_cond_to_bcond[] = {
552 [TCG_COND_EQ] = COND_E,
553 [TCG_COND_NE] = COND_NE,
554 [TCG_COND_LT] = COND_L,
555 [TCG_COND_GE] = COND_GE,
556 [TCG_COND_LE] = COND_LE,
557 [TCG_COND_GT] = COND_G,
558 [TCG_COND_LTU] = COND_CS,
559 [TCG_COND_GEU] = COND_CC,
560 [TCG_COND_LEU] = COND_LEU,
561 [TCG_COND_GTU] = COND_GU,
564 static const uint8_t tcg_cond_to_rcond[] = {
565 [TCG_COND_EQ] = RCOND_Z,
566 [TCG_COND_NE] = RCOND_NZ,
567 [TCG_COND_LT] = RCOND_LZ,
568 [TCG_COND_GT] = RCOND_GZ,
569 [TCG_COND_LE] = RCOND_LEZ,
570 [TCG_COND_GE] = RCOND_GEZ
573 static void tcg_out_bpcc0(TCGContext *s, int scond, int flags, int off19)
575 tcg_out32(s, INSN_OP(0) | INSN_OP2(1) | INSN_COND(scond) | flags | off19);
578 static void tcg_out_bpcc(TCGContext *s, int scond, int flags, TCGLabel *l)
580 int off19;
582 if (l->has_value) {
583 off19 = INSN_OFF19(tcg_pcrel_diff(s, l->u.value_ptr));
584 } else {
585 /* Make sure to preserve destinations during retranslation. */
586 off19 = *s->code_ptr & INSN_OFF19(-1);
587 tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP19, l, 0);
589 tcg_out_bpcc0(s, scond, flags, off19);
592 static void tcg_out_cmp(TCGContext *s, TCGReg c1, int32_t c2, int c2const)
594 tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, ARITH_SUBCC);
597 static void tcg_out_brcond_i32(TCGContext *s, TCGCond cond, TCGReg arg1,
598 int32_t arg2, int const_arg2, TCGLabel *l)
600 tcg_out_cmp(s, arg1, arg2, const_arg2);
601 tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_ICC | BPCC_PT, l);
602 tcg_out_nop(s);
605 static void tcg_out_movcc(TCGContext *s, TCGCond cond, int cc, TCGReg ret,
606 int32_t v1, int v1const)
608 tcg_out32(s, ARITH_MOVCC | cc | INSN_RD(ret)
609 | INSN_RS1(tcg_cond_to_bcond[cond])
610 | (v1const ? INSN_IMM11(v1) : INSN_RS2(v1)));
613 static void tcg_out_movcond_i32(TCGContext *s, TCGCond cond, TCGReg ret,
614 TCGReg c1, int32_t c2, int c2const,
615 int32_t v1, int v1const)
617 tcg_out_cmp(s, c1, c2, c2const);
618 tcg_out_movcc(s, cond, MOVCC_ICC, ret, v1, v1const);
621 static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, TCGReg arg1,
622 int32_t arg2, int const_arg2, TCGLabel *l)
624 /* For 64-bit signed comparisons vs zero, we can avoid the compare. */
625 if (arg2 == 0 && !is_unsigned_cond(cond)) {
626 int off16;
628 if (l->has_value) {
629 off16 = INSN_OFF16(tcg_pcrel_diff(s, l->u.value_ptr));
630 } else {
631 /* Make sure to preserve destinations during retranslation. */
632 off16 = *s->code_ptr & INSN_OFF16(-1);
633 tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP16, l, 0);
635 tcg_out32(s, INSN_OP(0) | INSN_OP2(3) | BPR_PT | INSN_RS1(arg1)
636 | INSN_COND(tcg_cond_to_rcond[cond]) | off16);
637 } else {
638 tcg_out_cmp(s, arg1, arg2, const_arg2);
639 tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_XCC | BPCC_PT, l);
641 tcg_out_nop(s);
644 static void tcg_out_movr(TCGContext *s, TCGCond cond, TCGReg ret, TCGReg c1,
645 int32_t v1, int v1const)
647 tcg_out32(s, ARITH_MOVR | INSN_RD(ret) | INSN_RS1(c1)
648 | (tcg_cond_to_rcond[cond] << 10)
649 | (v1const ? INSN_IMM10(v1) : INSN_RS2(v1)));
652 static void tcg_out_movcond_i64(TCGContext *s, TCGCond cond, TCGReg ret,
653 TCGReg c1, int32_t c2, int c2const,
654 int32_t v1, int v1const)
656 /* For 64-bit signed comparisons vs zero, we can avoid the compare.
657 Note that the immediate range is one bit smaller, so we must check
658 for that as well. */
659 if (c2 == 0 && !is_unsigned_cond(cond)
660 && (!v1const || check_fit_i32(v1, 10))) {
661 tcg_out_movr(s, cond, ret, c1, v1, v1const);
662 } else {
663 tcg_out_cmp(s, c1, c2, c2const);
664 tcg_out_movcc(s, cond, MOVCC_XCC, ret, v1, v1const);
668 static void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGReg ret,
669 TCGReg c1, int32_t c2, int c2const)
671 /* For 32-bit comparisons, we can play games with ADDC/SUBC. */
672 switch (cond) {
673 case TCG_COND_LTU:
674 case TCG_COND_GEU:
675 /* The result of the comparison is in the carry bit. */
676 break;
678 case TCG_COND_EQ:
679 case TCG_COND_NE:
680 /* For equality, we can transform to inequality vs zero. */
681 if (c2 != 0) {
682 tcg_out_arithc(s, TCG_REG_T1, c1, c2, c2const, ARITH_XOR);
683 c2 = TCG_REG_T1;
684 } else {
685 c2 = c1;
687 c1 = TCG_REG_G0, c2const = 0;
688 cond = (cond == TCG_COND_EQ ? TCG_COND_GEU : TCG_COND_LTU);
689 break;
691 case TCG_COND_GTU:
692 case TCG_COND_LEU:
693 /* If we don't need to load a constant into a register, we can
694 swap the operands on GTU/LEU. There's no benefit to loading
695 the constant into a temporary register. */
696 if (!c2const || c2 == 0) {
697 TCGReg t = c1;
698 c1 = c2;
699 c2 = t;
700 c2const = 0;
701 cond = tcg_swap_cond(cond);
702 break;
704 /* FALLTHRU */
706 default:
707 tcg_out_cmp(s, c1, c2, c2const);
708 tcg_out_movi_imm13(s, ret, 0);
709 tcg_out_movcc(s, cond, MOVCC_ICC, ret, 1, 1);
710 return;
713 tcg_out_cmp(s, c1, c2, c2const);
714 if (cond == TCG_COND_LTU) {
715 tcg_out_arithi(s, ret, TCG_REG_G0, 0, ARITH_ADDC);
716 } else {
717 tcg_out_arithi(s, ret, TCG_REG_G0, -1, ARITH_SUBC);
721 static void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGReg ret,
722 TCGReg c1, int32_t c2, int c2const)
724 if (use_vis3_instructions) {
725 switch (cond) {
726 case TCG_COND_NE:
727 if (c2 != 0) {
728 break;
730 c2 = c1, c2const = 0, c1 = TCG_REG_G0;
731 /* FALLTHRU */
732 case TCG_COND_LTU:
733 tcg_out_cmp(s, c1, c2, c2const);
734 tcg_out_arith(s, ret, TCG_REG_G0, TCG_REG_G0, ARITH_ADDXC);
735 return;
736 default:
737 break;
741 /* For 64-bit signed comparisons vs zero, we can avoid the compare
742 if the input does not overlap the output. */
743 if (c2 == 0 && !is_unsigned_cond(cond) && c1 != ret) {
744 tcg_out_movi_imm13(s, ret, 0);
745 tcg_out_movr(s, cond, ret, c1, 1, 1);
746 } else {
747 tcg_out_cmp(s, c1, c2, c2const);
748 tcg_out_movi_imm13(s, ret, 0);
749 tcg_out_movcc(s, cond, MOVCC_XCC, ret, 1, 1);
753 static void tcg_out_addsub2_i32(TCGContext *s, TCGReg rl, TCGReg rh,
754 TCGReg al, TCGReg ah, int32_t bl, int blconst,
755 int32_t bh, int bhconst, int opl, int oph)
757 TCGReg tmp = TCG_REG_T1;
759 /* Note that the low parts are fully consumed before tmp is set. */
760 if (rl != ah && (bhconst || rl != bh)) {
761 tmp = rl;
764 tcg_out_arithc(s, tmp, al, bl, blconst, opl);
765 tcg_out_arithc(s, rh, ah, bh, bhconst, oph);
766 tcg_out_mov(s, TCG_TYPE_I32, rl, tmp);
769 static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
770 TCGReg al, TCGReg ah, int32_t bl, int blconst,
771 int32_t bh, int bhconst, bool is_sub)
773 TCGReg tmp = TCG_REG_T1;
775 /* Note that the low parts are fully consumed before tmp is set. */
776 if (rl != ah && (bhconst || rl != bh)) {
777 tmp = rl;
780 tcg_out_arithc(s, tmp, al, bl, blconst, is_sub ? ARITH_SUBCC : ARITH_ADDCC);
782 if (use_vis3_instructions && !is_sub) {
783 /* Note that ADDXC doesn't accept immediates. */
784 if (bhconst && bh != 0) {
785 tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_T2, bh);
786 bh = TCG_REG_T2;
788 tcg_out_arith(s, rh, ah, bh, ARITH_ADDXC);
789 } else if (bh == TCG_REG_G0) {
790 /* If we have a zero, we can perform the operation in two insns,
791 with the arithmetic first, and a conditional move into place. */
792 if (rh == ah) {
793 tcg_out_arithi(s, TCG_REG_T2, ah, 1,
794 is_sub ? ARITH_SUB : ARITH_ADD);
795 tcg_out_movcc(s, TCG_COND_LTU, MOVCC_XCC, rh, TCG_REG_T2, 0);
796 } else {
797 tcg_out_arithi(s, rh, ah, 1, is_sub ? ARITH_SUB : ARITH_ADD);
798 tcg_out_movcc(s, TCG_COND_GEU, MOVCC_XCC, rh, ah, 0);
800 } else {
801 /* Otherwise adjust BH as if there is carry into T2 ... */
802 if (bhconst) {
803 tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_T2, bh + (is_sub ? -1 : 1));
804 } else {
805 tcg_out_arithi(s, TCG_REG_T2, bh, 1,
806 is_sub ? ARITH_SUB : ARITH_ADD);
808 /* ... smoosh T2 back to original BH if carry is clear ... */
809 tcg_out_movcc(s, TCG_COND_GEU, MOVCC_XCC, TCG_REG_T2, bh, bhconst);
810 /* ... and finally perform the arithmetic with the new operand. */
811 tcg_out_arith(s, rh, ah, TCG_REG_T2, is_sub ? ARITH_SUB : ARITH_ADD);
814 tcg_out_mov(s, TCG_TYPE_I64, rl, tmp);
817 static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest)
819 ptrdiff_t disp = tcg_pcrel_diff(s, dest);
821 if (disp == (int32_t)disp) {
822 tcg_out32(s, CALL | (uint32_t)disp >> 2);
823 } else {
824 uintptr_t desti = (uintptr_t)dest;
825 tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_T1, desti & ~0xfff);
826 tcg_out_arithi(s, TCG_REG_O7, TCG_REG_T1, desti & 0xfff, JMPL);
830 static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
832 tcg_out_call_nodelay(s, dest);
833 tcg_out_nop(s);
836 static void tcg_out_mb(TCGContext *s, TCGArg a0)
838 /* Note that the TCG memory order constants mirror the Sparc MEMBAR. */
839 tcg_out32(s, MEMBAR | (a0 & TCG_MO_ALL));
842 #ifdef CONFIG_SOFTMMU
843 static tcg_insn_unit *qemu_ld_trampoline[16];
844 static tcg_insn_unit *qemu_st_trampoline[16];
846 static void emit_extend(TCGContext *s, TCGReg r, int op)
848 /* Emit zero extend of 8, 16 or 32 bit data as
849 * required by the MO_* value op; do nothing for 64 bit.
851 switch (op & MO_SIZE) {
852 case MO_8:
853 tcg_out_arithi(s, r, r, 0xff, ARITH_AND);
854 break;
855 case MO_16:
856 tcg_out_arithi(s, r, r, 16, SHIFT_SLL);
857 tcg_out_arithi(s, r, r, 16, SHIFT_SRL);
858 break;
859 case MO_32:
860 if (SPARC64) {
861 tcg_out_arith(s, r, r, 0, SHIFT_SRL);
863 break;
864 case MO_64:
865 break;
869 static void build_trampolines(TCGContext *s)
871 static void * const qemu_ld_helpers[16] = {
872 [MO_UB] = helper_ret_ldub_mmu,
873 [MO_SB] = helper_ret_ldsb_mmu,
874 [MO_LEUW] = helper_le_lduw_mmu,
875 [MO_LESW] = helper_le_ldsw_mmu,
876 [MO_LEUL] = helper_le_ldul_mmu,
877 [MO_LEQ] = helper_le_ldq_mmu,
878 [MO_BEUW] = helper_be_lduw_mmu,
879 [MO_BESW] = helper_be_ldsw_mmu,
880 [MO_BEUL] = helper_be_ldul_mmu,
881 [MO_BEQ] = helper_be_ldq_mmu,
883 static void * const qemu_st_helpers[16] = {
884 [MO_UB] = helper_ret_stb_mmu,
885 [MO_LEUW] = helper_le_stw_mmu,
886 [MO_LEUL] = helper_le_stl_mmu,
887 [MO_LEQ] = helper_le_stq_mmu,
888 [MO_BEUW] = helper_be_stw_mmu,
889 [MO_BEUL] = helper_be_stl_mmu,
890 [MO_BEQ] = helper_be_stq_mmu,
893 int i;
894 TCGReg ra;
896 for (i = 0; i < 16; ++i) {
897 if (qemu_ld_helpers[i] == NULL) {
898 continue;
901 /* May as well align the trampoline. */
902 while ((uintptr_t)s->code_ptr & 15) {
903 tcg_out_nop(s);
905 qemu_ld_trampoline[i] = s->code_ptr;
907 if (SPARC64 || TARGET_LONG_BITS == 32) {
908 ra = TCG_REG_O3;
909 } else {
910 /* Install the high part of the address. */
911 tcg_out_arithi(s, TCG_REG_O1, TCG_REG_O2, 32, SHIFT_SRLX);
912 ra = TCG_REG_O4;
915 /* Set the retaddr operand. */
916 tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
917 /* Set the env operand. */
918 tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0);
919 /* Tail call. */
920 tcg_out_call_nodelay(s, qemu_ld_helpers[i]);
921 tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra);
924 for (i = 0; i < 16; ++i) {
925 if (qemu_st_helpers[i] == NULL) {
926 continue;
929 /* May as well align the trampoline. */
930 while ((uintptr_t)s->code_ptr & 15) {
931 tcg_out_nop(s);
933 qemu_st_trampoline[i] = s->code_ptr;
935 if (SPARC64) {
936 emit_extend(s, TCG_REG_O2, i);
937 ra = TCG_REG_O4;
938 } else {
939 ra = TCG_REG_O1;
940 if (TARGET_LONG_BITS == 64) {
941 /* Install the high part of the address. */
942 tcg_out_arithi(s, ra, ra + 1, 32, SHIFT_SRLX);
943 ra += 2;
944 } else {
945 ra += 1;
947 if ((i & MO_SIZE) == MO_64) {
948 /* Install the high part of the data. */
949 tcg_out_arithi(s, ra, ra + 1, 32, SHIFT_SRLX);
950 ra += 2;
951 } else {
952 emit_extend(s, ra, i);
953 ra += 1;
955 /* Skip the oi argument. */
956 ra += 1;
959 /* Set the retaddr operand. */
960 if (ra >= TCG_REG_O6) {
961 tcg_out_st(s, TCG_TYPE_PTR, TCG_REG_O7, TCG_REG_CALL_STACK,
962 TCG_TARGET_CALL_STACK_OFFSET);
963 ra = TCG_REG_G1;
965 tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
966 /* Set the env operand. */
967 tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0);
968 /* Tail call. */
969 tcg_out_call_nodelay(s, qemu_st_helpers[i]);
970 tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra);
973 #endif
975 /* Generate global QEMU prologue and epilogue code */
976 static void tcg_target_qemu_prologue(TCGContext *s)
978 int tmp_buf_size, frame_size;
980 /* The TCG temp buffer is at the top of the frame, immediately
981 below the frame pointer. */
982 tmp_buf_size = CPU_TEMP_BUF_NLONGS * (int)sizeof(long);
983 tcg_set_frame(s, TCG_REG_I6, TCG_TARGET_STACK_BIAS - tmp_buf_size,
984 tmp_buf_size);
986 /* TCG_TARGET_CALL_STACK_OFFSET includes the stack bias, but is
987 otherwise the minimal frame usable by callees. */
988 frame_size = TCG_TARGET_CALL_STACK_OFFSET - TCG_TARGET_STACK_BIAS;
989 frame_size += TCG_STATIC_CALL_ARGS_SIZE + tmp_buf_size;
990 frame_size += TCG_TARGET_STACK_ALIGN - 1;
991 frame_size &= -TCG_TARGET_STACK_ALIGN;
992 tcg_out32(s, SAVE | INSN_RD(TCG_REG_O6) | INSN_RS1(TCG_REG_O6) |
993 INSN_IMM13(-frame_size));
995 #ifndef CONFIG_SOFTMMU
996 if (guest_base != 0) {
997 tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base);
998 tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);
1000 #endif
1002 tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I1, 0, JMPL);
1003 /* delay slot */
1004 tcg_out_nop(s);
1006 /* No epilogue required. We issue ret + restore directly in the TB. */
1008 #ifdef CONFIG_SOFTMMU
1009 build_trampolines(s);
1010 #endif
1013 #if defined(CONFIG_SOFTMMU)
1014 /* Perform the TLB load and compare.
1016 Inputs:
1017 ADDRLO and ADDRHI contain the possible two parts of the address.
1019 MEM_INDEX and S_BITS are the memory context and log2 size of the load.
1021 WHICH is the offset into the CPUTLBEntry structure of the slot to read.
1022 This should be offsetof addr_read or addr_write.
1024 The result of the TLB comparison is in %[ix]cc. The sanitized address
1025 is in the returned register, maybe %o0. The TLB addend is in %o1. */
1027 static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addr, int mem_index,
1028 TCGMemOp opc, int which)
1030 const TCGReg r0 = TCG_REG_O0;
1031 const TCGReg r1 = TCG_REG_O1;
1032 const TCGReg r2 = TCG_REG_O2;
1033 unsigned s_bits = opc & MO_SIZE;
1034 unsigned a_bits = get_alignment_bits(opc);
1035 int tlb_ofs;
1037 /* Shift the page number down. */
1038 tcg_out_arithi(s, r1, addr, TARGET_PAGE_BITS, SHIFT_SRL);
1040 /* Mask out the page offset, except for the required alignment.
1041 We don't support unaligned accesses. */
1042 if (a_bits < s_bits) {
1043 a_bits = s_bits;
1045 tcg_out_movi(s, TCG_TYPE_TL, TCG_REG_T1,
1046 TARGET_PAGE_MASK | ((1 << a_bits) - 1));
1048 /* Mask the tlb index. */
1049 tcg_out_arithi(s, r1, r1, CPU_TLB_SIZE - 1, ARITH_AND);
1051 /* Mask page, part 2. */
1052 tcg_out_arith(s, r0, addr, TCG_REG_T1, ARITH_AND);
1054 /* Shift the tlb index into place. */
1055 tcg_out_arithi(s, r1, r1, CPU_TLB_ENTRY_BITS, SHIFT_SLL);
1057 /* Relative to the current ENV. */
1058 tcg_out_arith(s, r1, TCG_AREG0, r1, ARITH_ADD);
1060 /* Find a base address that can load both tlb comparator and addend. */
1061 tlb_ofs = offsetof(CPUArchState, tlb_table[mem_index][0]);
1062 if (!check_fit_ptr(tlb_ofs + sizeof(CPUTLBEntry), 13)) {
1063 if (tlb_ofs & ~0x3ff) {
1064 tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_T1, tlb_ofs & ~0x3ff);
1065 tcg_out_arith(s, r1, r1, TCG_REG_T1, ARITH_ADD);
1067 tlb_ofs &= 0x3ff;
1070 /* Load the tlb comparator and the addend. */
1071 tcg_out_ld(s, TCG_TYPE_TL, r2, r1, tlb_ofs + which);
1072 tcg_out_ld(s, TCG_TYPE_PTR, r1, r1, tlb_ofs+offsetof(CPUTLBEntry, addend));
1074 /* subcc arg0, arg2, %g0 */
1075 tcg_out_cmp(s, r0, r2, 0);
1077 /* If the guest address must be zero-extended, do so now. */
1078 if (SPARC64 && TARGET_LONG_BITS == 32) {
1079 tcg_out_arithi(s, r0, addr, 0, SHIFT_SRL);
1080 return r0;
1082 return addr;
1084 #endif /* CONFIG_SOFTMMU */
1086 static const int qemu_ld_opc[16] = {
1087 [MO_UB] = LDUB,
1088 [MO_SB] = LDSB,
1090 [MO_BEUW] = LDUH,
1091 [MO_BESW] = LDSH,
1092 [MO_BEUL] = LDUW,
1093 [MO_BESL] = LDSW,
1094 [MO_BEQ] = LDX,
1096 [MO_LEUW] = LDUH_LE,
1097 [MO_LESW] = LDSH_LE,
1098 [MO_LEUL] = LDUW_LE,
1099 [MO_LESL] = LDSW_LE,
1100 [MO_LEQ] = LDX_LE,
1103 static const int qemu_st_opc[16] = {
1104 [MO_UB] = STB,
1106 [MO_BEUW] = STH,
1107 [MO_BEUL] = STW,
1108 [MO_BEQ] = STX,
1110 [MO_LEUW] = STH_LE,
1111 [MO_LEUL] = STW_LE,
1112 [MO_LEQ] = STX_LE,
1115 static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
1116 TCGMemOpIdx oi, bool is_64)
1118 TCGMemOp memop = get_memop(oi);
1119 #ifdef CONFIG_SOFTMMU
1120 unsigned memi = get_mmuidx(oi);
1121 TCGReg addrz, param;
1122 tcg_insn_unit *func;
1123 tcg_insn_unit *label_ptr;
1125 addrz = tcg_out_tlb_load(s, addr, memi, memop,
1126 offsetof(CPUTLBEntry, addr_read));
1128 /* The fast path is exactly one insn. Thus we can perform the
1129 entire TLB Hit in the (annulled) delay slot of the branch
1130 over the TLB Miss case. */
1132 /* beq,a,pt %[xi]cc, label0 */
1133 label_ptr = s->code_ptr;
1134 tcg_out_bpcc0(s, COND_E, BPCC_A | BPCC_PT
1135 | (TARGET_LONG_BITS == 64 ? BPCC_XCC : BPCC_ICC), 0);
1136 /* delay slot */
1137 tcg_out_ldst_rr(s, data, addrz, TCG_REG_O1,
1138 qemu_ld_opc[memop & (MO_BSWAP | MO_SSIZE)]);
1140 /* TLB Miss. */
1142 param = TCG_REG_O1;
1143 if (!SPARC64 && TARGET_LONG_BITS == 64) {
1144 /* Skip the high-part; we'll perform the extract in the trampoline. */
1145 param++;
1147 tcg_out_mov(s, TCG_TYPE_REG, param++, addrz);
1149 /* We use the helpers to extend SB and SW data, leaving the case
1150 of SL needing explicit extending below. */
1151 if ((memop & MO_SSIZE) == MO_SL) {
1152 func = qemu_ld_trampoline[memop & (MO_BSWAP | MO_SIZE)];
1153 } else {
1154 func = qemu_ld_trampoline[memop & (MO_BSWAP | MO_SSIZE)];
1156 tcg_debug_assert(func != NULL);
1157 tcg_out_call_nodelay(s, func);
1158 /* delay slot */
1159 tcg_out_movi(s, TCG_TYPE_I32, param, oi);
1161 /* Recall that all of the helpers return 64-bit results.
1162 Which complicates things for sparcv8plus. */
1163 if (SPARC64) {
1164 /* We let the helper sign-extend SB and SW, but leave SL for here. */
1165 if (is_64 && (memop & MO_SSIZE) == MO_SL) {
1166 tcg_out_arithi(s, data, TCG_REG_O0, 0, SHIFT_SRA);
1167 } else {
1168 tcg_out_mov(s, TCG_TYPE_REG, data, TCG_REG_O0);
1170 } else {
1171 if ((memop & MO_SIZE) == MO_64) {
1172 tcg_out_arithi(s, TCG_REG_O0, TCG_REG_O0, 32, SHIFT_SLLX);
1173 tcg_out_arithi(s, TCG_REG_O1, TCG_REG_O1, 0, SHIFT_SRL);
1174 tcg_out_arith(s, data, TCG_REG_O0, TCG_REG_O1, ARITH_OR);
1175 } else if (is_64) {
1176 /* Re-extend from 32-bit rather than reassembling when we
1177 know the high register must be an extension. */
1178 tcg_out_arithi(s, data, TCG_REG_O1, 0,
1179 memop & MO_SIGN ? SHIFT_SRA : SHIFT_SRL);
1180 } else {
1181 tcg_out_mov(s, TCG_TYPE_I32, data, TCG_REG_O1);
1185 *label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
1186 #else
1187 if (SPARC64 && TARGET_LONG_BITS == 32) {
1188 tcg_out_arithi(s, TCG_REG_T1, addr, 0, SHIFT_SRL);
1189 addr = TCG_REG_T1;
1191 tcg_out_ldst_rr(s, data, addr,
1192 (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0),
1193 qemu_ld_opc[memop & (MO_BSWAP | MO_SSIZE)]);
1194 #endif /* CONFIG_SOFTMMU */
1197 static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
1198 TCGMemOpIdx oi)
1200 TCGMemOp memop = get_memop(oi);
1201 #ifdef CONFIG_SOFTMMU
1202 unsigned memi = get_mmuidx(oi);
1203 TCGReg addrz, param;
1204 tcg_insn_unit *func;
1205 tcg_insn_unit *label_ptr;
1207 addrz = tcg_out_tlb_load(s, addr, memi, memop,
1208 offsetof(CPUTLBEntry, addr_write));
1210 /* The fast path is exactly one insn. Thus we can perform the entire
1211 TLB Hit in the (annulled) delay slot of the branch over TLB Miss. */
1212 /* beq,a,pt %[xi]cc, label0 */
1213 label_ptr = s->code_ptr;
1214 tcg_out_bpcc0(s, COND_E, BPCC_A | BPCC_PT
1215 | (TARGET_LONG_BITS == 64 ? BPCC_XCC : BPCC_ICC), 0);
1216 /* delay slot */
1217 tcg_out_ldst_rr(s, data, addrz, TCG_REG_O1,
1218 qemu_st_opc[memop & (MO_BSWAP | MO_SIZE)]);
1220 /* TLB Miss. */
1222 param = TCG_REG_O1;
1223 if (!SPARC64 && TARGET_LONG_BITS == 64) {
1224 /* Skip the high-part; we'll perform the extract in the trampoline. */
1225 param++;
1227 tcg_out_mov(s, TCG_TYPE_REG, param++, addrz);
1228 if (!SPARC64 && (memop & MO_SIZE) == MO_64) {
1229 /* Skip the high-part; we'll perform the extract in the trampoline. */
1230 param++;
1232 tcg_out_mov(s, TCG_TYPE_REG, param++, data);
1234 func = qemu_st_trampoline[memop & (MO_BSWAP | MO_SIZE)];
1235 tcg_debug_assert(func != NULL);
1236 tcg_out_call_nodelay(s, func);
1237 /* delay slot */
1238 tcg_out_movi(s, TCG_TYPE_I32, param, oi);
1240 *label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
1241 #else
1242 if (SPARC64 && TARGET_LONG_BITS == 32) {
1243 tcg_out_arithi(s, TCG_REG_T1, addr, 0, SHIFT_SRL);
1244 addr = TCG_REG_T1;
1246 tcg_out_ldst_rr(s, data, addr,
1247 (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0),
1248 qemu_st_opc[memop & (MO_BSWAP | MO_SIZE)]);
1249 #endif /* CONFIG_SOFTMMU */
1252 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
1253 const TCGArg args[TCG_MAX_OP_ARGS],
1254 const int const_args[TCG_MAX_OP_ARGS])
1256 TCGArg a0, a1, a2;
1257 int c, c2;
1259 /* Hoist the loads of the most common arguments. */
1260 a0 = args[0];
1261 a1 = args[1];
1262 a2 = args[2];
1263 c2 = const_args[2];
1265 switch (opc) {
1266 case INDEX_op_exit_tb:
1267 if (check_fit_ptr(a0, 13)) {
1268 tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN);
1269 tcg_out_movi_imm13(s, TCG_REG_O0, a0);
1270 } else {
1271 tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, a0 & ~0x3ff);
1272 tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN);
1273 tcg_out_arithi(s, TCG_REG_O0, TCG_REG_O0, a0 & 0x3ff, ARITH_OR);
1275 break;
1276 case INDEX_op_goto_tb:
1277 if (s->tb_jmp_insn_offset) {
1278 /* direct jump method */
1279 s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s);
1280 /* Make sure to preserve links during retranslation. */
1281 tcg_out32(s, CALL | (*s->code_ptr & ~INSN_OP(-1)));
1282 } else {
1283 /* indirect jump method */
1284 tcg_out_ld_ptr(s, TCG_REG_T1,
1285 (uintptr_t)(s->tb_jmp_target_addr + a0));
1286 tcg_out_arithi(s, TCG_REG_G0, TCG_REG_T1, 0, JMPL);
1288 tcg_out_nop(s);
1289 s->tb_jmp_reset_offset[a0] = tcg_current_code_size(s);
1290 break;
1291 case INDEX_op_br:
1292 tcg_out_bpcc(s, COND_A, BPCC_PT, arg_label(a0));
1293 tcg_out_nop(s);
1294 break;
1296 #define OP_32_64(x) \
1297 glue(glue(case INDEX_op_, x), _i32): \
1298 glue(glue(case INDEX_op_, x), _i64)
1300 OP_32_64(ld8u):
1301 tcg_out_ldst(s, a0, a1, a2, LDUB);
1302 break;
1303 OP_32_64(ld8s):
1304 tcg_out_ldst(s, a0, a1, a2, LDSB);
1305 break;
1306 OP_32_64(ld16u):
1307 tcg_out_ldst(s, a0, a1, a2, LDUH);
1308 break;
1309 OP_32_64(ld16s):
1310 tcg_out_ldst(s, a0, a1, a2, LDSH);
1311 break;
1312 case INDEX_op_ld_i32:
1313 case INDEX_op_ld32u_i64:
1314 tcg_out_ldst(s, a0, a1, a2, LDUW);
1315 break;
1316 OP_32_64(st8):
1317 tcg_out_ldst(s, a0, a1, a2, STB);
1318 break;
1319 OP_32_64(st16):
1320 tcg_out_ldst(s, a0, a1, a2, STH);
1321 break;
1322 case INDEX_op_st_i32:
1323 case INDEX_op_st32_i64:
1324 tcg_out_ldst(s, a0, a1, a2, STW);
1325 break;
1326 OP_32_64(add):
1327 c = ARITH_ADD;
1328 goto gen_arith;
1329 OP_32_64(sub):
1330 c = ARITH_SUB;
1331 goto gen_arith;
1332 OP_32_64(and):
1333 c = ARITH_AND;
1334 goto gen_arith;
1335 OP_32_64(andc):
1336 c = ARITH_ANDN;
1337 goto gen_arith;
1338 OP_32_64(or):
1339 c = ARITH_OR;
1340 goto gen_arith;
1341 OP_32_64(orc):
1342 c = ARITH_ORN;
1343 goto gen_arith;
1344 OP_32_64(xor):
1345 c = ARITH_XOR;
1346 goto gen_arith;
1347 case INDEX_op_shl_i32:
1348 c = SHIFT_SLL;
1349 do_shift32:
1350 /* Limit immediate shift count lest we create an illegal insn. */
1351 tcg_out_arithc(s, a0, a1, a2 & 31, c2, c);
1352 break;
1353 case INDEX_op_shr_i32:
1354 c = SHIFT_SRL;
1355 goto do_shift32;
1356 case INDEX_op_sar_i32:
1357 c = SHIFT_SRA;
1358 goto do_shift32;
1359 case INDEX_op_mul_i32:
1360 c = ARITH_UMUL;
1361 goto gen_arith;
1363 OP_32_64(neg):
1364 c = ARITH_SUB;
1365 goto gen_arith1;
1366 OP_32_64(not):
1367 c = ARITH_ORN;
1368 goto gen_arith1;
1370 case INDEX_op_div_i32:
1371 tcg_out_div32(s, a0, a1, a2, c2, 0);
1372 break;
1373 case INDEX_op_divu_i32:
1374 tcg_out_div32(s, a0, a1, a2, c2, 1);
1375 break;
1377 case INDEX_op_brcond_i32:
1378 tcg_out_brcond_i32(s, a2, a0, a1, const_args[1], arg_label(args[3]));
1379 break;
1380 case INDEX_op_setcond_i32:
1381 tcg_out_setcond_i32(s, args[3], a0, a1, a2, c2);
1382 break;
1383 case INDEX_op_movcond_i32:
1384 tcg_out_movcond_i32(s, args[5], a0, a1, a2, c2, args[3], const_args[3]);
1385 break;
1387 case INDEX_op_add2_i32:
1388 tcg_out_addsub2_i32(s, args[0], args[1], args[2], args[3],
1389 args[4], const_args[4], args[5], const_args[5],
1390 ARITH_ADDCC, ARITH_ADDC);
1391 break;
1392 case INDEX_op_sub2_i32:
1393 tcg_out_addsub2_i32(s, args[0], args[1], args[2], args[3],
1394 args[4], const_args[4], args[5], const_args[5],
1395 ARITH_SUBCC, ARITH_SUBC);
1396 break;
1397 case INDEX_op_mulu2_i32:
1398 c = ARITH_UMUL;
1399 goto do_mul2;
1400 case INDEX_op_muls2_i32:
1401 c = ARITH_SMUL;
1402 do_mul2:
1403 /* The 32-bit multiply insns produce a full 64-bit result. If the
1404 destination register can hold it, we can avoid the slower RDY. */
1405 tcg_out_arithc(s, a0, a2, args[3], const_args[3], c);
1406 if (SPARC64 || a0 <= TCG_REG_O7) {
1407 tcg_out_arithi(s, a1, a0, 32, SHIFT_SRLX);
1408 } else {
1409 tcg_out_rdy(s, a1);
1411 break;
1413 case INDEX_op_qemu_ld_i32:
1414 tcg_out_qemu_ld(s, a0, a1, a2, false);
1415 break;
1416 case INDEX_op_qemu_ld_i64:
1417 tcg_out_qemu_ld(s, a0, a1, a2, true);
1418 break;
1419 case INDEX_op_qemu_st_i32:
1420 case INDEX_op_qemu_st_i64:
1421 tcg_out_qemu_st(s, a0, a1, a2);
1422 break;
1424 case INDEX_op_ld32s_i64:
1425 tcg_out_ldst(s, a0, a1, a2, LDSW);
1426 break;
1427 case INDEX_op_ld_i64:
1428 tcg_out_ldst(s, a0, a1, a2, LDX);
1429 break;
1430 case INDEX_op_st_i64:
1431 tcg_out_ldst(s, a0, a1, a2, STX);
1432 break;
1433 case INDEX_op_shl_i64:
1434 c = SHIFT_SLLX;
1435 do_shift64:
1436 /* Limit immediate shift count lest we create an illegal insn. */
1437 tcg_out_arithc(s, a0, a1, a2 & 63, c2, c);
1438 break;
1439 case INDEX_op_shr_i64:
1440 c = SHIFT_SRLX;
1441 goto do_shift64;
1442 case INDEX_op_sar_i64:
1443 c = SHIFT_SRAX;
1444 goto do_shift64;
1445 case INDEX_op_mul_i64:
1446 c = ARITH_MULX;
1447 goto gen_arith;
1448 case INDEX_op_div_i64:
1449 c = ARITH_SDIVX;
1450 goto gen_arith;
1451 case INDEX_op_divu_i64:
1452 c = ARITH_UDIVX;
1453 goto gen_arith;
1454 case INDEX_op_ext_i32_i64:
1455 case INDEX_op_ext32s_i64:
1456 tcg_out_arithi(s, a0, a1, 0, SHIFT_SRA);
1457 break;
1458 case INDEX_op_extu_i32_i64:
1459 case INDEX_op_ext32u_i64:
1460 tcg_out_arithi(s, a0, a1, 0, SHIFT_SRL);
1461 break;
1462 case INDEX_op_extrl_i64_i32:
1463 tcg_out_mov(s, TCG_TYPE_I32, a0, a1);
1464 break;
1465 case INDEX_op_extrh_i64_i32:
1466 tcg_out_arithi(s, a0, a1, 32, SHIFT_SRLX);
1467 break;
1469 case INDEX_op_brcond_i64:
1470 tcg_out_brcond_i64(s, a2, a0, a1, const_args[1], arg_label(args[3]));
1471 break;
1472 case INDEX_op_setcond_i64:
1473 tcg_out_setcond_i64(s, args[3], a0, a1, a2, c2);
1474 break;
1475 case INDEX_op_movcond_i64:
1476 tcg_out_movcond_i64(s, args[5], a0, a1, a2, c2, args[3], const_args[3]);
1477 break;
1478 case INDEX_op_add2_i64:
1479 tcg_out_addsub2_i64(s, args[0], args[1], args[2], args[3], args[4],
1480 const_args[4], args[5], const_args[5], false);
1481 break;
1482 case INDEX_op_sub2_i64:
1483 tcg_out_addsub2_i64(s, args[0], args[1], args[2], args[3], args[4],
1484 const_args[4], args[5], const_args[5], true);
1485 break;
1486 case INDEX_op_muluh_i64:
1487 tcg_out_arith(s, args[0], args[1], args[2], ARITH_UMULXHI);
1488 break;
1490 gen_arith:
1491 tcg_out_arithc(s, a0, a1, a2, c2, c);
1492 break;
1494 gen_arith1:
1495 tcg_out_arithc(s, a0, TCG_REG_G0, a1, const_args[1], c);
1496 break;
1498 case INDEX_op_mb:
1499 tcg_out_mb(s, a0);
1500 break;
1502 case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
1503 case INDEX_op_mov_i64:
1504 case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
1505 case INDEX_op_movi_i64:
1506 case INDEX_op_call: /* Always emitted via tcg_out_call. */
1507 default:
1508 tcg_abort();
1512 static const TCGTargetOpDef sparc_op_defs[] = {
1513 { INDEX_op_exit_tb, { } },
1514 { INDEX_op_goto_tb, { } },
1515 { INDEX_op_br, { } },
1517 { INDEX_op_ld8u_i32, { "r", "r" } },
1518 { INDEX_op_ld8s_i32, { "r", "r" } },
1519 { INDEX_op_ld16u_i32, { "r", "r" } },
1520 { INDEX_op_ld16s_i32, { "r", "r" } },
1521 { INDEX_op_ld_i32, { "r", "r" } },
1522 { INDEX_op_st8_i32, { "rZ", "r" } },
1523 { INDEX_op_st16_i32, { "rZ", "r" } },
1524 { INDEX_op_st_i32, { "rZ", "r" } },
1526 { INDEX_op_add_i32, { "r", "rZ", "rJ" } },
1527 { INDEX_op_mul_i32, { "r", "rZ", "rJ" } },
1528 { INDEX_op_div_i32, { "r", "rZ", "rJ" } },
1529 { INDEX_op_divu_i32, { "r", "rZ", "rJ" } },
1530 { INDEX_op_sub_i32, { "r", "rZ", "rJ" } },
1531 { INDEX_op_and_i32, { "r", "rZ", "rJ" } },
1532 { INDEX_op_andc_i32, { "r", "rZ", "rJ" } },
1533 { INDEX_op_or_i32, { "r", "rZ", "rJ" } },
1534 { INDEX_op_orc_i32, { "r", "rZ", "rJ" } },
1535 { INDEX_op_xor_i32, { "r", "rZ", "rJ" } },
1537 { INDEX_op_shl_i32, { "r", "rZ", "rJ" } },
1538 { INDEX_op_shr_i32, { "r", "rZ", "rJ" } },
1539 { INDEX_op_sar_i32, { "r", "rZ", "rJ" } },
1541 { INDEX_op_neg_i32, { "r", "rJ" } },
1542 { INDEX_op_not_i32, { "r", "rJ" } },
1544 { INDEX_op_brcond_i32, { "rZ", "rJ" } },
1545 { INDEX_op_setcond_i32, { "r", "rZ", "rJ" } },
1546 { INDEX_op_movcond_i32, { "r", "rZ", "rJ", "rI", "0" } },
1548 { INDEX_op_add2_i32, { "r", "r", "rZ", "rZ", "rJ", "rJ" } },
1549 { INDEX_op_sub2_i32, { "r", "r", "rZ", "rZ", "rJ", "rJ" } },
1550 { INDEX_op_mulu2_i32, { "r", "r", "rZ", "rJ" } },
1551 { INDEX_op_muls2_i32, { "r", "r", "rZ", "rJ" } },
1553 { INDEX_op_ld8u_i64, { "R", "r" } },
1554 { INDEX_op_ld8s_i64, { "R", "r" } },
1555 { INDEX_op_ld16u_i64, { "R", "r" } },
1556 { INDEX_op_ld16s_i64, { "R", "r" } },
1557 { INDEX_op_ld32u_i64, { "R", "r" } },
1558 { INDEX_op_ld32s_i64, { "R", "r" } },
1559 { INDEX_op_ld_i64, { "R", "r" } },
1560 { INDEX_op_st8_i64, { "RZ", "r" } },
1561 { INDEX_op_st16_i64, { "RZ", "r" } },
1562 { INDEX_op_st32_i64, { "RZ", "r" } },
1563 { INDEX_op_st_i64, { "RZ", "r" } },
1565 { INDEX_op_add_i64, { "R", "RZ", "RJ" } },
1566 { INDEX_op_mul_i64, { "R", "RZ", "RJ" } },
1567 { INDEX_op_div_i64, { "R", "RZ", "RJ" } },
1568 { INDEX_op_divu_i64, { "R", "RZ", "RJ" } },
1569 { INDEX_op_sub_i64, { "R", "RZ", "RJ" } },
1570 { INDEX_op_and_i64, { "R", "RZ", "RJ" } },
1571 { INDEX_op_andc_i64, { "R", "RZ", "RJ" } },
1572 { INDEX_op_or_i64, { "R", "RZ", "RJ" } },
1573 { INDEX_op_orc_i64, { "R", "RZ", "RJ" } },
1574 { INDEX_op_xor_i64, { "R", "RZ", "RJ" } },
1576 { INDEX_op_shl_i64, { "R", "RZ", "RJ" } },
1577 { INDEX_op_shr_i64, { "R", "RZ", "RJ" } },
1578 { INDEX_op_sar_i64, { "R", "RZ", "RJ" } },
1580 { INDEX_op_neg_i64, { "R", "RJ" } },
1581 { INDEX_op_not_i64, { "R", "RJ" } },
1583 { INDEX_op_ext32s_i64, { "R", "R" } },
1584 { INDEX_op_ext32u_i64, { "R", "R" } },
1585 { INDEX_op_ext_i32_i64, { "R", "r" } },
1586 { INDEX_op_extu_i32_i64, { "R", "r" } },
1587 { INDEX_op_extrl_i64_i32, { "r", "R" } },
1588 { INDEX_op_extrh_i64_i32, { "r", "R" } },
1590 { INDEX_op_brcond_i64, { "RZ", "RJ" } },
1591 { INDEX_op_setcond_i64, { "R", "RZ", "RJ" } },
1592 { INDEX_op_movcond_i64, { "R", "RZ", "RJ", "RI", "0" } },
1594 { INDEX_op_add2_i64, { "R", "R", "RZ", "RZ", "RJ", "RI" } },
1595 { INDEX_op_sub2_i64, { "R", "R", "RZ", "RZ", "RJ", "RI" } },
1596 { INDEX_op_muluh_i64, { "R", "RZ", "RZ" } },
1598 { INDEX_op_qemu_ld_i32, { "r", "A" } },
1599 { INDEX_op_qemu_ld_i64, { "R", "A" } },
1600 { INDEX_op_qemu_st_i32, { "sZ", "A" } },
1601 { INDEX_op_qemu_st_i64, { "SZ", "A" } },
1603 { INDEX_op_mb, { } },
1604 { -1 },
1607 static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)
1609 int i, n = ARRAY_SIZE(sparc_op_defs);
1611 for (i = 0; i < n; ++i) {
1612 if (sparc_op_defs[i].op == op) {
1613 return &sparc_op_defs[i];
1616 return NULL;
1619 static void tcg_target_init(TCGContext *s)
1621 /* Only probe for the platform and capabilities if we havn't already
1622 determined maximum values at compile time. */
1623 #ifndef use_vis3_instructions
1625 unsigned long hwcap = qemu_getauxval(AT_HWCAP);
1626 use_vis3_instructions = (hwcap & HWCAP_SPARC_VIS3) != 0;
1628 #endif
1630 tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
1631 tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I64], 0, ALL_64);
1633 tcg_regset_set32(tcg_target_call_clobber_regs, 0,
1634 (1 << TCG_REG_G1) |
1635 (1 << TCG_REG_G2) |
1636 (1 << TCG_REG_G3) |
1637 (1 << TCG_REG_G4) |
1638 (1 << TCG_REG_G5) |
1639 (1 << TCG_REG_G6) |
1640 (1 << TCG_REG_G7) |
1641 (1 << TCG_REG_O0) |
1642 (1 << TCG_REG_O1) |
1643 (1 << TCG_REG_O2) |
1644 (1 << TCG_REG_O3) |
1645 (1 << TCG_REG_O4) |
1646 (1 << TCG_REG_O5) |
1647 (1 << TCG_REG_O7));
1649 tcg_regset_clear(s->reserved_regs);
1650 tcg_regset_set_reg(s->reserved_regs, TCG_REG_G0); /* zero */
1651 tcg_regset_set_reg(s->reserved_regs, TCG_REG_G6); /* reserved for os */
1652 tcg_regset_set_reg(s->reserved_regs, TCG_REG_G7); /* thread pointer */
1653 tcg_regset_set_reg(s->reserved_regs, TCG_REG_I6); /* frame pointer */
1654 tcg_regset_set_reg(s->reserved_regs, TCG_REG_I7); /* return address */
1655 tcg_regset_set_reg(s->reserved_regs, TCG_REG_O6); /* stack pointer */
1656 tcg_regset_set_reg(s->reserved_regs, TCG_REG_T1); /* for internal use */
1657 tcg_regset_set_reg(s->reserved_regs, TCG_REG_T2); /* for internal use */
1660 #if SPARC64
1661 # define ELF_HOST_MACHINE EM_SPARCV9
1662 #else
1663 # define ELF_HOST_MACHINE EM_SPARC32PLUS
1664 # define ELF_HOST_FLAGS EF_SPARC_32PLUS
1665 #endif
1667 typedef struct {
1668 DebugFrameHeader h;
1669 uint8_t fde_def_cfa[SPARC64 ? 4 : 2];
1670 uint8_t fde_win_save;
1671 uint8_t fde_ret_save[3];
1672 } DebugFrame;
1674 static const DebugFrame debug_frame = {
1675 .h.cie.len = sizeof(DebugFrameCIE)-4, /* length after .len member */
1676 .h.cie.id = -1,
1677 .h.cie.version = 1,
1678 .h.cie.code_align = 1,
1679 .h.cie.data_align = -sizeof(void *) & 0x7f,
1680 .h.cie.return_column = 15, /* o7 */
1682 /* Total FDE size does not include the "len" member. */
1683 .h.fde.len = sizeof(DebugFrame) - offsetof(DebugFrame, h.fde.cie_offset),
1685 .fde_def_cfa = {
1686 #if SPARC64
1687 12, 30, /* DW_CFA_def_cfa i6, 2047 */
1688 (2047 & 0x7f) | 0x80, (2047 >> 7)
1689 #else
1690 13, 30 /* DW_CFA_def_cfa_register i6 */
1691 #endif
1693 .fde_win_save = 0x2d, /* DW_CFA_GNU_window_save */
1694 .fde_ret_save = { 9, 15, 31 }, /* DW_CFA_register o7, i7 */
1697 void tcg_register_jit(void *buf, size_t buf_size)
1699 tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
1702 void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr)
1704 uint32_t *ptr = (uint32_t *)jmp_addr;
1705 uintptr_t disp = addr - jmp_addr;
1707 /* We can reach the entire address space for 32-bit. For 64-bit
1708 the code_gen_buffer can't be larger than 2GB. */
1709 tcg_debug_assert(disp == (int32_t)disp);
1711 atomic_set(ptr, deposit32(CALL, 0, 30, disp >> 2));
1712 flush_icache_range(jmp_addr, jmp_addr + 4);