]>
Commit | Line | Data |
---|---|---|
8289b279 BS |
1 | /* |
2 | * Tiny Code Generator for QEMU | |
3 | * | |
4 | * Copyright (c) 2008 Fabrice Bellard | |
5 | * | |
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: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
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. | |
23 | */ | |
24 | ||
d4a9eb1f | 25 | #ifndef NDEBUG |
8289b279 BS |
26 | static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { |
27 | "%g0", | |
28 | "%g1", | |
29 | "%g2", | |
30 | "%g3", | |
31 | "%g4", | |
32 | "%g5", | |
33 | "%g6", | |
34 | "%g7", | |
35 | "%o0", | |
36 | "%o1", | |
37 | "%o2", | |
38 | "%o3", | |
39 | "%o4", | |
40 | "%o5", | |
41 | "%o6", | |
42 | "%o7", | |
43 | "%l0", | |
44 | "%l1", | |
45 | "%l2", | |
46 | "%l3", | |
47 | "%l4", | |
48 | "%l5", | |
49 | "%l6", | |
50 | "%l7", | |
51 | "%i0", | |
52 | "%i1", | |
53 | "%i2", | |
54 | "%i3", | |
55 | "%i4", | |
56 | "%i5", | |
57 | "%i6", | |
58 | "%i7", | |
59 | }; | |
d4a9eb1f | 60 | #endif |
8289b279 | 61 | |
e141ab52 | 62 | #define ARG_OFFSET 1 |
e141ab52 | 63 | |
0954d0d9 | 64 | static const int tcg_target_reg_alloc_order[] = { |
8289b279 BS |
65 | TCG_REG_L0, |
66 | TCG_REG_L1, | |
67 | TCG_REG_L2, | |
68 | TCG_REG_L3, | |
69 | TCG_REG_L4, | |
70 | TCG_REG_L5, | |
71 | TCG_REG_L6, | |
72 | TCG_REG_L7, | |
73 | TCG_REG_I0, | |
74 | TCG_REG_I1, | |
75 | TCG_REG_I2, | |
76 | TCG_REG_I3, | |
77 | TCG_REG_I4, | |
8289b279 BS |
78 | }; |
79 | ||
80 | static const int tcg_target_call_iarg_regs[6] = { | |
81 | TCG_REG_O0, | |
82 | TCG_REG_O1, | |
83 | TCG_REG_O2, | |
84 | TCG_REG_O3, | |
85 | TCG_REG_O4, | |
86 | TCG_REG_O5, | |
87 | }; | |
88 | ||
26a74ae3 | 89 | static const int tcg_target_call_oarg_regs[] = { |
8289b279 | 90 | TCG_REG_O0, |
e141ab52 BS |
91 | TCG_REG_O1, |
92 | TCG_REG_O2, | |
93 | TCG_REG_O3, | |
8289b279 BS |
94 | }; |
95 | ||
57e49b40 | 96 | static inline int check_fit_tl(tcg_target_long val, unsigned int bits) |
f5ef6aac | 97 | { |
57e49b40 BS |
98 | return (val << ((sizeof(tcg_target_long) * 8 - bits)) |
99 | >> (sizeof(tcg_target_long) * 8 - bits)) == val; | |
100 | } | |
101 | ||
102 | static inline int check_fit_i32(uint32_t val, unsigned int bits) | |
103 | { | |
104 | return ((val << (32 - bits)) >> (32 - bits)) == val; | |
f5ef6aac BS |
105 | } |
106 | ||
8289b279 | 107 | static void patch_reloc(uint8_t *code_ptr, int type, |
f54b3f92 | 108 | tcg_target_long value, tcg_target_long addend) |
8289b279 | 109 | { |
f54b3f92 | 110 | value += addend; |
8289b279 BS |
111 | switch (type) { |
112 | case R_SPARC_32: | |
113 | if (value != (uint32_t)value) | |
114 | tcg_abort(); | |
115 | *(uint32_t *)code_ptr = value; | |
116 | break; | |
f5ef6aac BS |
117 | case R_SPARC_WDISP22: |
118 | value -= (long)code_ptr; | |
119 | value >>= 2; | |
57e49b40 | 120 | if (!check_fit_tl(value, 22)) |
f5ef6aac BS |
121 | tcg_abort(); |
122 | *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x3fffff) | value; | |
123 | break; | |
1da92db2 BS |
124 | case R_SPARC_WDISP19: |
125 | value -= (long)code_ptr; | |
126 | value >>= 2; | |
127 | if (!check_fit_tl(value, 19)) | |
128 | tcg_abort(); | |
129 | *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x7ffff) | value; | |
130 | break; | |
8289b279 BS |
131 | default: |
132 | tcg_abort(); | |
133 | } | |
134 | } | |
135 | ||
136 | /* maximum number of register used for input function arguments */ | |
137 | static inline int tcg_target_get_call_iarg_regs_count(int flags) | |
138 | { | |
139 | return 6; | |
140 | } | |
141 | ||
142 | /* parse target specific constraints */ | |
143 | static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) | |
144 | { | |
145 | const char *ct_str; | |
146 | ||
147 | ct_str = *pct_str; | |
148 | switch (ct_str[0]) { | |
149 | case 'r': | |
5e143c43 RH |
150 | ct->ct |= TCG_CT_REG; |
151 | tcg_regset_set32(ct->u.regs, 0, 0xffffffff); | |
152 | break; | |
8289b279 BS |
153 | case 'L': /* qemu_ld/st constraint */ |
154 | ct->ct |= TCG_CT_REG; | |
155 | tcg_regset_set32(ct->u.regs, 0, 0xffffffff); | |
53c37487 BS |
156 | // Helper args |
157 | tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0); | |
158 | tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1); | |
159 | tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2); | |
e141ab52 | 160 | tcg_regset_reset_reg(ct->u.regs, TCG_REG_O3); |
8289b279 BS |
161 | break; |
162 | case 'I': | |
163 | ct->ct |= TCG_CT_CONST_S11; | |
164 | break; | |
165 | case 'J': | |
166 | ct->ct |= TCG_CT_CONST_S13; | |
167 | break; | |
168 | default: | |
169 | return -1; | |
170 | } | |
171 | ct_str++; | |
172 | *pct_str = ct_str; | |
173 | return 0; | |
174 | } | |
175 | ||
8289b279 BS |
176 | /* test if a constant matches the constraint */ |
177 | static inline int tcg_target_const_match(tcg_target_long val, | |
178 | const TCGArgConstraint *arg_ct) | |
179 | { | |
180 | int ct; | |
181 | ||
182 | ct = arg_ct->ct; | |
183 | if (ct & TCG_CT_CONST) | |
184 | return 1; | |
57e49b40 | 185 | else if ((ct & TCG_CT_CONST_S11) && check_fit_tl(val, 11)) |
8289b279 | 186 | return 1; |
57e49b40 | 187 | else if ((ct & TCG_CT_CONST_S13) && check_fit_tl(val, 13)) |
8289b279 BS |
188 | return 1; |
189 | else | |
190 | return 0; | |
191 | } | |
192 | ||
193 | #define INSN_OP(x) ((x) << 30) | |
194 | #define INSN_OP2(x) ((x) << 22) | |
195 | #define INSN_OP3(x) ((x) << 19) | |
196 | #define INSN_OPF(x) ((x) << 5) | |
197 | #define INSN_RD(x) ((x) << 25) | |
198 | #define INSN_RS1(x) ((x) << 14) | |
199 | #define INSN_RS2(x) (x) | |
8384dd67 | 200 | #define INSN_ASI(x) ((x) << 5) |
8289b279 | 201 | |
dbfe80e1 | 202 | #define INSN_IMM11(x) ((1 << 13) | ((x) & 0x7ff)) |
8289b279 | 203 | #define INSN_IMM13(x) ((1 << 13) | ((x) & 0x1fff)) |
1da92db2 | 204 | #define INSN_OFF19(x) (((x) >> 2) & 0x07ffff) |
b3db8758 | 205 | #define INSN_OFF22(x) (((x) >> 2) & 0x3fffff) |
8289b279 | 206 | |
b3db8758 | 207 | #define INSN_COND(x, a) (((x) << 25) | ((a) << 29)) |
cf7c2ca5 BS |
208 | #define COND_N 0x0 |
209 | #define COND_E 0x1 | |
210 | #define COND_LE 0x2 | |
211 | #define COND_L 0x3 | |
212 | #define COND_LEU 0x4 | |
213 | #define COND_CS 0x5 | |
214 | #define COND_NEG 0x6 | |
215 | #define COND_VS 0x7 | |
b3db8758 | 216 | #define COND_A 0x8 |
cf7c2ca5 BS |
217 | #define COND_NE 0x9 |
218 | #define COND_G 0xa | |
219 | #define COND_GE 0xb | |
220 | #define COND_GU 0xc | |
221 | #define COND_CC 0xd | |
222 | #define COND_POS 0xe | |
223 | #define COND_VC 0xf | |
b3db8758 | 224 | #define BA (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2)) |
8289b279 | 225 | |
dbfe80e1 RH |
226 | #define MOVCC_ICC (1 << 18) |
227 | #define MOVCC_XCC (1 << 18 | 1 << 12) | |
228 | ||
8289b279 | 229 | #define ARITH_ADD (INSN_OP(2) | INSN_OP3(0x00)) |
7a3766f3 | 230 | #define ARITH_ADDCC (INSN_OP(2) | INSN_OP3(0x10)) |
8289b279 | 231 | #define ARITH_AND (INSN_OP(2) | INSN_OP3(0x01)) |
dc69960d | 232 | #define ARITH_ANDN (INSN_OP(2) | INSN_OP3(0x05)) |
8289b279 | 233 | #define ARITH_OR (INSN_OP(2) | INSN_OP3(0x02)) |
9a7f3228 | 234 | #define ARITH_ORCC (INSN_OP(2) | INSN_OP3(0x12)) |
be6551b1 | 235 | #define ARITH_ORN (INSN_OP(2) | INSN_OP3(0x06)) |
8289b279 | 236 | #define ARITH_XOR (INSN_OP(2) | INSN_OP3(0x03)) |
f5ef6aac BS |
237 | #define ARITH_SUB (INSN_OP(2) | INSN_OP3(0x04)) |
238 | #define ARITH_SUBCC (INSN_OP(2) | INSN_OP3(0x14)) | |
a221ae3f | 239 | #define ARITH_ADDX (INSN_OP(2) | INSN_OP3(0x08)) |
8289b279 BS |
240 | #define ARITH_SUBX (INSN_OP(2) | INSN_OP3(0x0c)) |
241 | #define ARITH_UMUL (INSN_OP(2) | INSN_OP3(0x0a)) | |
242 | #define ARITH_UDIV (INSN_OP(2) | INSN_OP3(0x0e)) | |
243 | #define ARITH_SDIV (INSN_OP(2) | INSN_OP3(0x0f)) | |
244 | #define ARITH_MULX (INSN_OP(2) | INSN_OP3(0x09)) | |
245 | #define ARITH_UDIVX (INSN_OP(2) | INSN_OP3(0x0d)) | |
246 | #define ARITH_SDIVX (INSN_OP(2) | INSN_OP3(0x2d)) | |
dbfe80e1 | 247 | #define ARITH_MOVCC (INSN_OP(2) | INSN_OP3(0x2c)) |
8289b279 BS |
248 | |
249 | #define SHIFT_SLL (INSN_OP(2) | INSN_OP3(0x25)) | |
250 | #define SHIFT_SRL (INSN_OP(2) | INSN_OP3(0x26)) | |
251 | #define SHIFT_SRA (INSN_OP(2) | INSN_OP3(0x27)) | |
252 | ||
253 | #define SHIFT_SLLX (INSN_OP(2) | INSN_OP3(0x25) | (1 << 12)) | |
254 | #define SHIFT_SRLX (INSN_OP(2) | INSN_OP3(0x26) | (1 << 12)) | |
255 | #define SHIFT_SRAX (INSN_OP(2) | INSN_OP3(0x27) | (1 << 12)) | |
256 | ||
7a3766f3 | 257 | #define RDY (INSN_OP(2) | INSN_OP3(0x28) | INSN_RS1(0)) |
583d1215 | 258 | #define WRY (INSN_OP(2) | INSN_OP3(0x30) | INSN_RD(0)) |
8289b279 BS |
259 | #define JMPL (INSN_OP(2) | INSN_OP3(0x38)) |
260 | #define SAVE (INSN_OP(2) | INSN_OP3(0x3c)) | |
261 | #define RESTORE (INSN_OP(2) | INSN_OP3(0x3d)) | |
262 | #define SETHI (INSN_OP(0) | INSN_OP2(0x4)) | |
263 | #define CALL INSN_OP(1) | |
264 | #define LDUB (INSN_OP(3) | INSN_OP3(0x01)) | |
265 | #define LDSB (INSN_OP(3) | INSN_OP3(0x09)) | |
266 | #define LDUH (INSN_OP(3) | INSN_OP3(0x02)) | |
267 | #define LDSH (INSN_OP(3) | INSN_OP3(0x0a)) | |
268 | #define LDUW (INSN_OP(3) | INSN_OP3(0x00)) | |
269 | #define LDSW (INSN_OP(3) | INSN_OP3(0x08)) | |
270 | #define LDX (INSN_OP(3) | INSN_OP3(0x0b)) | |
271 | #define STB (INSN_OP(3) | INSN_OP3(0x05)) | |
272 | #define STH (INSN_OP(3) | INSN_OP3(0x06)) | |
273 | #define STW (INSN_OP(3) | INSN_OP3(0x04)) | |
274 | #define STX (INSN_OP(3) | INSN_OP3(0x0e)) | |
8384dd67 BS |
275 | #define LDUBA (INSN_OP(3) | INSN_OP3(0x11)) |
276 | #define LDSBA (INSN_OP(3) | INSN_OP3(0x19)) | |
277 | #define LDUHA (INSN_OP(3) | INSN_OP3(0x12)) | |
278 | #define LDSHA (INSN_OP(3) | INSN_OP3(0x1a)) | |
279 | #define LDUWA (INSN_OP(3) | INSN_OP3(0x10)) | |
280 | #define LDSWA (INSN_OP(3) | INSN_OP3(0x18)) | |
281 | #define LDXA (INSN_OP(3) | INSN_OP3(0x1b)) | |
282 | #define STBA (INSN_OP(3) | INSN_OP3(0x15)) | |
283 | #define STHA (INSN_OP(3) | INSN_OP3(0x16)) | |
284 | #define STWA (INSN_OP(3) | INSN_OP3(0x14)) | |
285 | #define STXA (INSN_OP(3) | INSN_OP3(0x1e)) | |
286 | ||
287 | #ifndef ASI_PRIMARY_LITTLE | |
288 | #define ASI_PRIMARY_LITTLE 0x88 | |
289 | #endif | |
8289b279 | 290 | |
26cc915c BS |
291 | static inline void tcg_out_arith(TCGContext *s, int rd, int rs1, int rs2, |
292 | int op) | |
293 | { | |
294 | tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) | | |
295 | INSN_RS2(rs2)); | |
296 | } | |
297 | ||
6f41b777 BS |
298 | static inline void tcg_out_arithi(TCGContext *s, int rd, int rs1, |
299 | uint32_t offset, int op) | |
26cc915c BS |
300 | { |
301 | tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) | | |
302 | INSN_IMM13(offset)); | |
303 | } | |
304 | ||
ba225198 RH |
305 | static void tcg_out_arithc(TCGContext *s, int rd, int rs1, |
306 | int val2, int val2const, int op) | |
307 | { | |
308 | tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) | |
309 | | (val2const ? INSN_IMM13(val2) : INSN_RS2(val2))); | |
310 | } | |
311 | ||
2a534aff RH |
312 | static inline void tcg_out_mov(TCGContext *s, TCGType type, |
313 | TCGReg ret, TCGReg arg) | |
8289b279 | 314 | { |
26cc915c BS |
315 | tcg_out_arith(s, ret, arg, TCG_REG_G0, ARITH_OR); |
316 | } | |
317 | ||
318 | static inline void tcg_out_sethi(TCGContext *s, int ret, uint32_t arg) | |
319 | { | |
320 | tcg_out32(s, SETHI | INSN_RD(ret) | ((arg & 0xfffffc00) >> 10)); | |
8289b279 BS |
321 | } |
322 | ||
b101234a BS |
323 | static inline void tcg_out_movi_imm13(TCGContext *s, int ret, uint32_t arg) |
324 | { | |
325 | tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR); | |
326 | } | |
327 | ||
328 | static inline void tcg_out_movi_imm32(TCGContext *s, int ret, uint32_t arg) | |
8289b279 | 329 | { |
4a09aa89 | 330 | if (check_fit_tl(arg, 13)) |
b101234a | 331 | tcg_out_movi_imm13(s, ret, arg); |
8289b279 | 332 | else { |
26cc915c | 333 | tcg_out_sethi(s, ret, arg); |
8289b279 | 334 | if (arg & 0x3ff) |
b101234a | 335 | tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR); |
8289b279 BS |
336 | } |
337 | } | |
338 | ||
b101234a | 339 | static inline void tcg_out_movi(TCGContext *s, TCGType type, |
2a534aff | 340 | TCGReg ret, tcg_target_long arg) |
b101234a | 341 | { |
43172207 RH |
342 | /* All 32-bit constants, as well as 64-bit constants with |
343 | no high bits set go through movi_imm32. */ | |
344 | if (TCG_TARGET_REG_BITS == 32 | |
345 | || type == TCG_TYPE_I32 | |
346 | || (arg & ~(tcg_target_long)0xffffffff) == 0) { | |
347 | tcg_out_movi_imm32(s, ret, arg); | |
348 | } else if (check_fit_tl(arg, 13)) { | |
349 | /* A 13-bit constant sign-extended to 64-bits. */ | |
350 | tcg_out_movi_imm13(s, ret, arg); | |
351 | } else if (check_fit_tl(arg, 32)) { | |
352 | /* A 32-bit constant sign-extended to 64-bits. */ | |
353 | tcg_out_sethi(s, ret, ~arg); | |
354 | tcg_out_arithi(s, ret, ret, (arg & 0x3ff) | -0x400, ARITH_XOR); | |
355 | } else { | |
356 | tcg_out_movi_imm32(s, TCG_REG_I4, arg >> (TCG_TARGET_REG_BITS / 2)); | |
d795eb86 | 357 | tcg_out_arithi(s, TCG_REG_I4, TCG_REG_I4, 32, SHIFT_SLLX); |
b101234a | 358 | tcg_out_movi_imm32(s, ret, arg); |
d795eb86 | 359 | tcg_out_arith(s, ret, ret, TCG_REG_I4, ARITH_OR); |
6f41b777 | 360 | } |
b101234a BS |
361 | } |
362 | ||
8289b279 BS |
363 | static inline void tcg_out_ld_raw(TCGContext *s, int ret, |
364 | tcg_target_long arg) | |
365 | { | |
26cc915c | 366 | tcg_out_sethi(s, ret, arg); |
8289b279 BS |
367 | tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) | |
368 | INSN_IMM13(arg & 0x3ff)); | |
369 | } | |
370 | ||
b3db8758 BS |
371 | static inline void tcg_out_ld_ptr(TCGContext *s, int ret, |
372 | tcg_target_long arg) | |
373 | { | |
b101234a BS |
374 | if (!check_fit_tl(arg, 10)) |
375 | tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ffULL); | |
a212ea75 RH |
376 | if (TCG_TARGET_REG_BITS == 64) { |
377 | tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) | | |
378 | INSN_IMM13(arg & 0x3ff)); | |
379 | } else { | |
380 | tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) | | |
381 | INSN_IMM13(arg & 0x3ff)); | |
382 | } | |
b3db8758 BS |
383 | } |
384 | ||
8289b279 BS |
385 | static inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op) |
386 | { | |
57e49b40 | 387 | if (check_fit_tl(offset, 13)) |
8289b279 BS |
388 | tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) | |
389 | INSN_IMM13(offset)); | |
cf7c2ca5 BS |
390 | else { |
391 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset); | |
392 | tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) | | |
393 | INSN_RS2(addr)); | |
394 | } | |
8289b279 BS |
395 | } |
396 | ||
8384dd67 BS |
397 | static inline void tcg_out_ldst_asi(TCGContext *s, int ret, int addr, |
398 | int offset, int op, int asi) | |
399 | { | |
400 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset); | |
401 | tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) | | |
402 | INSN_ASI(asi) | INSN_RS2(addr)); | |
403 | } | |
404 | ||
2a534aff RH |
405 | static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg ret, |
406 | TCGReg arg1, tcg_target_long arg2) | |
8289b279 | 407 | { |
7d551702 BS |
408 | if (type == TCG_TYPE_I32) |
409 | tcg_out_ldst(s, ret, arg1, arg2, LDUW); | |
410 | else | |
411 | tcg_out_ldst(s, ret, arg1, arg2, LDX); | |
8289b279 BS |
412 | } |
413 | ||
2a534aff RH |
414 | static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, |
415 | TCGReg arg1, tcg_target_long arg2) | |
8289b279 | 416 | { |
7d551702 BS |
417 | if (type == TCG_TYPE_I32) |
418 | tcg_out_ldst(s, arg, arg1, arg2, STW); | |
419 | else | |
420 | tcg_out_ldst(s, arg, arg1, arg2, STX); | |
8289b279 BS |
421 | } |
422 | ||
583d1215 | 423 | static inline void tcg_out_sety(TCGContext *s, int rs) |
8289b279 | 424 | { |
583d1215 | 425 | tcg_out32(s, WRY | INSN_RS1(TCG_REG_G0) | INSN_RS2(rs)); |
8289b279 BS |
426 | } |
427 | ||
7a3766f3 RH |
428 | static inline void tcg_out_rdy(TCGContext *s, int rd) |
429 | { | |
430 | tcg_out32(s, RDY | INSN_RD(rd)); | |
431 | } | |
432 | ||
8289b279 BS |
433 | static inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val) |
434 | { | |
435 | if (val != 0) { | |
57e49b40 | 436 | if (check_fit_tl(val, 13)) |
8289b279 | 437 | tcg_out_arithi(s, reg, reg, val, ARITH_ADD); |
f5ef6aac BS |
438 | else { |
439 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, val); | |
440 | tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_ADD); | |
441 | } | |
8289b279 BS |
442 | } |
443 | } | |
444 | ||
53c37487 BS |
445 | static inline void tcg_out_andi(TCGContext *s, int reg, tcg_target_long val) |
446 | { | |
447 | if (val != 0) { | |
448 | if (check_fit_tl(val, 13)) | |
449 | tcg_out_arithi(s, reg, reg, val, ARITH_AND); | |
450 | else { | |
451 | tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, val); | |
452 | tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_AND); | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
583d1215 RH |
457 | static void tcg_out_div32(TCGContext *s, int rd, int rs1, |
458 | int val2, int val2const, int uns) | |
459 | { | |
460 | /* Load Y with the sign/zero extension of RS1 to 64-bits. */ | |
461 | if (uns) { | |
462 | tcg_out_sety(s, TCG_REG_G0); | |
463 | } else { | |
464 | tcg_out_arithi(s, TCG_REG_I5, rs1, 31, SHIFT_SRA); | |
465 | tcg_out_sety(s, TCG_REG_I5); | |
466 | } | |
467 | ||
468 | tcg_out_arithc(s, rd, rs1, val2, val2const, | |
469 | uns ? ARITH_UDIV : ARITH_SDIV); | |
470 | } | |
471 | ||
8289b279 BS |
472 | static inline void tcg_out_nop(TCGContext *s) |
473 | { | |
26cc915c | 474 | tcg_out_sethi(s, TCG_REG_G0, 0); |
8289b279 BS |
475 | } |
476 | ||
1da92db2 | 477 | static void tcg_out_branch_i32(TCGContext *s, int opc, int label_index) |
cf7c2ca5 | 478 | { |
cf7c2ca5 BS |
479 | TCGLabel *l = &s->labels[label_index]; |
480 | ||
481 | if (l->has_value) { | |
f5ef6aac | 482 | tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2) |
cf7c2ca5 | 483 | | INSN_OFF22(l->u.value - (unsigned long)s->code_ptr))); |
f5ef6aac BS |
484 | } else { |
485 | tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP22, label_index, 0); | |
486 | tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2) | 0)); | |
487 | } | |
cf7c2ca5 BS |
488 | } |
489 | ||
a212ea75 | 490 | #if TCG_TARGET_REG_BITS == 64 |
1da92db2 BS |
491 | static void tcg_out_branch_i64(TCGContext *s, int opc, int label_index) |
492 | { | |
1da92db2 BS |
493 | TCGLabel *l = &s->labels[label_index]; |
494 | ||
495 | if (l->has_value) { | |
1da92db2 BS |
496 | tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x1) | |
497 | (0x5 << 19) | | |
498 | INSN_OFF19(l->u.value - (unsigned long)s->code_ptr))); | |
499 | } else { | |
500 | tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP19, label_index, 0); | |
501 | tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x1) | | |
502 | (0x5 << 19) | 0)); | |
503 | } | |
504 | } | |
505 | #endif | |
506 | ||
cf7c2ca5 BS |
507 | static const uint8_t tcg_cond_to_bcond[10] = { |
508 | [TCG_COND_EQ] = COND_E, | |
509 | [TCG_COND_NE] = COND_NE, | |
510 | [TCG_COND_LT] = COND_L, | |
511 | [TCG_COND_GE] = COND_GE, | |
512 | [TCG_COND_LE] = COND_LE, | |
513 | [TCG_COND_GT] = COND_G, | |
514 | [TCG_COND_LTU] = COND_CS, | |
515 | [TCG_COND_GEU] = COND_CC, | |
516 | [TCG_COND_LEU] = COND_LEU, | |
517 | [TCG_COND_GTU] = COND_GU, | |
518 | }; | |
519 | ||
56f4927e RH |
520 | static void tcg_out_cmp(TCGContext *s, TCGArg c1, TCGArg c2, int c2const) |
521 | { | |
ba225198 | 522 | tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, ARITH_SUBCC); |
56f4927e RH |
523 | } |
524 | ||
8a56e840 | 525 | static void tcg_out_brcond_i32(TCGContext *s, TCGCond cond, |
1da92db2 BS |
526 | TCGArg arg1, TCGArg arg2, int const_arg2, |
527 | int label_index) | |
cf7c2ca5 | 528 | { |
56f4927e | 529 | tcg_out_cmp(s, arg1, arg2, const_arg2); |
1da92db2 | 530 | tcg_out_branch_i32(s, tcg_cond_to_bcond[cond], label_index); |
cf7c2ca5 BS |
531 | tcg_out_nop(s); |
532 | } | |
533 | ||
a212ea75 | 534 | #if TCG_TARGET_REG_BITS == 64 |
8a56e840 | 535 | static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, |
1da92db2 BS |
536 | TCGArg arg1, TCGArg arg2, int const_arg2, |
537 | int label_index) | |
538 | { | |
56f4927e | 539 | tcg_out_cmp(s, arg1, arg2, const_arg2); |
1da92db2 BS |
540 | tcg_out_branch_i64(s, tcg_cond_to_bcond[cond], label_index); |
541 | tcg_out_nop(s); | |
542 | } | |
56f4927e | 543 | #else |
8a56e840 | 544 | static void tcg_out_brcond2_i32(TCGContext *s, TCGCond cond, |
56f4927e RH |
545 | TCGArg al, TCGArg ah, |
546 | TCGArg bl, int blconst, | |
547 | TCGArg bh, int bhconst, int label_dest) | |
548 | { | |
549 | int cc, label_next = gen_new_label(); | |
550 | ||
551 | tcg_out_cmp(s, ah, bh, bhconst); | |
552 | ||
553 | /* Note that we fill one of the delay slots with the second compare. */ | |
554 | switch (cond) { | |
555 | case TCG_COND_EQ: | |
556 | cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0); | |
557 | tcg_out_branch_i32(s, cc, label_next); | |
558 | tcg_out_cmp(s, al, bl, blconst); | |
559 | cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_EQ], 0); | |
560 | tcg_out_branch_i32(s, cc, label_dest); | |
561 | break; | |
562 | ||
563 | case TCG_COND_NE: | |
564 | cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0); | |
565 | tcg_out_branch_i32(s, cc, label_dest); | |
566 | tcg_out_cmp(s, al, bl, blconst); | |
567 | tcg_out_branch_i32(s, cc, label_dest); | |
568 | break; | |
569 | ||
570 | default: | |
571 | /* ??? One could fairly easily special-case 64-bit unsigned | |
572 | compares against 32-bit zero-extended constants. For instance, | |
573 | we know that (unsigned)AH < 0 is false and need not emit it. | |
574 | Similarly, (unsigned)AH > 0 being true implies AH != 0, so the | |
575 | second branch will never be taken. */ | |
576 | cc = INSN_COND(tcg_cond_to_bcond[cond], 0); | |
577 | tcg_out_branch_i32(s, cc, label_dest); | |
578 | tcg_out_nop(s); | |
579 | cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0); | |
580 | tcg_out_branch_i32(s, cc, label_next); | |
581 | tcg_out_cmp(s, al, bl, blconst); | |
582 | cc = INSN_COND(tcg_cond_to_bcond[tcg_unsigned_cond(cond)], 0); | |
583 | tcg_out_branch_i32(s, cc, label_dest); | |
584 | break; | |
585 | } | |
586 | tcg_out_nop(s); | |
587 | ||
9d6fca70 | 588 | tcg_out_label(s, label_next, s->code_ptr); |
56f4927e | 589 | } |
1da92db2 BS |
590 | #endif |
591 | ||
8a56e840 | 592 | static void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGArg ret, |
dbfe80e1 RH |
593 | TCGArg c1, TCGArg c2, int c2const) |
594 | { | |
595 | TCGArg t; | |
596 | ||
597 | /* For 32-bit comparisons, we can play games with ADDX/SUBX. */ | |
598 | switch (cond) { | |
599 | case TCG_COND_EQ: | |
600 | case TCG_COND_NE: | |
601 | if (c2 != 0) { | |
602 | tcg_out_arithc(s, ret, c1, c2, c2const, ARITH_XOR); | |
603 | } | |
604 | c1 = TCG_REG_G0, c2 = ret, c2const = 0; | |
605 | cond = (cond == TCG_COND_EQ ? TCG_COND_LEU : TCG_COND_LTU); | |
606 | break; | |
607 | ||
608 | case TCG_COND_GTU: | |
609 | case TCG_COND_GEU: | |
610 | if (c2const && c2 != 0) { | |
611 | tcg_out_movi_imm13(s, TCG_REG_I5, c2); | |
612 | c2 = TCG_REG_I5; | |
613 | } | |
614 | t = c1, c1 = c2, c2 = t, c2const = 0; | |
615 | cond = tcg_swap_cond(cond); | |
616 | break; | |
617 | ||
618 | case TCG_COND_LTU: | |
619 | case TCG_COND_LEU: | |
620 | break; | |
621 | ||
622 | default: | |
623 | tcg_out_cmp(s, c1, c2, c2const); | |
dbfe80e1 | 624 | tcg_out_movi_imm13(s, ret, 0); |
9b9c37c3 RH |
625 | tcg_out32(s, ARITH_MOVCC | INSN_RD(ret) |
626 | | INSN_RS1(tcg_cond_to_bcond[cond]) | |
627 | | MOVCC_ICC | INSN_IMM11(1)); | |
dbfe80e1 RH |
628 | return; |
629 | } | |
630 | ||
631 | tcg_out_cmp(s, c1, c2, c2const); | |
632 | if (cond == TCG_COND_LTU) { | |
633 | tcg_out_arithi(s, ret, TCG_REG_G0, 0, ARITH_ADDX); | |
634 | } else { | |
635 | tcg_out_arithi(s, ret, TCG_REG_G0, -1, ARITH_SUBX); | |
636 | } | |
637 | } | |
638 | ||
639 | #if TCG_TARGET_REG_BITS == 64 | |
8a56e840 | 640 | static void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGArg ret, |
dbfe80e1 RH |
641 | TCGArg c1, TCGArg c2, int c2const) |
642 | { | |
643 | tcg_out_cmp(s, c1, c2, c2const); | |
644 | tcg_out_movi_imm13(s, ret, 0); | |
645 | tcg_out32 (s, ARITH_MOVCC | INSN_RD(ret) | |
646 | | INSN_RS1(tcg_cond_to_bcond[cond]) | |
647 | | MOVCC_XCC | INSN_IMM11(1)); | |
648 | } | |
649 | #else | |
8a56e840 | 650 | static void tcg_out_setcond2_i32(TCGContext *s, TCGCond cond, TCGArg ret, |
dbfe80e1 RH |
651 | TCGArg al, TCGArg ah, |
652 | TCGArg bl, int blconst, | |
653 | TCGArg bh, int bhconst) | |
654 | { | |
655 | int lab; | |
656 | ||
657 | switch (cond) { | |
658 | case TCG_COND_EQ: | |
659 | tcg_out_setcond_i32(s, TCG_COND_EQ, TCG_REG_I5, al, bl, blconst); | |
660 | tcg_out_setcond_i32(s, TCG_COND_EQ, ret, ah, bh, bhconst); | |
661 | tcg_out_arith(s, ret, ret, TCG_REG_I5, ARITH_AND); | |
662 | break; | |
663 | ||
664 | case TCG_COND_NE: | |
665 | tcg_out_setcond_i32(s, TCG_COND_NE, TCG_REG_I5, al, al, blconst); | |
666 | tcg_out_setcond_i32(s, TCG_COND_NE, ret, ah, bh, bhconst); | |
667 | tcg_out_arith(s, ret, ret, TCG_REG_I5, ARITH_OR); | |
668 | break; | |
669 | ||
670 | default: | |
671 | lab = gen_new_label(); | |
672 | ||
673 | tcg_out_cmp(s, ah, bh, bhconst); | |
674 | tcg_out_branch_i32(s, INSN_COND(tcg_cond_to_bcond[cond], 1), lab); | |
675 | tcg_out_movi_imm13(s, ret, 1); | |
676 | tcg_out_branch_i32(s, INSN_COND(COND_NE, 1), lab); | |
677 | tcg_out_movi_imm13(s, ret, 0); | |
678 | ||
679 | tcg_out_setcond_i32(s, tcg_unsigned_cond(cond), ret, al, bl, blconst); | |
680 | ||
9d6fca70 | 681 | tcg_out_label(s, lab, s->code_ptr); |
dbfe80e1 RH |
682 | break; |
683 | } | |
684 | } | |
685 | #endif | |
686 | ||
7d551702 | 687 | /* Generate global QEMU prologue and epilogue code */ |
e4d58b41 | 688 | static void tcg_target_qemu_prologue(TCGContext *s) |
b3db8758 | 689 | { |
f44c9960 BS |
690 | tcg_set_frame(s, TCG_REG_I6, TCG_TARGET_CALL_STACK_OFFSET, |
691 | CPU_TEMP_BUF_NLONGS * (int)sizeof(long)); | |
b3db8758 | 692 | tcg_out32(s, SAVE | INSN_RD(TCG_REG_O6) | INSN_RS1(TCG_REG_O6) | |
f44c9960 BS |
693 | INSN_IMM13(-(TCG_TARGET_STACK_MINFRAME + |
694 | CPU_TEMP_BUF_NLONGS * (int)sizeof(long)))); | |
cea5f9a2 | 695 | tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I1) | |
7d551702 | 696 | INSN_RS2(TCG_REG_G0)); |
cea5f9a2 | 697 | tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, TCG_REG_I0); |
b3db8758 BS |
698 | } |
699 | ||
f5ef6aac | 700 | #if defined(CONFIG_SOFTMMU) |
f5ef6aac | 701 | |
79383c9c | 702 | #include "../../softmmu_defs.h" |
f5ef6aac | 703 | |
e141ab52 BS |
704 | /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr, |
705 | int mmu_idx) */ | |
706 | static const void * const qemu_ld_helpers[4] = { | |
707 | helper_ldb_mmu, | |
708 | helper_ldw_mmu, | |
709 | helper_ldl_mmu, | |
710 | helper_ldq_mmu, | |
711 | }; | |
712 | ||
713 | /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr, | |
714 | uintxx_t val, int mmu_idx) */ | |
715 | static const void * const qemu_st_helpers[4] = { | |
716 | helper_stb_mmu, | |
717 | helper_stw_mmu, | |
718 | helper_stl_mmu, | |
719 | helper_stq_mmu, | |
720 | }; | |
e141ab52 | 721 | #endif |
f5ef6aac | 722 | |
bffe1431 BS |
723 | #if TARGET_LONG_BITS == 32 |
724 | #define TARGET_LD_OP LDUW | |
725 | #else | |
726 | #define TARGET_LD_OP LDX | |
727 | #endif | |
728 | ||
65850a02 | 729 | #if defined(CONFIG_SOFTMMU) |
355b1943 | 730 | #if HOST_LONG_BITS == 32 |
65850a02 BS |
731 | #define TARGET_ADDEND_LD_OP LDUW |
732 | #else | |
733 | #define TARGET_ADDEND_LD_OP LDX | |
734 | #endif | |
735 | #endif | |
9d0efc88 | 736 | |
9b9c37c3 | 737 | #if TCG_TARGET_REG_BITS == 64 |
bffe1431 BS |
738 | #define HOST_LD_OP LDX |
739 | #define HOST_ST_OP STX | |
740 | #define HOST_SLL_OP SHIFT_SLLX | |
741 | #define HOST_SRA_OP SHIFT_SRAX | |
742 | #else | |
743 | #define HOST_LD_OP LDUW | |
744 | #define HOST_ST_OP STW | |
745 | #define HOST_SLL_OP SHIFT_SLL | |
746 | #define HOST_SRA_OP SHIFT_SRA | |
747 | #endif | |
748 | ||
f5ef6aac BS |
749 | static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, |
750 | int opc) | |
751 | { | |
56fc64df | 752 | int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits; |
f5ef6aac | 753 | #if defined(CONFIG_SOFTMMU) |
53c37487 | 754 | uint32_t *label1_ptr, *label2_ptr; |
f5ef6aac BS |
755 | #endif |
756 | ||
757 | data_reg = *args++; | |
758 | addr_reg = *args++; | |
759 | mem_index = *args; | |
760 | s_bits = opc & 3; | |
761 | ||
53c37487 BS |
762 | arg0 = TCG_REG_O0; |
763 | arg1 = TCG_REG_O1; | |
56fc64df | 764 | arg2 = TCG_REG_O2; |
f5ef6aac | 765 | |
f5ef6aac | 766 | #if defined(CONFIG_SOFTMMU) |
56fc64df BS |
767 | /* srl addr_reg, x, arg1 */ |
768 | tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS, | |
f5ef6aac | 769 | SHIFT_SRL); |
56fc64df BS |
770 | /* and addr_reg, x, arg0 */ |
771 | tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1), | |
f5ef6aac BS |
772 | ARITH_AND); |
773 | ||
56fc64df BS |
774 | /* and arg1, x, arg1 */ |
775 | tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS); | |
f5ef6aac | 776 | |
56fc64df | 777 | /* add arg1, x, arg1 */ |
9349b4f9 | 778 | tcg_out_addi(s, arg1, offsetof(CPUArchState, |
56fc64df | 779 | tlb_table[mem_index][0].addr_read)); |
53c37487 | 780 | |
56fc64df BS |
781 | /* add env, arg1, arg1 */ |
782 | tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD); | |
f5ef6aac | 783 | |
56fc64df | 784 | /* ld [arg1], arg2 */ |
bffe1431 | 785 | tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) | |
56fc64df | 786 | INSN_RS2(TCG_REG_G0)); |
f5ef6aac | 787 | |
56fc64df BS |
788 | /* subcc arg0, arg2, %g0 */ |
789 | tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC); | |
f5ef6aac BS |
790 | |
791 | /* will become: | |
1da92db2 BS |
792 | be label1 |
793 | or | |
794 | be,pt %xcc label1 */ | |
53c37487 | 795 | label1_ptr = (uint32_t *)s->code_ptr; |
f5ef6aac BS |
796 | tcg_out32(s, 0); |
797 | ||
53c37487 | 798 | /* mov (delay slot) */ |
3b6dac34 | 799 | tcg_out_mov(s, TCG_TYPE_PTR, arg0, addr_reg); |
f5ef6aac | 800 | |
bffe1431 BS |
801 | /* mov */ |
802 | tcg_out_movi(s, TCG_TYPE_I32, arg1, mem_index); | |
e141ab52 BS |
803 | /* XXX/FIXME: suboptimal */ |
804 | tcg_out_mov(s, TCG_TYPE_I32, tcg_target_call_iarg_regs[3], | |
805 | tcg_target_call_iarg_regs[2]); | |
806 | tcg_out_mov(s, TCG_TYPE_I64, tcg_target_call_iarg_regs[2], | |
807 | tcg_target_call_iarg_regs[1]); | |
808 | tcg_out_mov(s, TCG_TYPE_TL, tcg_target_call_iarg_regs[1], | |
809 | tcg_target_call_iarg_regs[0]); | |
810 | tcg_out_mov(s, TCG_TYPE_PTR, tcg_target_call_iarg_regs[0], | |
811 | TCG_AREG0); | |
bffe1431 | 812 | |
f5ef6aac | 813 | /* XXX: move that code at the end of the TB */ |
53c37487 | 814 | /* qemu_ld_helper[s_bits](arg0, arg1) */ |
f5ef6aac BS |
815 | tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_ld_helpers[s_bits] |
816 | - (tcg_target_ulong)s->code_ptr) >> 2) | |
817 | & 0x3fffffff)); | |
bffe1431 BS |
818 | /* Store AREG0 in stack to avoid ugly glibc bugs that mangle |
819 | global registers */ | |
820 | // delay slot | |
821 | tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, | |
f843e528 BS |
822 | TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE - |
823 | sizeof(long), HOST_ST_OP); | |
bffe1431 | 824 | tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, |
f843e528 BS |
825 | TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE - |
826 | sizeof(long), HOST_LD_OP); | |
f5ef6aac | 827 | |
53c37487 | 828 | /* data_reg = sign_extend(arg0) */ |
f5ef6aac BS |
829 | switch(opc) { |
830 | case 0 | 4: | |
53c37487 | 831 | /* sll arg0, 24/56, data_reg */ |
56fc64df | 832 | tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 8, |
bffe1431 | 833 | HOST_SLL_OP); |
53c37487 | 834 | /* sra data_reg, 24/56, data_reg */ |
56fc64df | 835 | tcg_out_arithi(s, data_reg, data_reg, |
bffe1431 | 836 | (int)sizeof(tcg_target_long) * 8 - 8, HOST_SRA_OP); |
f5ef6aac BS |
837 | break; |
838 | case 1 | 4: | |
53c37487 | 839 | /* sll arg0, 16/48, data_reg */ |
56fc64df | 840 | tcg_out_arithi(s, data_reg, arg0, |
bffe1431 | 841 | (int)sizeof(tcg_target_long) * 8 - 16, HOST_SLL_OP); |
53c37487 | 842 | /* sra data_reg, 16/48, data_reg */ |
56fc64df | 843 | tcg_out_arithi(s, data_reg, data_reg, |
bffe1431 | 844 | (int)sizeof(tcg_target_long) * 8 - 16, HOST_SRA_OP); |
f5ef6aac BS |
845 | break; |
846 | case 2 | 4: | |
53c37487 | 847 | /* sll arg0, 32, data_reg */ |
bffe1431 | 848 | tcg_out_arithi(s, data_reg, arg0, 32, HOST_SLL_OP); |
53c37487 | 849 | /* sra data_reg, 32, data_reg */ |
bffe1431 | 850 | tcg_out_arithi(s, data_reg, data_reg, 32, HOST_SRA_OP); |
f5ef6aac BS |
851 | break; |
852 | case 0: | |
853 | case 1: | |
854 | case 2: | |
855 | case 3: | |
856 | default: | |
857 | /* mov */ | |
3b6dac34 | 858 | tcg_out_mov(s, TCG_TYPE_REG, data_reg, arg0); |
f5ef6aac BS |
859 | break; |
860 | } | |
861 | ||
862 | /* will become: | |
863 | ba label2 */ | |
53c37487 | 864 | label2_ptr = (uint32_t *)s->code_ptr; |
f5ef6aac BS |
865 | tcg_out32(s, 0); |
866 | ||
53c37487 BS |
867 | /* nop (delay slot */ |
868 | tcg_out_nop(s); | |
869 | ||
f5ef6aac | 870 | /* label1: */ |
1da92db2 BS |
871 | #if TARGET_LONG_BITS == 32 |
872 | /* be label1 */ | |
53c37487 BS |
873 | *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) | |
874 | INSN_OFF22((unsigned long)s->code_ptr - | |
875 | (unsigned long)label1_ptr)); | |
1da92db2 BS |
876 | #else |
877 | /* be,pt %xcc label1 */ | |
878 | *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x1) | | |
879 | (0x5 << 19) | INSN_OFF19((unsigned long)s->code_ptr - | |
880 | (unsigned long)label1_ptr)); | |
881 | #endif | |
f5ef6aac | 882 | |
56fc64df BS |
883 | /* ld [arg1 + x], arg1 */ |
884 | tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) - | |
9d0efc88 | 885 | offsetof(CPUTLBEntry, addr_read), TARGET_ADDEND_LD_OP); |
90cbed46 BS |
886 | |
887 | #if TARGET_LONG_BITS == 32 | |
888 | /* and addr_reg, x, arg0 */ | |
889 | tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, 0xffffffff); | |
890 | tcg_out_arith(s, arg0, addr_reg, TCG_REG_I5, ARITH_AND); | |
891 | /* add arg0, arg1, arg0 */ | |
892 | tcg_out_arith(s, arg0, arg0, arg1, ARITH_ADD); | |
893 | #else | |
56fc64df BS |
894 | /* add addr_reg, arg1, arg0 */ |
895 | tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD); | |
90cbed46 BS |
896 | #endif |
897 | ||
f5ef6aac | 898 | #else |
56fc64df | 899 | arg0 = addr_reg; |
f5ef6aac BS |
900 | #endif |
901 | ||
f5ef6aac BS |
902 | switch(opc) { |
903 | case 0: | |
56fc64df BS |
904 | /* ldub [arg0], data_reg */ |
905 | tcg_out_ldst(s, data_reg, arg0, 0, LDUB); | |
f5ef6aac BS |
906 | break; |
907 | case 0 | 4: | |
56fc64df BS |
908 | /* ldsb [arg0], data_reg */ |
909 | tcg_out_ldst(s, data_reg, arg0, 0, LDSB); | |
f5ef6aac BS |
910 | break; |
911 | case 1: | |
8384dd67 | 912 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
913 | /* lduh [arg0], data_reg */ |
914 | tcg_out_ldst(s, data_reg, arg0, 0, LDUH); | |
8384dd67 | 915 | #else |
56fc64df BS |
916 | /* lduha [arg0] ASI_PRIMARY_LITTLE, data_reg */ |
917 | tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUHA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 918 | #endif |
f5ef6aac BS |
919 | break; |
920 | case 1 | 4: | |
8384dd67 | 921 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
922 | /* ldsh [arg0], data_reg */ |
923 | tcg_out_ldst(s, data_reg, arg0, 0, LDSH); | |
8384dd67 | 924 | #else |
56fc64df BS |
925 | /* ldsha [arg0] ASI_PRIMARY_LITTLE, data_reg */ |
926 | tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSHA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 927 | #endif |
f5ef6aac BS |
928 | break; |
929 | case 2: | |
8384dd67 | 930 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
931 | /* lduw [arg0], data_reg */ |
932 | tcg_out_ldst(s, data_reg, arg0, 0, LDUW); | |
8384dd67 | 933 | #else |
56fc64df BS |
934 | /* lduwa [arg0] ASI_PRIMARY_LITTLE, data_reg */ |
935 | tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUWA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 936 | #endif |
f5ef6aac BS |
937 | break; |
938 | case 2 | 4: | |
8384dd67 | 939 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
940 | /* ldsw [arg0], data_reg */ |
941 | tcg_out_ldst(s, data_reg, arg0, 0, LDSW); | |
8384dd67 | 942 | #else |
56fc64df BS |
943 | /* ldswa [arg0] ASI_PRIMARY_LITTLE, data_reg */ |
944 | tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSWA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 945 | #endif |
f5ef6aac BS |
946 | break; |
947 | case 3: | |
8384dd67 | 948 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
949 | /* ldx [arg0], data_reg */ |
950 | tcg_out_ldst(s, data_reg, arg0, 0, LDX); | |
8384dd67 | 951 | #else |
56fc64df BS |
952 | /* ldxa [arg0] ASI_PRIMARY_LITTLE, data_reg */ |
953 | tcg_out_ldst_asi(s, data_reg, arg0, 0, LDXA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 954 | #endif |
f5ef6aac BS |
955 | break; |
956 | default: | |
957 | tcg_abort(); | |
958 | } | |
959 | ||
960 | #if defined(CONFIG_SOFTMMU) | |
961 | /* label2: */ | |
9a7f3228 | 962 | *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) | |
53c37487 BS |
963 | INSN_OFF22((unsigned long)s->code_ptr - |
964 | (unsigned long)label2_ptr)); | |
f5ef6aac BS |
965 | #endif |
966 | } | |
967 | ||
968 | static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, | |
969 | int opc) | |
970 | { | |
56fc64df | 971 | int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits; |
f5ef6aac | 972 | #if defined(CONFIG_SOFTMMU) |
53c37487 | 973 | uint32_t *label1_ptr, *label2_ptr; |
f5ef6aac BS |
974 | #endif |
975 | ||
976 | data_reg = *args++; | |
977 | addr_reg = *args++; | |
978 | mem_index = *args; | |
979 | ||
980 | s_bits = opc; | |
981 | ||
53c37487 BS |
982 | arg0 = TCG_REG_O0; |
983 | arg1 = TCG_REG_O1; | |
984 | arg2 = TCG_REG_O2; | |
f5ef6aac | 985 | |
f5ef6aac | 986 | #if defined(CONFIG_SOFTMMU) |
56fc64df BS |
987 | /* srl addr_reg, x, arg1 */ |
988 | tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS, | |
f5ef6aac | 989 | SHIFT_SRL); |
53c37487 | 990 | |
56fc64df BS |
991 | /* and addr_reg, x, arg0 */ |
992 | tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1), | |
f5ef6aac BS |
993 | ARITH_AND); |
994 | ||
56fc64df BS |
995 | /* and arg1, x, arg1 */ |
996 | tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS); | |
f5ef6aac | 997 | |
56fc64df | 998 | /* add arg1, x, arg1 */ |
9349b4f9 | 999 | tcg_out_addi(s, arg1, offsetof(CPUArchState, |
56fc64df | 1000 | tlb_table[mem_index][0].addr_write)); |
f5ef6aac | 1001 | |
56fc64df BS |
1002 | /* add env, arg1, arg1 */ |
1003 | tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD); | |
f5ef6aac | 1004 | |
56fc64df | 1005 | /* ld [arg1], arg2 */ |
bffe1431 | 1006 | tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) | |
56fc64df | 1007 | INSN_RS2(TCG_REG_G0)); |
53c37487 | 1008 | |
56fc64df BS |
1009 | /* subcc arg0, arg2, %g0 */ |
1010 | tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC); | |
f5ef6aac BS |
1011 | |
1012 | /* will become: | |
1da92db2 BS |
1013 | be label1 |
1014 | or | |
1015 | be,pt %xcc label1 */ | |
53c37487 | 1016 | label1_ptr = (uint32_t *)s->code_ptr; |
f5ef6aac | 1017 | tcg_out32(s, 0); |
f5ef6aac | 1018 | |
53c37487 | 1019 | /* mov (delay slot) */ |
3b6dac34 | 1020 | tcg_out_mov(s, TCG_TYPE_PTR, arg0, addr_reg); |
53c37487 | 1021 | |
53c37487 | 1022 | /* mov */ |
3b6dac34 | 1023 | tcg_out_mov(s, TCG_TYPE_REG, arg1, data_reg); |
53c37487 | 1024 | |
bffe1431 BS |
1025 | /* mov */ |
1026 | tcg_out_movi(s, TCG_TYPE_I32, arg2, mem_index); | |
1027 | ||
5bd33de6 BS |
1028 | /* XXX/FIXME: suboptimal */ |
1029 | tcg_out_mov(s, TCG_TYPE_I32, tcg_target_call_iarg_regs[3], | |
1030 | tcg_target_call_iarg_regs[2]); | |
1031 | tcg_out_mov(s, TCG_TYPE_I64, tcg_target_call_iarg_regs[2], | |
1032 | tcg_target_call_iarg_regs[1]); | |
1033 | tcg_out_mov(s, TCG_TYPE_TL, tcg_target_call_iarg_regs[1], | |
1034 | tcg_target_call_iarg_regs[0]); | |
1035 | tcg_out_mov(s, TCG_TYPE_PTR, tcg_target_call_iarg_regs[0], | |
1036 | TCG_AREG0); | |
53c37487 BS |
1037 | /* XXX: move that code at the end of the TB */ |
1038 | /* qemu_st_helper[s_bits](arg0, arg1, arg2) */ | |
f5ef6aac BS |
1039 | tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_st_helpers[s_bits] |
1040 | - (tcg_target_ulong)s->code_ptr) >> 2) | |
1041 | & 0x3fffffff)); | |
bffe1431 BS |
1042 | /* Store AREG0 in stack to avoid ugly glibc bugs that mangle |
1043 | global registers */ | |
1044 | // delay slot | |
1045 | tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, | |
f843e528 BS |
1046 | TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE - |
1047 | sizeof(long), HOST_ST_OP); | |
bffe1431 | 1048 | tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, |
f843e528 BS |
1049 | TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE - |
1050 | sizeof(long), HOST_LD_OP); | |
f5ef6aac BS |
1051 | |
1052 | /* will become: | |
1053 | ba label2 */ | |
53c37487 | 1054 | label2_ptr = (uint32_t *)s->code_ptr; |
f5ef6aac BS |
1055 | tcg_out32(s, 0); |
1056 | ||
53c37487 BS |
1057 | /* nop (delay slot) */ |
1058 | tcg_out_nop(s); | |
1059 | ||
1da92db2 BS |
1060 | #if TARGET_LONG_BITS == 32 |
1061 | /* be label1 */ | |
53c37487 BS |
1062 | *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) | |
1063 | INSN_OFF22((unsigned long)s->code_ptr - | |
1064 | (unsigned long)label1_ptr)); | |
1da92db2 BS |
1065 | #else |
1066 | /* be,pt %xcc label1 */ | |
1067 | *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x1) | | |
1068 | (0x5 << 19) | INSN_OFF19((unsigned long)s->code_ptr - | |
1069 | (unsigned long)label1_ptr)); | |
1070 | #endif | |
f5ef6aac | 1071 | |
56fc64df BS |
1072 | /* ld [arg1 + x], arg1 */ |
1073 | tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) - | |
9d0efc88 | 1074 | offsetof(CPUTLBEntry, addr_write), TARGET_ADDEND_LD_OP); |
53c37487 | 1075 | |
90cbed46 BS |
1076 | #if TARGET_LONG_BITS == 32 |
1077 | /* and addr_reg, x, arg0 */ | |
1078 | tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, 0xffffffff); | |
1079 | tcg_out_arith(s, arg0, addr_reg, TCG_REG_I5, ARITH_AND); | |
1080 | /* add arg0, arg1, arg0 */ | |
1081 | tcg_out_arith(s, arg0, arg0, arg1, ARITH_ADD); | |
1082 | #else | |
56fc64df BS |
1083 | /* add addr_reg, arg1, arg0 */ |
1084 | tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD); | |
90cbed46 BS |
1085 | #endif |
1086 | ||
f5ef6aac | 1087 | #else |
56fc64df | 1088 | arg0 = addr_reg; |
f5ef6aac BS |
1089 | #endif |
1090 | ||
f5ef6aac BS |
1091 | switch(opc) { |
1092 | case 0: | |
56fc64df BS |
1093 | /* stb data_reg, [arg0] */ |
1094 | tcg_out_ldst(s, data_reg, arg0, 0, STB); | |
f5ef6aac BS |
1095 | break; |
1096 | case 1: | |
8384dd67 | 1097 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
1098 | /* sth data_reg, [arg0] */ |
1099 | tcg_out_ldst(s, data_reg, arg0, 0, STH); | |
8384dd67 | 1100 | #else |
56fc64df BS |
1101 | /* stha data_reg, [arg0] ASI_PRIMARY_LITTLE */ |
1102 | tcg_out_ldst_asi(s, data_reg, arg0, 0, STHA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 1103 | #endif |
f5ef6aac BS |
1104 | break; |
1105 | case 2: | |
8384dd67 | 1106 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
1107 | /* stw data_reg, [arg0] */ |
1108 | tcg_out_ldst(s, data_reg, arg0, 0, STW); | |
8384dd67 | 1109 | #else |
56fc64df BS |
1110 | /* stwa data_reg, [arg0] ASI_PRIMARY_LITTLE */ |
1111 | tcg_out_ldst_asi(s, data_reg, arg0, 0, STWA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 1112 | #endif |
f5ef6aac BS |
1113 | break; |
1114 | case 3: | |
8384dd67 | 1115 | #ifdef TARGET_WORDS_BIGENDIAN |
56fc64df BS |
1116 | /* stx data_reg, [arg0] */ |
1117 | tcg_out_ldst(s, data_reg, arg0, 0, STX); | |
8384dd67 | 1118 | #else |
56fc64df BS |
1119 | /* stxa data_reg, [arg0] ASI_PRIMARY_LITTLE */ |
1120 | tcg_out_ldst_asi(s, data_reg, arg0, 0, STXA, ASI_PRIMARY_LITTLE); | |
8384dd67 | 1121 | #endif |
f5ef6aac BS |
1122 | break; |
1123 | default: | |
1124 | tcg_abort(); | |
1125 | } | |
1126 | ||
1127 | #if defined(CONFIG_SOFTMMU) | |
1128 | /* label2: */ | |
9a7f3228 | 1129 | *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) | |
53c37487 BS |
1130 | INSN_OFF22((unsigned long)s->code_ptr - |
1131 | (unsigned long)label2_ptr)); | |
f5ef6aac BS |
1132 | #endif |
1133 | } | |
1134 | ||
a9751609 | 1135 | static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, |
8289b279 BS |
1136 | const int *const_args) |
1137 | { | |
1138 | int c; | |
1139 | ||
1140 | switch (opc) { | |
1141 | case INDEX_op_exit_tb: | |
b3db8758 BS |
1142 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, args[0]); |
1143 | tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I7) | | |
8289b279 | 1144 | INSN_IMM13(8)); |
b3db8758 BS |
1145 | tcg_out32(s, RESTORE | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_G0) | |
1146 | INSN_RS2(TCG_REG_G0)); | |
8289b279 BS |
1147 | break; |
1148 | case INDEX_op_goto_tb: | |
1149 | if (s->tb_jmp_offset) { | |
1150 | /* direct jump method */ | |
26cc915c | 1151 | tcg_out_sethi(s, TCG_REG_I5, args[0] & 0xffffe000); |
cf7c2ca5 BS |
1152 | tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) | |
1153 | INSN_IMM13((args[0] & 0x1fff))); | |
8289b279 | 1154 | s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf; |
8289b279 BS |
1155 | } else { |
1156 | /* indirect jump method */ | |
b3db8758 BS |
1157 | tcg_out_ld_ptr(s, TCG_REG_I5, (tcg_target_long)(s->tb_next + args[0])); |
1158 | tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) | | |
1159 | INSN_RS2(TCG_REG_G0)); | |
8289b279 | 1160 | } |
53cd9273 | 1161 | tcg_out_nop(s); |
8289b279 BS |
1162 | s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf; |
1163 | break; | |
1164 | case INDEX_op_call: | |
bffe1431 BS |
1165 | if (const_args[0]) |
1166 | tcg_out32(s, CALL | ((((tcg_target_ulong)args[0] | |
1167 | - (tcg_target_ulong)s->code_ptr) >> 2) | |
1168 | & 0x3fffffff)); | |
1169 | else { | |
1170 | tcg_out_ld_ptr(s, TCG_REG_I5, | |
1171 | (tcg_target_long)(s->tb_next + args[0])); | |
1172 | tcg_out32(s, JMPL | INSN_RD(TCG_REG_O7) | INSN_RS1(TCG_REG_I5) | | |
1173 | INSN_RS2(TCG_REG_G0)); | |
8289b279 | 1174 | } |
bffe1431 BS |
1175 | /* Store AREG0 in stack to avoid ugly glibc bugs that mangle |
1176 | global registers */ | |
1177 | // delay slot | |
1178 | tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, | |
f843e528 BS |
1179 | TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE - |
1180 | sizeof(long), HOST_ST_OP); | |
bffe1431 | 1181 | tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, |
f843e528 BS |
1182 | TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE - |
1183 | sizeof(long), HOST_LD_OP); | |
8289b279 BS |
1184 | break; |
1185 | case INDEX_op_jmp: | |
8289b279 | 1186 | case INDEX_op_br: |
1da92db2 | 1187 | tcg_out_branch_i32(s, COND_A, args[0]); |
f5ef6aac | 1188 | tcg_out_nop(s); |
8289b279 BS |
1189 | break; |
1190 | case INDEX_op_movi_i32: | |
1191 | tcg_out_movi(s, TCG_TYPE_I32, args[0], (uint32_t)args[1]); | |
1192 | break; | |
1193 | ||
a212ea75 | 1194 | #if TCG_TARGET_REG_BITS == 64 |
8289b279 | 1195 | #define OP_32_64(x) \ |
ba225198 RH |
1196 | glue(glue(case INDEX_op_, x), _i32): \ |
1197 | glue(glue(case INDEX_op_, x), _i64) | |
8289b279 BS |
1198 | #else |
1199 | #define OP_32_64(x) \ | |
ba225198 | 1200 | glue(glue(case INDEX_op_, x), _i32) |
8289b279 | 1201 | #endif |
ba225198 | 1202 | OP_32_64(ld8u): |
8289b279 BS |
1203 | tcg_out_ldst(s, args[0], args[1], args[2], LDUB); |
1204 | break; | |
ba225198 | 1205 | OP_32_64(ld8s): |
8289b279 BS |
1206 | tcg_out_ldst(s, args[0], args[1], args[2], LDSB); |
1207 | break; | |
ba225198 | 1208 | OP_32_64(ld16u): |
8289b279 BS |
1209 | tcg_out_ldst(s, args[0], args[1], args[2], LDUH); |
1210 | break; | |
ba225198 | 1211 | OP_32_64(ld16s): |
8289b279 BS |
1212 | tcg_out_ldst(s, args[0], args[1], args[2], LDSH); |
1213 | break; | |
1214 | case INDEX_op_ld_i32: | |
a212ea75 | 1215 | #if TCG_TARGET_REG_BITS == 64 |
53cd9273 | 1216 | case INDEX_op_ld32u_i64: |
8289b279 BS |
1217 | #endif |
1218 | tcg_out_ldst(s, args[0], args[1], args[2], LDUW); | |
1219 | break; | |
ba225198 | 1220 | OP_32_64(st8): |
8289b279 BS |
1221 | tcg_out_ldst(s, args[0], args[1], args[2], STB); |
1222 | break; | |
ba225198 | 1223 | OP_32_64(st16): |
8289b279 BS |
1224 | tcg_out_ldst(s, args[0], args[1], args[2], STH); |
1225 | break; | |
1226 | case INDEX_op_st_i32: | |
a212ea75 | 1227 | #if TCG_TARGET_REG_BITS == 64 |
53cd9273 | 1228 | case INDEX_op_st32_i64: |
8289b279 BS |
1229 | #endif |
1230 | tcg_out_ldst(s, args[0], args[1], args[2], STW); | |
1231 | break; | |
ba225198 | 1232 | OP_32_64(add): |
53cd9273 | 1233 | c = ARITH_ADD; |
ba225198 RH |
1234 | goto gen_arith; |
1235 | OP_32_64(sub): | |
8289b279 | 1236 | c = ARITH_SUB; |
ba225198 RH |
1237 | goto gen_arith; |
1238 | OP_32_64(and): | |
8289b279 | 1239 | c = ARITH_AND; |
ba225198 | 1240 | goto gen_arith; |
dc69960d RH |
1241 | OP_32_64(andc): |
1242 | c = ARITH_ANDN; | |
1243 | goto gen_arith; | |
ba225198 | 1244 | OP_32_64(or): |
8289b279 | 1245 | c = ARITH_OR; |
ba225198 | 1246 | goto gen_arith; |
18c8f7a3 RH |
1247 | OP_32_64(orc): |
1248 | c = ARITH_ORN; | |
1249 | goto gen_arith; | |
ba225198 | 1250 | OP_32_64(xor): |
8289b279 | 1251 | c = ARITH_XOR; |
ba225198 | 1252 | goto gen_arith; |
8289b279 BS |
1253 | case INDEX_op_shl_i32: |
1254 | c = SHIFT_SLL; | |
ba225198 | 1255 | goto gen_arith; |
8289b279 BS |
1256 | case INDEX_op_shr_i32: |
1257 | c = SHIFT_SRL; | |
ba225198 | 1258 | goto gen_arith; |
8289b279 BS |
1259 | case INDEX_op_sar_i32: |
1260 | c = SHIFT_SRA; | |
ba225198 | 1261 | goto gen_arith; |
8289b279 BS |
1262 | case INDEX_op_mul_i32: |
1263 | c = ARITH_UMUL; | |
ba225198 | 1264 | goto gen_arith; |
583d1215 | 1265 | |
4b5a85c1 RH |
1266 | OP_32_64(neg): |
1267 | c = ARITH_SUB; | |
1268 | goto gen_arith1; | |
be6551b1 RH |
1269 | OP_32_64(not): |
1270 | c = ARITH_ORN; | |
1271 | goto gen_arith1; | |
4b5a85c1 | 1272 | |
583d1215 RH |
1273 | case INDEX_op_div_i32: |
1274 | tcg_out_div32(s, args[0], args[1], args[2], const_args[2], 0); | |
1275 | break; | |
1276 | case INDEX_op_divu_i32: | |
1277 | tcg_out_div32(s, args[0], args[1], args[2], const_args[2], 1); | |
1278 | break; | |
1279 | ||
1280 | case INDEX_op_rem_i32: | |
1281 | case INDEX_op_remu_i32: | |
1282 | tcg_out_div32(s, TCG_REG_I5, args[1], args[2], const_args[2], | |
1283 | opc == INDEX_op_remu_i32); | |
1284 | tcg_out_arithc(s, TCG_REG_I5, TCG_REG_I5, args[2], const_args[2], | |
1285 | ARITH_UMUL); | |
1286 | tcg_out_arith(s, args[0], args[1], TCG_REG_I5, ARITH_SUB); | |
1287 | break; | |
8289b279 BS |
1288 | |
1289 | case INDEX_op_brcond_i32: | |
1da92db2 BS |
1290 | tcg_out_brcond_i32(s, args[2], args[0], args[1], const_args[1], |
1291 | args[3]); | |
8289b279 | 1292 | break; |
dbfe80e1 RH |
1293 | case INDEX_op_setcond_i32: |
1294 | tcg_out_setcond_i32(s, args[3], args[0], args[1], | |
1295 | args[2], const_args[2]); | |
1296 | break; | |
1297 | ||
56f4927e RH |
1298 | #if TCG_TARGET_REG_BITS == 32 |
1299 | case INDEX_op_brcond2_i32: | |
1300 | tcg_out_brcond2_i32(s, args[4], args[0], args[1], | |
1301 | args[2], const_args[2], | |
1302 | args[3], const_args[3], args[5]); | |
1303 | break; | |
dbfe80e1 RH |
1304 | case INDEX_op_setcond2_i32: |
1305 | tcg_out_setcond2_i32(s, args[5], args[0], args[1], args[2], | |
1306 | args[3], const_args[3], | |
1307 | args[4], const_args[4]); | |
1308 | break; | |
7a3766f3 RH |
1309 | case INDEX_op_add2_i32: |
1310 | tcg_out_arithc(s, args[0], args[2], args[4], const_args[4], | |
1311 | ARITH_ADDCC); | |
1312 | tcg_out_arithc(s, args[1], args[3], args[5], const_args[5], | |
1313 | ARITH_ADDX); | |
1314 | break; | |
1315 | case INDEX_op_sub2_i32: | |
1316 | tcg_out_arithc(s, args[0], args[2], args[4], const_args[4], | |
1317 | ARITH_SUBCC); | |
1318 | tcg_out_arithc(s, args[1], args[3], args[5], const_args[5], | |
1319 | ARITH_SUBX); | |
1320 | break; | |
1321 | case INDEX_op_mulu2_i32: | |
1322 | tcg_out_arithc(s, args[0], args[2], args[3], const_args[3], | |
1323 | ARITH_UMUL); | |
1324 | tcg_out_rdy(s, args[1]); | |
1325 | break; | |
56f4927e | 1326 | #endif |
8289b279 BS |
1327 | |
1328 | case INDEX_op_qemu_ld8u: | |
f5ef6aac | 1329 | tcg_out_qemu_ld(s, args, 0); |
8289b279 BS |
1330 | break; |
1331 | case INDEX_op_qemu_ld8s: | |
f5ef6aac | 1332 | tcg_out_qemu_ld(s, args, 0 | 4); |
8289b279 BS |
1333 | break; |
1334 | case INDEX_op_qemu_ld16u: | |
f5ef6aac | 1335 | tcg_out_qemu_ld(s, args, 1); |
8289b279 BS |
1336 | break; |
1337 | case INDEX_op_qemu_ld16s: | |
f5ef6aac | 1338 | tcg_out_qemu_ld(s, args, 1 | 4); |
8289b279 | 1339 | break; |
86feb1c8 RH |
1340 | case INDEX_op_qemu_ld32: |
1341 | #if TCG_TARGET_REG_BITS == 64 | |
8289b279 | 1342 | case INDEX_op_qemu_ld32u: |
86feb1c8 | 1343 | #endif |
f5ef6aac | 1344 | tcg_out_qemu_ld(s, args, 2); |
8289b279 | 1345 | break; |
30c0c76c | 1346 | #if TCG_TARGET_REG_BITS == 64 |
8289b279 | 1347 | case INDEX_op_qemu_ld32s: |
f5ef6aac | 1348 | tcg_out_qemu_ld(s, args, 2 | 4); |
8289b279 | 1349 | break; |
30c0c76c | 1350 | #endif |
8289b279 | 1351 | case INDEX_op_qemu_st8: |
f5ef6aac | 1352 | tcg_out_qemu_st(s, args, 0); |
8289b279 BS |
1353 | break; |
1354 | case INDEX_op_qemu_st16: | |
f5ef6aac | 1355 | tcg_out_qemu_st(s, args, 1); |
8289b279 BS |
1356 | break; |
1357 | case INDEX_op_qemu_st32: | |
f5ef6aac | 1358 | tcg_out_qemu_st(s, args, 2); |
8289b279 BS |
1359 | break; |
1360 | ||
a212ea75 | 1361 | #if TCG_TARGET_REG_BITS == 64 |
8289b279 BS |
1362 | case INDEX_op_movi_i64: |
1363 | tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]); | |
1364 | break; | |
53cd9273 BS |
1365 | case INDEX_op_ld32s_i64: |
1366 | tcg_out_ldst(s, args[0], args[1], args[2], LDSW); | |
1367 | break; | |
8289b279 BS |
1368 | case INDEX_op_ld_i64: |
1369 | tcg_out_ldst(s, args[0], args[1], args[2], LDX); | |
1370 | break; | |
1371 | case INDEX_op_st_i64: | |
1372 | tcg_out_ldst(s, args[0], args[1], args[2], STX); | |
1373 | break; | |
1374 | case INDEX_op_shl_i64: | |
1375 | c = SHIFT_SLLX; | |
ba225198 | 1376 | goto gen_arith; |
8289b279 BS |
1377 | case INDEX_op_shr_i64: |
1378 | c = SHIFT_SRLX; | |
ba225198 | 1379 | goto gen_arith; |
8289b279 BS |
1380 | case INDEX_op_sar_i64: |
1381 | c = SHIFT_SRAX; | |
ba225198 | 1382 | goto gen_arith; |
8289b279 BS |
1383 | case INDEX_op_mul_i64: |
1384 | c = ARITH_MULX; | |
ba225198 | 1385 | goto gen_arith; |
583d1215 | 1386 | case INDEX_op_div_i64: |
53cd9273 | 1387 | c = ARITH_SDIVX; |
ba225198 | 1388 | goto gen_arith; |
583d1215 | 1389 | case INDEX_op_divu_i64: |
8289b279 | 1390 | c = ARITH_UDIVX; |
ba225198 | 1391 | goto gen_arith; |
583d1215 RH |
1392 | case INDEX_op_rem_i64: |
1393 | case INDEX_op_remu_i64: | |
1394 | tcg_out_arithc(s, TCG_REG_I5, args[1], args[2], const_args[2], | |
1395 | opc == INDEX_op_rem_i64 ? ARITH_SDIVX : ARITH_UDIVX); | |
1396 | tcg_out_arithc(s, TCG_REG_I5, TCG_REG_I5, args[2], const_args[2], | |
1397 | ARITH_MULX); | |
1398 | tcg_out_arith(s, args[0], args[1], TCG_REG_I5, ARITH_SUB); | |
1399 | break; | |
cc6dfecf RH |
1400 | case INDEX_op_ext32s_i64: |
1401 | if (const_args[1]) { | |
1402 | tcg_out_movi(s, TCG_TYPE_I64, args[0], (int32_t)args[1]); | |
1403 | } else { | |
1404 | tcg_out_arithi(s, args[0], args[1], 0, SHIFT_SRA); | |
1405 | } | |
1406 | break; | |
1407 | case INDEX_op_ext32u_i64: | |
1408 | if (const_args[1]) { | |
1409 | tcg_out_movi_imm32(s, args[0], args[1]); | |
1410 | } else { | |
1411 | tcg_out_arithi(s, args[0], args[1], 0, SHIFT_SRL); | |
1412 | } | |
1413 | break; | |
8289b279 BS |
1414 | |
1415 | case INDEX_op_brcond_i64: | |
1da92db2 BS |
1416 | tcg_out_brcond_i64(s, args[2], args[0], args[1], const_args[1], |
1417 | args[3]); | |
8289b279 | 1418 | break; |
dbfe80e1 RH |
1419 | case INDEX_op_setcond_i64: |
1420 | tcg_out_setcond_i64(s, args[3], args[0], args[1], | |
1421 | args[2], const_args[2]); | |
1422 | break; | |
1423 | ||
8289b279 | 1424 | case INDEX_op_qemu_ld64: |
f5ef6aac | 1425 | tcg_out_qemu_ld(s, args, 3); |
8289b279 BS |
1426 | break; |
1427 | case INDEX_op_qemu_st64: | |
f5ef6aac | 1428 | tcg_out_qemu_st(s, args, 3); |
8289b279 BS |
1429 | break; |
1430 | ||
1431 | #endif | |
ba225198 RH |
1432 | gen_arith: |
1433 | tcg_out_arithc(s, args[0], args[1], args[2], const_args[2], c); | |
53cd9273 BS |
1434 | break; |
1435 | ||
4b5a85c1 RH |
1436 | gen_arith1: |
1437 | tcg_out_arithc(s, args[0], TCG_REG_G0, args[1], const_args[1], c); | |
1438 | break; | |
1439 | ||
8289b279 BS |
1440 | default: |
1441 | fprintf(stderr, "unknown opcode 0x%x\n", opc); | |
1442 | tcg_abort(); | |
1443 | } | |
1444 | } | |
1445 | ||
1446 | static const TCGTargetOpDef sparc_op_defs[] = { | |
1447 | { INDEX_op_exit_tb, { } }, | |
b3db8758 | 1448 | { INDEX_op_goto_tb, { } }, |
8289b279 BS |
1449 | { INDEX_op_call, { "ri" } }, |
1450 | { INDEX_op_jmp, { "ri" } }, | |
1451 | { INDEX_op_br, { } }, | |
1452 | ||
1453 | { INDEX_op_mov_i32, { "r", "r" } }, | |
1454 | { INDEX_op_movi_i32, { "r" } }, | |
1455 | { INDEX_op_ld8u_i32, { "r", "r" } }, | |
1456 | { INDEX_op_ld8s_i32, { "r", "r" } }, | |
1457 | { INDEX_op_ld16u_i32, { "r", "r" } }, | |
1458 | { INDEX_op_ld16s_i32, { "r", "r" } }, | |
1459 | { INDEX_op_ld_i32, { "r", "r" } }, | |
1460 | { INDEX_op_st8_i32, { "r", "r" } }, | |
1461 | { INDEX_op_st16_i32, { "r", "r" } }, | |
1462 | { INDEX_op_st_i32, { "r", "r" } }, | |
1463 | ||
53cd9273 BS |
1464 | { INDEX_op_add_i32, { "r", "r", "rJ" } }, |
1465 | { INDEX_op_mul_i32, { "r", "r", "rJ" } }, | |
583d1215 RH |
1466 | { INDEX_op_div_i32, { "r", "r", "rJ" } }, |
1467 | { INDEX_op_divu_i32, { "r", "r", "rJ" } }, | |
1468 | { INDEX_op_rem_i32, { "r", "r", "rJ" } }, | |
1469 | { INDEX_op_remu_i32, { "r", "r", "rJ" } }, | |
53cd9273 BS |
1470 | { INDEX_op_sub_i32, { "r", "r", "rJ" } }, |
1471 | { INDEX_op_and_i32, { "r", "r", "rJ" } }, | |
dc69960d | 1472 | { INDEX_op_andc_i32, { "r", "r", "rJ" } }, |
53cd9273 | 1473 | { INDEX_op_or_i32, { "r", "r", "rJ" } }, |
18c8f7a3 | 1474 | { INDEX_op_orc_i32, { "r", "r", "rJ" } }, |
53cd9273 | 1475 | { INDEX_op_xor_i32, { "r", "r", "rJ" } }, |
8289b279 | 1476 | |
53cd9273 BS |
1477 | { INDEX_op_shl_i32, { "r", "r", "rJ" } }, |
1478 | { INDEX_op_shr_i32, { "r", "r", "rJ" } }, | |
1479 | { INDEX_op_sar_i32, { "r", "r", "rJ" } }, | |
8289b279 | 1480 | |
4b5a85c1 | 1481 | { INDEX_op_neg_i32, { "r", "rJ" } }, |
be6551b1 | 1482 | { INDEX_op_not_i32, { "r", "rJ" } }, |
4b5a85c1 | 1483 | |
56f4927e | 1484 | { INDEX_op_brcond_i32, { "r", "rJ" } }, |
dbfe80e1 RH |
1485 | { INDEX_op_setcond_i32, { "r", "r", "rJ" } }, |
1486 | ||
56f4927e RH |
1487 | #if TCG_TARGET_REG_BITS == 32 |
1488 | { INDEX_op_brcond2_i32, { "r", "r", "rJ", "rJ" } }, | |
dbfe80e1 | 1489 | { INDEX_op_setcond2_i32, { "r", "r", "r", "rJ", "rJ" } }, |
7a3766f3 RH |
1490 | { INDEX_op_add2_i32, { "r", "r", "r", "r", "rJ", "rJ" } }, |
1491 | { INDEX_op_sub2_i32, { "r", "r", "r", "r", "rJ", "rJ" } }, | |
1492 | { INDEX_op_mulu2_i32, { "r", "r", "r", "rJ" } }, | |
56f4927e | 1493 | #endif |
8289b279 BS |
1494 | |
1495 | { INDEX_op_qemu_ld8u, { "r", "L" } }, | |
1496 | { INDEX_op_qemu_ld8s, { "r", "L" } }, | |
1497 | { INDEX_op_qemu_ld16u, { "r", "L" } }, | |
1498 | { INDEX_op_qemu_ld16s, { "r", "L" } }, | |
86feb1c8 | 1499 | { INDEX_op_qemu_ld32, { "r", "L" } }, |
30c0c76c | 1500 | #if TCG_TARGET_REG_BITS == 64 |
86feb1c8 | 1501 | { INDEX_op_qemu_ld32u, { "r", "L" } }, |
8289b279 | 1502 | { INDEX_op_qemu_ld32s, { "r", "L" } }, |
30c0c76c | 1503 | #endif |
8289b279 BS |
1504 | |
1505 | { INDEX_op_qemu_st8, { "L", "L" } }, | |
1506 | { INDEX_op_qemu_st16, { "L", "L" } }, | |
1507 | { INDEX_op_qemu_st32, { "L", "L" } }, | |
1508 | ||
a212ea75 | 1509 | #if TCG_TARGET_REG_BITS == 64 |
8289b279 BS |
1510 | { INDEX_op_mov_i64, { "r", "r" } }, |
1511 | { INDEX_op_movi_i64, { "r" } }, | |
1512 | { INDEX_op_ld8u_i64, { "r", "r" } }, | |
1513 | { INDEX_op_ld8s_i64, { "r", "r" } }, | |
1514 | { INDEX_op_ld16u_i64, { "r", "r" } }, | |
1515 | { INDEX_op_ld16s_i64, { "r", "r" } }, | |
1516 | { INDEX_op_ld32u_i64, { "r", "r" } }, | |
1517 | { INDEX_op_ld32s_i64, { "r", "r" } }, | |
1518 | { INDEX_op_ld_i64, { "r", "r" } }, | |
1519 | { INDEX_op_st8_i64, { "r", "r" } }, | |
1520 | { INDEX_op_st16_i64, { "r", "r" } }, | |
1521 | { INDEX_op_st32_i64, { "r", "r" } }, | |
1522 | { INDEX_op_st_i64, { "r", "r" } }, | |
56fc64df BS |
1523 | { INDEX_op_qemu_ld64, { "L", "L" } }, |
1524 | { INDEX_op_qemu_st64, { "L", "L" } }, | |
8289b279 | 1525 | |
53cd9273 BS |
1526 | { INDEX_op_add_i64, { "r", "r", "rJ" } }, |
1527 | { INDEX_op_mul_i64, { "r", "r", "rJ" } }, | |
583d1215 RH |
1528 | { INDEX_op_div_i64, { "r", "r", "rJ" } }, |
1529 | { INDEX_op_divu_i64, { "r", "r", "rJ" } }, | |
1530 | { INDEX_op_rem_i64, { "r", "r", "rJ" } }, | |
1531 | { INDEX_op_remu_i64, { "r", "r", "rJ" } }, | |
53cd9273 BS |
1532 | { INDEX_op_sub_i64, { "r", "r", "rJ" } }, |
1533 | { INDEX_op_and_i64, { "r", "r", "rJ" } }, | |
dc69960d | 1534 | { INDEX_op_andc_i64, { "r", "r", "rJ" } }, |
53cd9273 | 1535 | { INDEX_op_or_i64, { "r", "r", "rJ" } }, |
18c8f7a3 | 1536 | { INDEX_op_orc_i64, { "r", "r", "rJ" } }, |
53cd9273 | 1537 | { INDEX_op_xor_i64, { "r", "r", "rJ" } }, |
8289b279 | 1538 | |
53cd9273 BS |
1539 | { INDEX_op_shl_i64, { "r", "r", "rJ" } }, |
1540 | { INDEX_op_shr_i64, { "r", "r", "rJ" } }, | |
1541 | { INDEX_op_sar_i64, { "r", "r", "rJ" } }, | |
4b5a85c1 RH |
1542 | |
1543 | { INDEX_op_neg_i64, { "r", "rJ" } }, | |
be6551b1 | 1544 | { INDEX_op_not_i64, { "r", "rJ" } }, |
4b5a85c1 | 1545 | |
cc6dfecf RH |
1546 | { INDEX_op_ext32s_i64, { "r", "ri" } }, |
1547 | { INDEX_op_ext32u_i64, { "r", "ri" } }, | |
8289b279 | 1548 | |
56f4927e | 1549 | { INDEX_op_brcond_i64, { "r", "rJ" } }, |
dbfe80e1 | 1550 | { INDEX_op_setcond_i64, { "r", "r", "rJ" } }, |
3ee60ad4 RH |
1551 | #else |
1552 | { INDEX_op_qemu_ld64, { "L", "L", "L" } }, | |
1553 | { INDEX_op_qemu_st64, { "L", "L", "L" } }, | |
8289b279 BS |
1554 | #endif |
1555 | { -1 }, | |
1556 | }; | |
1557 | ||
e4d58b41 | 1558 | static void tcg_target_init(TCGContext *s) |
8289b279 BS |
1559 | { |
1560 | tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff); | |
a212ea75 | 1561 | #if TCG_TARGET_REG_BITS == 64 |
8289b279 BS |
1562 | tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff); |
1563 | #endif | |
1564 | tcg_regset_set32(tcg_target_call_clobber_regs, 0, | |
b3db8758 BS |
1565 | (1 << TCG_REG_G1) | |
1566 | (1 << TCG_REG_G2) | | |
1567 | (1 << TCG_REG_G3) | | |
1568 | (1 << TCG_REG_G4) | | |
1569 | (1 << TCG_REG_G5) | | |
1570 | (1 << TCG_REG_G6) | | |
1571 | (1 << TCG_REG_G7) | | |
8289b279 BS |
1572 | (1 << TCG_REG_O0) | |
1573 | (1 << TCG_REG_O1) | | |
1574 | (1 << TCG_REG_O2) | | |
1575 | (1 << TCG_REG_O3) | | |
1576 | (1 << TCG_REG_O4) | | |
1577 | (1 << TCG_REG_O5) | | |
8289b279 BS |
1578 | (1 << TCG_REG_O7)); |
1579 | ||
1580 | tcg_regset_clear(s->reserved_regs); | |
1581 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_G0); | |
a212ea75 | 1582 | #if TCG_TARGET_REG_BITS == 64 |
d795eb86 BS |
1583 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_I4); // for internal use |
1584 | #endif | |
53cd9273 | 1585 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_I5); // for internal use |
8289b279 BS |
1586 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_I6); |
1587 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_I7); | |
1588 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_O6); | |
1589 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_O7); | |
1590 | tcg_add_target_add_op_defs(sparc_op_defs); | |
1591 | } | |
cb1977d3 RH |
1592 | |
1593 | #if TCG_TARGET_REG_BITS == 64 | |
1594 | # define ELF_HOST_MACHINE EM_SPARCV9 | |
9b9c37c3 | 1595 | #else |
cb1977d3 RH |
1596 | # define ELF_HOST_MACHINE EM_SPARC32PLUS |
1597 | # define ELF_HOST_FLAGS EF_SPARC_32PLUS | |
cb1977d3 RH |
1598 | #endif |
1599 | ||
1600 | typedef struct { | |
1601 | uint32_t len __attribute__((aligned((sizeof(void *))))); | |
1602 | uint32_t id; | |
1603 | uint8_t version; | |
1604 | char augmentation[1]; | |
1605 | uint8_t code_align; | |
1606 | uint8_t data_align; | |
1607 | uint8_t return_column; | |
1608 | } DebugFrameCIE; | |
1609 | ||
1610 | typedef struct { | |
1611 | uint32_t len __attribute__((aligned((sizeof(void *))))); | |
1612 | uint32_t cie_offset; | |
1613 | tcg_target_long func_start __attribute__((packed)); | |
1614 | tcg_target_long func_len __attribute__((packed)); | |
1615 | uint8_t def_cfa[TCG_TARGET_REG_BITS == 64 ? 4 : 2]; | |
1616 | uint8_t win_save; | |
1617 | uint8_t ret_save[3]; | |
1618 | } DebugFrameFDE; | |
1619 | ||
1620 | typedef struct { | |
1621 | DebugFrameCIE cie; | |
1622 | DebugFrameFDE fde; | |
1623 | } DebugFrame; | |
1624 | ||
1625 | static DebugFrame debug_frame = { | |
1626 | .cie.len = sizeof(DebugFrameCIE)-4, /* length after .len member */ | |
1627 | .cie.id = -1, | |
1628 | .cie.version = 1, | |
1629 | .cie.code_align = 1, | |
1630 | .cie.data_align = -sizeof(void *) & 0x7f, | |
1631 | .cie.return_column = 15, /* o7 */ | |
1632 | ||
1633 | .fde.len = sizeof(DebugFrameFDE)-4, /* length after .len member */ | |
1634 | .fde.def_cfa = { | |
1635 | #if TCG_TARGET_REG_BITS == 64 | |
1636 | 12, 30, /* DW_CFA_def_cfa i6, 2047 */ | |
1637 | (2047 & 0x7f) | 0x80, (2047 >> 7) | |
1638 | #else | |
1639 | 13, 30 /* DW_CFA_def_cfa_register i6 */ | |
1640 | #endif | |
1641 | }, | |
1642 | .fde.win_save = 0x2d, /* DW_CFA_GNU_window_save */ | |
1643 | .fde.ret_save = { 9, 15, 31 }, /* DW_CFA_register o7, i7 */ | |
1644 | }; | |
1645 | ||
1646 | void tcg_register_jit(void *buf, size_t buf_size) | |
1647 | { | |
1648 | debug_frame.fde.func_start = (tcg_target_long) buf; | |
1649 | debug_frame.fde.func_len = buf_size; | |
1650 | ||
1651 | tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); | |
1652 | } |