root / tcg / arm / tcg-target.c @ 26c5d372
History | View | Annotate | Download (52.8 kB)
1 | 811d4cf4 | balrog | /*
|
---|---|---|---|
2 | 811d4cf4 | balrog | * Tiny Code Generator for QEMU
|
3 | 811d4cf4 | balrog | *
|
4 | 811d4cf4 | balrog | * Copyright (c) 2008 Andrzej Zaborowski
|
5 | 811d4cf4 | balrog | *
|
6 | 811d4cf4 | balrog | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 811d4cf4 | balrog | * of this software and associated documentation files (the "Software"), to deal
|
8 | 811d4cf4 | balrog | * in the Software without restriction, including without limitation the rights
|
9 | 811d4cf4 | balrog | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 811d4cf4 | balrog | * copies of the Software, and to permit persons to whom the Software is
|
11 | 811d4cf4 | balrog | * furnished to do so, subject to the following conditions:
|
12 | 811d4cf4 | balrog | *
|
13 | 811d4cf4 | balrog | * The above copyright notice and this permission notice shall be included in
|
14 | 811d4cf4 | balrog | * all copies or substantial portions of the Software.
|
15 | 811d4cf4 | balrog | *
|
16 | 811d4cf4 | balrog | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 811d4cf4 | balrog | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 811d4cf4 | balrog | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 811d4cf4 | balrog | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 811d4cf4 | balrog | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 811d4cf4 | balrog | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 811d4cf4 | balrog | * THE SOFTWARE.
|
23 | 811d4cf4 | balrog | */
|
24 | d4a9eb1f | blueswir1 | |
25 | d4a9eb1f | blueswir1 | #ifndef NDEBUG
|
26 | d4a9eb1f | blueswir1 | static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { |
27 | 811d4cf4 | balrog | "%r0",
|
28 | 811d4cf4 | balrog | "%r1",
|
29 | 811d4cf4 | balrog | "%r2",
|
30 | 811d4cf4 | balrog | "%r3",
|
31 | 811d4cf4 | balrog | "%r4",
|
32 | 811d4cf4 | balrog | "%r5",
|
33 | 811d4cf4 | balrog | "%r6",
|
34 | 811d4cf4 | balrog | "%r7",
|
35 | 811d4cf4 | balrog | "%r8",
|
36 | 811d4cf4 | balrog | "%r9",
|
37 | 811d4cf4 | balrog | "%r10",
|
38 | 811d4cf4 | balrog | "%r11",
|
39 | 811d4cf4 | balrog | "%r12",
|
40 | 811d4cf4 | balrog | "%r13",
|
41 | 811d4cf4 | balrog | "%r14",
|
42 | 811d4cf4 | balrog | }; |
43 | d4a9eb1f | blueswir1 | #endif
|
44 | 811d4cf4 | balrog | |
45 | d4a9eb1f | blueswir1 | static const int tcg_target_reg_alloc_order[] = { |
46 | 811d4cf4 | balrog | TCG_REG_R0, |
47 | 811d4cf4 | balrog | TCG_REG_R1, |
48 | 811d4cf4 | balrog | TCG_REG_R2, |
49 | 811d4cf4 | balrog | TCG_REG_R3, |
50 | 811d4cf4 | balrog | TCG_REG_R4, |
51 | 811d4cf4 | balrog | TCG_REG_R5, |
52 | 811d4cf4 | balrog | TCG_REG_R6, |
53 | 811d4cf4 | balrog | TCG_REG_R7, |
54 | 811d4cf4 | balrog | TCG_REG_R8, |
55 | 811d4cf4 | balrog | TCG_REG_R9, |
56 | 811d4cf4 | balrog | TCG_REG_R10, |
57 | 811d4cf4 | balrog | TCG_REG_R11, |
58 | 811d4cf4 | balrog | TCG_REG_R12, |
59 | 811d4cf4 | balrog | TCG_REG_R13, |
60 | 811d4cf4 | balrog | TCG_REG_R14, |
61 | 811d4cf4 | balrog | }; |
62 | 811d4cf4 | balrog | |
63 | d4a9eb1f | blueswir1 | static const int tcg_target_call_iarg_regs[4] = { |
64 | 811d4cf4 | balrog | TCG_REG_R0, TCG_REG_R1, TCG_REG_R2, TCG_REG_R3 |
65 | 811d4cf4 | balrog | }; |
66 | d4a9eb1f | blueswir1 | static const int tcg_target_call_oarg_regs[2] = { |
67 | 811d4cf4 | balrog | TCG_REG_R0, TCG_REG_R1 |
68 | 811d4cf4 | balrog | }; |
69 | 811d4cf4 | balrog | |
70 | 650bbb36 | balrog | static void patch_reloc(uint8_t *code_ptr, int type, |
71 | 811d4cf4 | balrog | tcg_target_long value, tcg_target_long addend) |
72 | 811d4cf4 | balrog | { |
73 | 811d4cf4 | balrog | switch (type) {
|
74 | 811d4cf4 | balrog | case R_ARM_ABS32:
|
75 | 811d4cf4 | balrog | *(uint32_t *) code_ptr = value; |
76 | 811d4cf4 | balrog | break;
|
77 | 811d4cf4 | balrog | |
78 | 811d4cf4 | balrog | case R_ARM_CALL:
|
79 | 811d4cf4 | balrog | case R_ARM_JUMP24:
|
80 | 811d4cf4 | balrog | default:
|
81 | 811d4cf4 | balrog | tcg_abort(); |
82 | 811d4cf4 | balrog | |
83 | 811d4cf4 | balrog | case R_ARM_PC24:
|
84 | eae6ce52 | balrog | *(uint32_t *) code_ptr = ((*(uint32_t *) code_ptr) & 0xff000000) |
|
85 | e936243a | balrog | (((value - ((tcg_target_long) code_ptr + 8)) >> 2) & 0xffffff); |
86 | 811d4cf4 | balrog | break;
|
87 | 811d4cf4 | balrog | } |
88 | 811d4cf4 | balrog | } |
89 | 811d4cf4 | balrog | |
90 | 811d4cf4 | balrog | /* maximum number of register used for input function arguments */
|
91 | 811d4cf4 | balrog | static inline int tcg_target_get_call_iarg_regs_count(int flags) |
92 | 811d4cf4 | balrog | { |
93 | 811d4cf4 | balrog | return 4; |
94 | 811d4cf4 | balrog | } |
95 | 811d4cf4 | balrog | |
96 | 811d4cf4 | balrog | /* parse target specific constraints */
|
97 | d4a9eb1f | blueswir1 | static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) |
98 | 811d4cf4 | balrog | { |
99 | 811d4cf4 | balrog | const char *ct_str; |
100 | 811d4cf4 | balrog | |
101 | 811d4cf4 | balrog | ct_str = *pct_str; |
102 | 811d4cf4 | balrog | switch (ct_str[0]) { |
103 | cb4e581f | Laurent Desnogues | case 'I': |
104 | cb4e581f | Laurent Desnogues | ct->ct |= TCG_CT_CONST_ARM; |
105 | cb4e581f | Laurent Desnogues | break;
|
106 | cb4e581f | Laurent Desnogues | |
107 | 811d4cf4 | balrog | case 'r': |
108 | 811d4cf4 | balrog | #ifndef CONFIG_SOFTMMU
|
109 | 811d4cf4 | balrog | case 'd': |
110 | 811d4cf4 | balrog | case 'D': |
111 | 811d4cf4 | balrog | case 'x': |
112 | 811d4cf4 | balrog | case 'X': |
113 | 811d4cf4 | balrog | #endif
|
114 | 811d4cf4 | balrog | ct->ct |= TCG_CT_REG; |
115 | 811d4cf4 | balrog | tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1); |
116 | 811d4cf4 | balrog | break;
|
117 | 811d4cf4 | balrog | |
118 | 811d4cf4 | balrog | #ifdef CONFIG_SOFTMMU
|
119 | d0660ed4 | balrog | /* qemu_ld/st inputs (unless 'X', 'd' or 'D') */
|
120 | 811d4cf4 | balrog | case 'x': |
121 | 811d4cf4 | balrog | ct->ct |= TCG_CT_REG; |
122 | 811d4cf4 | balrog | tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1); |
123 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R0); |
124 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1); |
125 | 811d4cf4 | balrog | break;
|
126 | 811d4cf4 | balrog | |
127 | d0660ed4 | balrog | /* qemu_ld64 data_reg */
|
128 | d0660ed4 | balrog | case 'd': |
129 | d0660ed4 | balrog | ct->ct |= TCG_CT_REG; |
130 | d0660ed4 | balrog | tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1); |
131 | d0660ed4 | balrog | /* r1 is still needed to load data_reg2, so don't use it. */
|
132 | d0660ed4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1); |
133 | d0660ed4 | balrog | break;
|
134 | d0660ed4 | balrog | |
135 | 811d4cf4 | balrog | /* qemu_ld/st64 data_reg2 */
|
136 | 811d4cf4 | balrog | case 'D': |
137 | 811d4cf4 | balrog | ct->ct |= TCG_CT_REG; |
138 | 811d4cf4 | balrog | tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1); |
139 | 811d4cf4 | balrog | /* r0, r1 and optionally r2 will be overwritten by the address
|
140 | 811d4cf4 | balrog | * and the low word of data, so don't use these. */
|
141 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R0); |
142 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1); |
143 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
144 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R2); |
145 | 811d4cf4 | balrog | # endif
|
146 | 811d4cf4 | balrog | break;
|
147 | 811d4cf4 | balrog | |
148 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
149 | 811d4cf4 | balrog | /* qemu_ld/st addr_reg2 */
|
150 | 811d4cf4 | balrog | case 'X': |
151 | 811d4cf4 | balrog | ct->ct |= TCG_CT_REG; |
152 | 811d4cf4 | balrog | tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1); |
153 | 811d4cf4 | balrog | /* r0 will be overwritten by the low word of base, so don't use it. */
|
154 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R0); |
155 | 811d4cf4 | balrog | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1); |
156 | 811d4cf4 | balrog | break;
|
157 | 811d4cf4 | balrog | # endif
|
158 | 811d4cf4 | balrog | #endif
|
159 | 811d4cf4 | balrog | |
160 | 811d4cf4 | balrog | default:
|
161 | 811d4cf4 | balrog | return -1; |
162 | 811d4cf4 | balrog | } |
163 | 811d4cf4 | balrog | ct_str++; |
164 | 811d4cf4 | balrog | *pct_str = ct_str; |
165 | 811d4cf4 | balrog | |
166 | 811d4cf4 | balrog | return 0; |
167 | 811d4cf4 | balrog | } |
168 | 811d4cf4 | balrog | |
169 | 94953e6d | Laurent Desnogues | static inline uint32_t rotl(uint32_t val, int n) |
170 | 94953e6d | Laurent Desnogues | { |
171 | 94953e6d | Laurent Desnogues | return (val << n) | (val >> (32 - n)); |
172 | 94953e6d | Laurent Desnogues | } |
173 | 94953e6d | Laurent Desnogues | |
174 | 94953e6d | Laurent Desnogues | /* ARM immediates for ALU instructions are made of an unsigned 8-bit
|
175 | 94953e6d | Laurent Desnogues | right-rotated by an even amount between 0 and 30. */
|
176 | 94953e6d | Laurent Desnogues | static inline int encode_imm(uint32_t imm) |
177 | 94953e6d | Laurent Desnogues | { |
178 | 4e6f6d4c | Laurent Desnogues | int shift;
|
179 | 4e6f6d4c | Laurent Desnogues | |
180 | 94953e6d | Laurent Desnogues | /* simple case, only lower bits */
|
181 | 94953e6d | Laurent Desnogues | if ((imm & ~0xff) == 0) |
182 | 94953e6d | Laurent Desnogues | return 0; |
183 | 94953e6d | Laurent Desnogues | /* then try a simple even shift */
|
184 | 94953e6d | Laurent Desnogues | shift = ctz32(imm) & ~1;
|
185 | 94953e6d | Laurent Desnogues | if (((imm >> shift) & ~0xff) == 0) |
186 | 94953e6d | Laurent Desnogues | return 32 - shift; |
187 | 94953e6d | Laurent Desnogues | /* now try harder with rotations */
|
188 | 94953e6d | Laurent Desnogues | if ((rotl(imm, 2) & ~0xff) == 0) |
189 | 94953e6d | Laurent Desnogues | return 2; |
190 | 94953e6d | Laurent Desnogues | if ((rotl(imm, 4) & ~0xff) == 0) |
191 | 94953e6d | Laurent Desnogues | return 4; |
192 | 94953e6d | Laurent Desnogues | if ((rotl(imm, 6) & ~0xff) == 0) |
193 | 94953e6d | Laurent Desnogues | return 6; |
194 | 94953e6d | Laurent Desnogues | /* imm can't be encoded */
|
195 | 94953e6d | Laurent Desnogues | return -1; |
196 | 94953e6d | Laurent Desnogues | } |
197 | cb4e581f | Laurent Desnogues | |
198 | cb4e581f | Laurent Desnogues | static inline int check_fit_imm(uint32_t imm) |
199 | cb4e581f | Laurent Desnogues | { |
200 | 94953e6d | Laurent Desnogues | return encode_imm(imm) >= 0; |
201 | cb4e581f | Laurent Desnogues | } |
202 | cb4e581f | Laurent Desnogues | |
203 | 811d4cf4 | balrog | /* Test if a constant matches the constraint.
|
204 | 811d4cf4 | balrog | * TODO: define constraints for:
|
205 | 811d4cf4 | balrog | *
|
206 | 811d4cf4 | balrog | * ldr/str offset: between -0xfff and 0xfff
|
207 | 811d4cf4 | balrog | * ldrh/strh offset: between -0xff and 0xff
|
208 | 811d4cf4 | balrog | * mov operand2: values represented with x << (2 * y), x < 0x100
|
209 | 811d4cf4 | balrog | * add, sub, eor...: ditto
|
210 | 811d4cf4 | balrog | */
|
211 | 811d4cf4 | balrog | static inline int tcg_target_const_match(tcg_target_long val, |
212 | 811d4cf4 | balrog | const TCGArgConstraint *arg_ct)
|
213 | 811d4cf4 | balrog | { |
214 | 811d4cf4 | balrog | int ct;
|
215 | 811d4cf4 | balrog | ct = arg_ct->ct; |
216 | 811d4cf4 | balrog | if (ct & TCG_CT_CONST)
|
217 | 811d4cf4 | balrog | return 1; |
218 | cb4e581f | Laurent Desnogues | else if ((ct & TCG_CT_CONST_ARM) && check_fit_imm(val)) |
219 | cb4e581f | Laurent Desnogues | return 1; |
220 | 811d4cf4 | balrog | else
|
221 | 811d4cf4 | balrog | return 0; |
222 | 811d4cf4 | balrog | } |
223 | 811d4cf4 | balrog | |
224 | 811d4cf4 | balrog | enum arm_data_opc_e {
|
225 | 811d4cf4 | balrog | ARITH_AND = 0x0,
|
226 | 811d4cf4 | balrog | ARITH_EOR = 0x1,
|
227 | 811d4cf4 | balrog | ARITH_SUB = 0x2,
|
228 | 811d4cf4 | balrog | ARITH_RSB = 0x3,
|
229 | 811d4cf4 | balrog | ARITH_ADD = 0x4,
|
230 | 811d4cf4 | balrog | ARITH_ADC = 0x5,
|
231 | 811d4cf4 | balrog | ARITH_SBC = 0x6,
|
232 | 811d4cf4 | balrog | ARITH_RSC = 0x7,
|
233 | 3979144c | pbrook | ARITH_TST = 0x8,
|
234 | 811d4cf4 | balrog | ARITH_CMP = 0xa,
|
235 | 811d4cf4 | balrog | ARITH_CMN = 0xb,
|
236 | 811d4cf4 | balrog | ARITH_ORR = 0xc,
|
237 | 811d4cf4 | balrog | ARITH_MOV = 0xd,
|
238 | 811d4cf4 | balrog | ARITH_BIC = 0xe,
|
239 | 811d4cf4 | balrog | ARITH_MVN = 0xf,
|
240 | 811d4cf4 | balrog | }; |
241 | 811d4cf4 | balrog | |
242 | 3979144c | pbrook | #define TO_CPSR(opc) \
|
243 | 3979144c | pbrook | ((opc == ARITH_CMP || opc == ARITH_CMN || opc == ARITH_TST) << 20)
|
244 | 811d4cf4 | balrog | |
245 | 811d4cf4 | balrog | #define SHIFT_IMM_LSL(im) (((im) << 7) | 0x00) |
246 | 811d4cf4 | balrog | #define SHIFT_IMM_LSR(im) (((im) << 7) | 0x20) |
247 | 811d4cf4 | balrog | #define SHIFT_IMM_ASR(im) (((im) << 7) | 0x40) |
248 | 811d4cf4 | balrog | #define SHIFT_IMM_ROR(im) (((im) << 7) | 0x60) |
249 | 811d4cf4 | balrog | #define SHIFT_REG_LSL(rs) (((rs) << 8) | 0x10) |
250 | 811d4cf4 | balrog | #define SHIFT_REG_LSR(rs) (((rs) << 8) | 0x30) |
251 | 811d4cf4 | balrog | #define SHIFT_REG_ASR(rs) (((rs) << 8) | 0x50) |
252 | 811d4cf4 | balrog | #define SHIFT_REG_ROR(rs) (((rs) << 8) | 0x70) |
253 | 811d4cf4 | balrog | |
254 | 811d4cf4 | balrog | enum arm_cond_code_e {
|
255 | 811d4cf4 | balrog | COND_EQ = 0x0,
|
256 | 811d4cf4 | balrog | COND_NE = 0x1,
|
257 | 811d4cf4 | balrog | COND_CS = 0x2, /* Unsigned greater or equal */ |
258 | 811d4cf4 | balrog | COND_CC = 0x3, /* Unsigned less than */ |
259 | 811d4cf4 | balrog | COND_MI = 0x4, /* Negative */ |
260 | 811d4cf4 | balrog | COND_PL = 0x5, /* Zero or greater */ |
261 | 811d4cf4 | balrog | COND_VS = 0x6, /* Overflow */ |
262 | 811d4cf4 | balrog | COND_VC = 0x7, /* No overflow */ |
263 | 811d4cf4 | balrog | COND_HI = 0x8, /* Unsigned greater than */ |
264 | 811d4cf4 | balrog | COND_LS = 0x9, /* Unsigned less or equal */ |
265 | 811d4cf4 | balrog | COND_GE = 0xa,
|
266 | 811d4cf4 | balrog | COND_LT = 0xb,
|
267 | 811d4cf4 | balrog | COND_GT = 0xc,
|
268 | 811d4cf4 | balrog | COND_LE = 0xd,
|
269 | 811d4cf4 | balrog | COND_AL = 0xe,
|
270 | 811d4cf4 | balrog | }; |
271 | 811d4cf4 | balrog | |
272 | 811d4cf4 | balrog | static const uint8_t tcg_cond_to_arm_cond[10] = { |
273 | 811d4cf4 | balrog | [TCG_COND_EQ] = COND_EQ, |
274 | 811d4cf4 | balrog | [TCG_COND_NE] = COND_NE, |
275 | 811d4cf4 | balrog | [TCG_COND_LT] = COND_LT, |
276 | 811d4cf4 | balrog | [TCG_COND_GE] = COND_GE, |
277 | 811d4cf4 | balrog | [TCG_COND_LE] = COND_LE, |
278 | 811d4cf4 | balrog | [TCG_COND_GT] = COND_GT, |
279 | 811d4cf4 | balrog | /* unsigned */
|
280 | 811d4cf4 | balrog | [TCG_COND_LTU] = COND_CC, |
281 | 811d4cf4 | balrog | [TCG_COND_GEU] = COND_CS, |
282 | 811d4cf4 | balrog | [TCG_COND_LEU] = COND_LS, |
283 | 811d4cf4 | balrog | [TCG_COND_GTU] = COND_HI, |
284 | 811d4cf4 | balrog | }; |
285 | 811d4cf4 | balrog | |
286 | 811d4cf4 | balrog | static inline void tcg_out_bx(TCGContext *s, int cond, int rn) |
287 | 811d4cf4 | balrog | { |
288 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x012fff10 | rn); |
289 | 811d4cf4 | balrog | } |
290 | 811d4cf4 | balrog | |
291 | 811d4cf4 | balrog | static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset) |
292 | 811d4cf4 | balrog | { |
293 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x0a000000 | |
294 | 811d4cf4 | balrog | (((offset - 8) >> 2) & 0x00ffffff)); |
295 | 811d4cf4 | balrog | } |
296 | 811d4cf4 | balrog | |
297 | e936243a | balrog | static inline void tcg_out_b_noaddr(TCGContext *s, int cond) |
298 | e936243a | balrog | { |
299 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
300 | e936243a | balrog | tcg_out8(s, (cond << 4) | 0x0a); |
301 | e936243a | balrog | s->code_ptr += 3;
|
302 | e936243a | balrog | #else
|
303 | e936243a | balrog | s->code_ptr += 3;
|
304 | e936243a | balrog | tcg_out8(s, (cond << 4) | 0x0a); |
305 | e936243a | balrog | #endif
|
306 | e936243a | balrog | } |
307 | e936243a | balrog | |
308 | 811d4cf4 | balrog | static inline void tcg_out_bl(TCGContext *s, int cond, int32_t offset) |
309 | 811d4cf4 | balrog | { |
310 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x0b000000 | |
311 | 811d4cf4 | balrog | (((offset - 8) >> 2) & 0x00ffffff)); |
312 | 811d4cf4 | balrog | } |
313 | 811d4cf4 | balrog | |
314 | 811d4cf4 | balrog | static inline void tcg_out_dat_reg(TCGContext *s, |
315 | 811d4cf4 | balrog | int cond, int opc, int rd, int rn, int rm, int shift) |
316 | 811d4cf4 | balrog | { |
317 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | (0 << 25) | (opc << 21) | TO_CPSR(opc) | |
318 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | shift | rm); |
319 | 811d4cf4 | balrog | } |
320 | 811d4cf4 | balrog | |
321 | 811d4cf4 | balrog | static inline void tcg_out_dat_reg2(TCGContext *s, |
322 | 811d4cf4 | balrog | int cond, int opc0, int opc1, int rd0, int rd1, |
323 | 811d4cf4 | balrog | int rn0, int rn1, int rm0, int rm1, int shift) |
324 | 811d4cf4 | balrog | { |
325 | 0c9c3a9e | balrog | if (rd0 == rn1 || rd0 == rm1) {
|
326 | 0c9c3a9e | balrog | tcg_out32(s, (cond << 28) | (0 << 25) | (opc0 << 21) | (1 << 20) | |
327 | 0c9c3a9e | balrog | (rn0 << 16) | (8 << 12) | shift | rm0); |
328 | 0c9c3a9e | balrog | tcg_out32(s, (cond << 28) | (0 << 25) | (opc1 << 21) | |
329 | 0c9c3a9e | balrog | (rn1 << 16) | (rd1 << 12) | shift | rm1); |
330 | 0c9c3a9e | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
331 | 0c9c3a9e | balrog | rd0, 0, TCG_REG_R8, SHIFT_IMM_LSL(0)); |
332 | 0c9c3a9e | balrog | } else {
|
333 | 0c9c3a9e | balrog | tcg_out32(s, (cond << 28) | (0 << 25) | (opc0 << 21) | (1 << 20) | |
334 | 0c9c3a9e | balrog | (rn0 << 16) | (rd0 << 12) | shift | rm0); |
335 | 0c9c3a9e | balrog | tcg_out32(s, (cond << 28) | (0 << 25) | (opc1 << 21) | |
336 | 0c9c3a9e | balrog | (rn1 << 16) | (rd1 << 12) | shift | rm1); |
337 | 0c9c3a9e | balrog | } |
338 | 811d4cf4 | balrog | } |
339 | 811d4cf4 | balrog | |
340 | 811d4cf4 | balrog | static inline void tcg_out_dat_imm(TCGContext *s, |
341 | 811d4cf4 | balrog | int cond, int opc, int rd, int rn, int im) |
342 | 811d4cf4 | balrog | { |
343 | 3979144c | pbrook | tcg_out32(s, (cond << 28) | (1 << 25) | (opc << 21) | TO_CPSR(opc) | |
344 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | im); |
345 | 811d4cf4 | balrog | } |
346 | 811d4cf4 | balrog | |
347 | 811d4cf4 | balrog | static inline void tcg_out_movi32(TCGContext *s, |
348 | 811d4cf4 | balrog | int cond, int rd, int32_t arg) |
349 | 811d4cf4 | balrog | { |
350 | 811d4cf4 | balrog | int offset = (uint32_t) arg - ((uint32_t) s->code_ptr + 8); |
351 | 811d4cf4 | balrog | |
352 | 811d4cf4 | balrog | /* TODO: This is very suboptimal, we can easily have a constant
|
353 | 811d4cf4 | balrog | * pool somewhere after all the instructions. */
|
354 | 811d4cf4 | balrog | |
355 | 811d4cf4 | balrog | if (arg < 0 && arg > -0x100) |
356 | 811d4cf4 | balrog | return tcg_out_dat_imm(s, cond, ARITH_MVN, rd, 0, (~arg) & 0xff); |
357 | 811d4cf4 | balrog | |
358 | 811d4cf4 | balrog | if (offset < 0x100 && offset > -0x100) |
359 | 811d4cf4 | balrog | return offset >= 0 ? |
360 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_ADD, rd, 15, offset) :
|
361 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_SUB, rd, 15, -offset);
|
362 | 811d4cf4 | balrog | |
363 | cb4e581f | Laurent Desnogues | #ifdef __ARM_ARCH_7A__
|
364 | cb4e581f | Laurent Desnogues | /* use movw/movt */
|
365 | cb4e581f | Laurent Desnogues | /* movw */
|
366 | cb4e581f | Laurent Desnogues | tcg_out32(s, (cond << 28) | 0x03000000 | (rd << 12) |
367 | cb4e581f | Laurent Desnogues | | ((arg << 4) & 0x000f0000) | (arg & 0xfff)); |
368 | cb4e581f | Laurent Desnogues | if (arg & 0xffff0000) |
369 | cb4e581f | Laurent Desnogues | /* movt */
|
370 | cb4e581f | Laurent Desnogues | tcg_out32(s, (cond << 28) | 0x03400000 | (rd << 12) |
371 | cb4e581f | Laurent Desnogues | | ((arg >> 12) & 0x000f0000) | ((arg >> 16) & 0xfff)); |
372 | cb4e581f | Laurent Desnogues | #else
|
373 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, rd, 0, arg & 0xff); |
374 | 811d4cf4 | balrog | if (arg & 0x0000ff00) |
375 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_ORR, rd, rd, |
376 | 811d4cf4 | balrog | ((arg >> 8) & 0xff) | 0xc00); |
377 | 811d4cf4 | balrog | if (arg & 0x00ff0000) |
378 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_ORR, rd, rd, |
379 | 811d4cf4 | balrog | ((arg >> 16) & 0xff) | 0x800); |
380 | 811d4cf4 | balrog | if (arg & 0xff000000) |
381 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_ORR, rd, rd, |
382 | 811d4cf4 | balrog | ((arg >> 24) & 0xff) | 0x400); |
383 | cb4e581f | Laurent Desnogues | #endif
|
384 | 811d4cf4 | balrog | } |
385 | 811d4cf4 | balrog | |
386 | 811d4cf4 | balrog | static inline void tcg_out_mul32(TCGContext *s, |
387 | 811d4cf4 | balrog | int cond, int rd, int rs, int rm) |
388 | 811d4cf4 | balrog | { |
389 | 811d4cf4 | balrog | if (rd != rm)
|
390 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | (rd << 16) | (0 << 12) | |
391 | 811d4cf4 | balrog | (rs << 8) | 0x90 | rm); |
392 | 811d4cf4 | balrog | else if (rd != rs) |
393 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | (rd << 16) | (0 << 12) | |
394 | 811d4cf4 | balrog | (rm << 8) | 0x90 | rs); |
395 | 811d4cf4 | balrog | else {
|
396 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | ( 8 << 16) | (0 << 12) | |
397 | 811d4cf4 | balrog | (rs << 8) | 0x90 | rm); |
398 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
399 | 811d4cf4 | balrog | rd, 0, 8, SHIFT_IMM_LSL(0)); |
400 | 811d4cf4 | balrog | } |
401 | 811d4cf4 | balrog | } |
402 | 811d4cf4 | balrog | |
403 | 811d4cf4 | balrog | static inline void tcg_out_umull32(TCGContext *s, |
404 | 811d4cf4 | balrog | int cond, int rd0, int rd1, int rs, int rm) |
405 | 811d4cf4 | balrog | { |
406 | 811d4cf4 | balrog | if (rd0 != rm && rd1 != rm)
|
407 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x800090 | |
408 | 811d4cf4 | balrog | (rd1 << 16) | (rd0 << 12) | (rs << 8) | rm); |
409 | 811d4cf4 | balrog | else if (rd0 != rs && rd1 != rs) |
410 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x800090 | |
411 | 811d4cf4 | balrog | (rd1 << 16) | (rd0 << 12) | (rm << 8) | rs); |
412 | 811d4cf4 | balrog | else {
|
413 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
414 | 811d4cf4 | balrog | TCG_REG_R8, 0, rm, SHIFT_IMM_LSL(0)); |
415 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x800098 | |
416 | 811d4cf4 | balrog | (rd1 << 16) | (rd0 << 12) | (rs << 8)); |
417 | 811d4cf4 | balrog | } |
418 | 811d4cf4 | balrog | } |
419 | 811d4cf4 | balrog | |
420 | 811d4cf4 | balrog | static inline void tcg_out_smull32(TCGContext *s, |
421 | 811d4cf4 | balrog | int cond, int rd0, int rd1, int rs, int rm) |
422 | 811d4cf4 | balrog | { |
423 | 811d4cf4 | balrog | if (rd0 != rm && rd1 != rm)
|
424 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0xc00090 | |
425 | 811d4cf4 | balrog | (rd1 << 16) | (rd0 << 12) | (rs << 8) | rm); |
426 | 811d4cf4 | balrog | else if (rd0 != rs && rd1 != rs) |
427 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0xc00090 | |
428 | 811d4cf4 | balrog | (rd1 << 16) | (rd0 << 12) | (rm << 8) | rs); |
429 | 811d4cf4 | balrog | else {
|
430 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
431 | 811d4cf4 | balrog | TCG_REG_R8, 0, rm, SHIFT_IMM_LSL(0)); |
432 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0xc00098 | |
433 | 811d4cf4 | balrog | (rd1 << 16) | (rd0 << 12) | (rs << 8)); |
434 | 811d4cf4 | balrog | } |
435 | 811d4cf4 | balrog | } |
436 | 811d4cf4 | balrog | |
437 | 811d4cf4 | balrog | static inline void tcg_out_ld32_12(TCGContext *s, int cond, |
438 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
439 | 811d4cf4 | balrog | { |
440 | 811d4cf4 | balrog | if (im >= 0) |
441 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05900000 | |
442 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | (im & 0xfff)); |
443 | 811d4cf4 | balrog | else
|
444 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05100000 | |
445 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | ((-im) & 0xfff)); |
446 | 811d4cf4 | balrog | } |
447 | 811d4cf4 | balrog | |
448 | 811d4cf4 | balrog | static inline void tcg_out_st32_12(TCGContext *s, int cond, |
449 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
450 | 811d4cf4 | balrog | { |
451 | 811d4cf4 | balrog | if (im >= 0) |
452 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05800000 | |
453 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | (im & 0xfff)); |
454 | 811d4cf4 | balrog | else
|
455 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05000000 | |
456 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | ((-im) & 0xfff)); |
457 | 811d4cf4 | balrog | } |
458 | 811d4cf4 | balrog | |
459 | 811d4cf4 | balrog | static inline void tcg_out_ld32_r(TCGContext *s, int cond, |
460 | 811d4cf4 | balrog | int rd, int rn, int rm) |
461 | 811d4cf4 | balrog | { |
462 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x07900000 | |
463 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
464 | 811d4cf4 | balrog | } |
465 | 811d4cf4 | balrog | |
466 | 811d4cf4 | balrog | static inline void tcg_out_st32_r(TCGContext *s, int cond, |
467 | 811d4cf4 | balrog | int rd, int rn, int rm) |
468 | 811d4cf4 | balrog | { |
469 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x07800000 | |
470 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
471 | 811d4cf4 | balrog | } |
472 | 811d4cf4 | balrog | |
473 | 3979144c | pbrook | /* Register pre-increment with base writeback. */
|
474 | 3979144c | pbrook | static inline void tcg_out_ld32_rwb(TCGContext *s, int cond, |
475 | 3979144c | pbrook | int rd, int rn, int rm) |
476 | 3979144c | pbrook | { |
477 | 3979144c | pbrook | tcg_out32(s, (cond << 28) | 0x07b00000 | |
478 | 3979144c | pbrook | (rn << 16) | (rd << 12) | rm); |
479 | 3979144c | pbrook | } |
480 | 3979144c | pbrook | |
481 | 3979144c | pbrook | static inline void tcg_out_st32_rwb(TCGContext *s, int cond, |
482 | 3979144c | pbrook | int rd, int rn, int rm) |
483 | 3979144c | pbrook | { |
484 | 3979144c | pbrook | tcg_out32(s, (cond << 28) | 0x07a00000 | |
485 | 3979144c | pbrook | (rn << 16) | (rd << 12) | rm); |
486 | 3979144c | pbrook | } |
487 | 3979144c | pbrook | |
488 | 811d4cf4 | balrog | static inline void tcg_out_ld16u_8(TCGContext *s, int cond, |
489 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
490 | 811d4cf4 | balrog | { |
491 | 811d4cf4 | balrog | if (im >= 0) |
492 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x01d000b0 | |
493 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
494 | 811d4cf4 | balrog | ((im & 0xf0) << 4) | (im & 0xf)); |
495 | 811d4cf4 | balrog | else
|
496 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x015000b0 | |
497 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
498 | 811d4cf4 | balrog | (((-im) & 0xf0) << 4) | ((-im) & 0xf)); |
499 | 811d4cf4 | balrog | } |
500 | 811d4cf4 | balrog | |
501 | 811d4cf4 | balrog | static inline void tcg_out_st16u_8(TCGContext *s, int cond, |
502 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
503 | 811d4cf4 | balrog | { |
504 | 811d4cf4 | balrog | if (im >= 0) |
505 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x01c000b0 | |
506 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
507 | 811d4cf4 | balrog | ((im & 0xf0) << 4) | (im & 0xf)); |
508 | 811d4cf4 | balrog | else
|
509 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x014000b0 | |
510 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
511 | 811d4cf4 | balrog | (((-im) & 0xf0) << 4) | ((-im) & 0xf)); |
512 | 811d4cf4 | balrog | } |
513 | 811d4cf4 | balrog | |
514 | 811d4cf4 | balrog | static inline void tcg_out_ld16u_r(TCGContext *s, int cond, |
515 | 811d4cf4 | balrog | int rd, int rn, int rm) |
516 | 811d4cf4 | balrog | { |
517 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x019000b0 | |
518 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
519 | 811d4cf4 | balrog | } |
520 | 811d4cf4 | balrog | |
521 | 811d4cf4 | balrog | static inline void tcg_out_st16u_r(TCGContext *s, int cond, |
522 | 811d4cf4 | balrog | int rd, int rn, int rm) |
523 | 811d4cf4 | balrog | { |
524 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x018000b0 | |
525 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
526 | 811d4cf4 | balrog | } |
527 | 811d4cf4 | balrog | |
528 | 811d4cf4 | balrog | static inline void tcg_out_ld16s_8(TCGContext *s, int cond, |
529 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
530 | 811d4cf4 | balrog | { |
531 | 811d4cf4 | balrog | if (im >= 0) |
532 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x01d000f0 | |
533 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
534 | 811d4cf4 | balrog | ((im & 0xf0) << 4) | (im & 0xf)); |
535 | 811d4cf4 | balrog | else
|
536 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x015000f0 | |
537 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
538 | 811d4cf4 | balrog | (((-im) & 0xf0) << 4) | ((-im) & 0xf)); |
539 | 811d4cf4 | balrog | } |
540 | 811d4cf4 | balrog | |
541 | 811d4cf4 | balrog | static inline void tcg_out_st16s_8(TCGContext *s, int cond, |
542 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
543 | 811d4cf4 | balrog | { |
544 | 811d4cf4 | balrog | if (im >= 0) |
545 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x01c000f0 | |
546 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
547 | 811d4cf4 | balrog | ((im & 0xf0) << 4) | (im & 0xf)); |
548 | 811d4cf4 | balrog | else
|
549 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x014000f0 | |
550 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
551 | 811d4cf4 | balrog | (((-im) & 0xf0) << 4) | ((-im) & 0xf)); |
552 | 811d4cf4 | balrog | } |
553 | 811d4cf4 | balrog | |
554 | 811d4cf4 | balrog | static inline void tcg_out_ld16s_r(TCGContext *s, int cond, |
555 | 811d4cf4 | balrog | int rd, int rn, int rm) |
556 | 811d4cf4 | balrog | { |
557 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x019000f0 | |
558 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
559 | 811d4cf4 | balrog | } |
560 | 811d4cf4 | balrog | |
561 | 811d4cf4 | balrog | static inline void tcg_out_st16s_r(TCGContext *s, int cond, |
562 | 811d4cf4 | balrog | int rd, int rn, int rm) |
563 | 811d4cf4 | balrog | { |
564 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x018000f0 | |
565 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
566 | 811d4cf4 | balrog | } |
567 | 811d4cf4 | balrog | |
568 | 811d4cf4 | balrog | static inline void tcg_out_ld8_12(TCGContext *s, int cond, |
569 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
570 | 811d4cf4 | balrog | { |
571 | 811d4cf4 | balrog | if (im >= 0) |
572 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05d00000 | |
573 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | (im & 0xfff)); |
574 | 811d4cf4 | balrog | else
|
575 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05500000 | |
576 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | ((-im) & 0xfff)); |
577 | 811d4cf4 | balrog | } |
578 | 811d4cf4 | balrog | |
579 | 811d4cf4 | balrog | static inline void tcg_out_st8_12(TCGContext *s, int cond, |
580 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
581 | 811d4cf4 | balrog | { |
582 | 811d4cf4 | balrog | if (im >= 0) |
583 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05c00000 | |
584 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | (im & 0xfff)); |
585 | 811d4cf4 | balrog | else
|
586 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x05400000 | |
587 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | ((-im) & 0xfff)); |
588 | 811d4cf4 | balrog | } |
589 | 811d4cf4 | balrog | |
590 | 811d4cf4 | balrog | static inline void tcg_out_ld8_r(TCGContext *s, int cond, |
591 | 811d4cf4 | balrog | int rd, int rn, int rm) |
592 | 811d4cf4 | balrog | { |
593 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x07d00000 | |
594 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
595 | 811d4cf4 | balrog | } |
596 | 811d4cf4 | balrog | |
597 | 811d4cf4 | balrog | static inline void tcg_out_st8_r(TCGContext *s, int cond, |
598 | 811d4cf4 | balrog | int rd, int rn, int rm) |
599 | 811d4cf4 | balrog | { |
600 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x07c00000 | |
601 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
602 | 811d4cf4 | balrog | } |
603 | 811d4cf4 | balrog | |
604 | 811d4cf4 | balrog | static inline void tcg_out_ld8s_8(TCGContext *s, int cond, |
605 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
606 | 811d4cf4 | balrog | { |
607 | 811d4cf4 | balrog | if (im >= 0) |
608 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x01d000d0 | |
609 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
610 | 811d4cf4 | balrog | ((im & 0xf0) << 4) | (im & 0xf)); |
611 | 811d4cf4 | balrog | else
|
612 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x015000d0 | |
613 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
614 | 811d4cf4 | balrog | (((-im) & 0xf0) << 4) | ((-im) & 0xf)); |
615 | 811d4cf4 | balrog | } |
616 | 811d4cf4 | balrog | |
617 | 811d4cf4 | balrog | static inline void tcg_out_st8s_8(TCGContext *s, int cond, |
618 | 811d4cf4 | balrog | int rd, int rn, tcg_target_long im) |
619 | 811d4cf4 | balrog | { |
620 | 811d4cf4 | balrog | if (im >= 0) |
621 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x01c000d0 | |
622 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
623 | 811d4cf4 | balrog | ((im & 0xf0) << 4) | (im & 0xf)); |
624 | 811d4cf4 | balrog | else
|
625 | 811d4cf4 | balrog | tcg_out32(s, (cond << 28) | 0x014000d0 | |
626 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | |
627 | 811d4cf4 | balrog | (((-im) & 0xf0) << 4) | ((-im) & 0xf)); |
628 | 811d4cf4 | balrog | } |
629 | 811d4cf4 | balrog | |
630 | 811d4cf4 | balrog | static inline void tcg_out_ld8s_r(TCGContext *s, int cond, |
631 | 811d4cf4 | balrog | int rd, int rn, int rm) |
632 | 811d4cf4 | balrog | { |
633 | 204c1674 | balrog | tcg_out32(s, (cond << 28) | 0x019000d0 | |
634 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
635 | 811d4cf4 | balrog | } |
636 | 811d4cf4 | balrog | |
637 | 811d4cf4 | balrog | static inline void tcg_out_st8s_r(TCGContext *s, int cond, |
638 | 811d4cf4 | balrog | int rd, int rn, int rm) |
639 | 811d4cf4 | balrog | { |
640 | 204c1674 | balrog | tcg_out32(s, (cond << 28) | 0x018000d0 | |
641 | 811d4cf4 | balrog | (rn << 16) | (rd << 12) | rm); |
642 | 811d4cf4 | balrog | } |
643 | 811d4cf4 | balrog | |
644 | 811d4cf4 | balrog | static inline void tcg_out_ld32u(TCGContext *s, int cond, |
645 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
646 | 811d4cf4 | balrog | { |
647 | 811d4cf4 | balrog | if (offset > 0xfff || offset < -0xfff) { |
648 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
649 | 811d4cf4 | balrog | tcg_out_ld32_r(s, cond, rd, rn, TCG_REG_R8); |
650 | 811d4cf4 | balrog | } else
|
651 | 811d4cf4 | balrog | tcg_out_ld32_12(s, cond, rd, rn, offset); |
652 | 811d4cf4 | balrog | } |
653 | 811d4cf4 | balrog | |
654 | 811d4cf4 | balrog | static inline void tcg_out_st32(TCGContext *s, int cond, |
655 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
656 | 811d4cf4 | balrog | { |
657 | 811d4cf4 | balrog | if (offset > 0xfff || offset < -0xfff) { |
658 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
659 | 811d4cf4 | balrog | tcg_out_st32_r(s, cond, rd, rn, TCG_REG_R8); |
660 | 811d4cf4 | balrog | } else
|
661 | 811d4cf4 | balrog | tcg_out_st32_12(s, cond, rd, rn, offset); |
662 | 811d4cf4 | balrog | } |
663 | 811d4cf4 | balrog | |
664 | 811d4cf4 | balrog | static inline void tcg_out_ld16u(TCGContext *s, int cond, |
665 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
666 | 811d4cf4 | balrog | { |
667 | 811d4cf4 | balrog | if (offset > 0xff || offset < -0xff) { |
668 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
669 | 811d4cf4 | balrog | tcg_out_ld16u_r(s, cond, rd, rn, TCG_REG_R8); |
670 | 811d4cf4 | balrog | } else
|
671 | 811d4cf4 | balrog | tcg_out_ld16u_8(s, cond, rd, rn, offset); |
672 | 811d4cf4 | balrog | } |
673 | 811d4cf4 | balrog | |
674 | 811d4cf4 | balrog | static inline void tcg_out_ld16s(TCGContext *s, int cond, |
675 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
676 | 811d4cf4 | balrog | { |
677 | 811d4cf4 | balrog | if (offset > 0xff || offset < -0xff) { |
678 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
679 | 811d4cf4 | balrog | tcg_out_ld16s_r(s, cond, rd, rn, TCG_REG_R8); |
680 | 811d4cf4 | balrog | } else
|
681 | 811d4cf4 | balrog | tcg_out_ld16s_8(s, cond, rd, rn, offset); |
682 | 811d4cf4 | balrog | } |
683 | 811d4cf4 | balrog | |
684 | 811d4cf4 | balrog | static inline void tcg_out_st16u(TCGContext *s, int cond, |
685 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
686 | 811d4cf4 | balrog | { |
687 | 811d4cf4 | balrog | if (offset > 0xff || offset < -0xff) { |
688 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
689 | 811d4cf4 | balrog | tcg_out_st16u_r(s, cond, rd, rn, TCG_REG_R8); |
690 | 811d4cf4 | balrog | } else
|
691 | 811d4cf4 | balrog | tcg_out_st16u_8(s, cond, rd, rn, offset); |
692 | 811d4cf4 | balrog | } |
693 | 811d4cf4 | balrog | |
694 | 811d4cf4 | balrog | static inline void tcg_out_ld8u(TCGContext *s, int cond, |
695 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
696 | 811d4cf4 | balrog | { |
697 | 811d4cf4 | balrog | if (offset > 0xfff || offset < -0xfff) { |
698 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
699 | 811d4cf4 | balrog | tcg_out_ld8_r(s, cond, rd, rn, TCG_REG_R8); |
700 | 811d4cf4 | balrog | } else
|
701 | 811d4cf4 | balrog | tcg_out_ld8_12(s, cond, rd, rn, offset); |
702 | 811d4cf4 | balrog | } |
703 | 811d4cf4 | balrog | |
704 | 811d4cf4 | balrog | static inline void tcg_out_ld8s(TCGContext *s, int cond, |
705 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
706 | 811d4cf4 | balrog | { |
707 | 811d4cf4 | balrog | if (offset > 0xff || offset < -0xff) { |
708 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
709 | 811d4cf4 | balrog | tcg_out_ld8s_r(s, cond, rd, rn, TCG_REG_R8); |
710 | 811d4cf4 | balrog | } else
|
711 | 811d4cf4 | balrog | tcg_out_ld8s_8(s, cond, rd, rn, offset); |
712 | 811d4cf4 | balrog | } |
713 | 811d4cf4 | balrog | |
714 | 811d4cf4 | balrog | static inline void tcg_out_st8u(TCGContext *s, int cond, |
715 | 811d4cf4 | balrog | int rd, int rn, int32_t offset) |
716 | 811d4cf4 | balrog | { |
717 | 811d4cf4 | balrog | if (offset > 0xfff || offset < -0xfff) { |
718 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, offset); |
719 | 811d4cf4 | balrog | tcg_out_st8_r(s, cond, rd, rn, TCG_REG_R8); |
720 | 811d4cf4 | balrog | } else
|
721 | 811d4cf4 | balrog | tcg_out_st8_12(s, cond, rd, rn, offset); |
722 | 811d4cf4 | balrog | } |
723 | 811d4cf4 | balrog | |
724 | 811d4cf4 | balrog | static inline void tcg_out_goto(TCGContext *s, int cond, uint32_t addr) |
725 | 811d4cf4 | balrog | { |
726 | 811d4cf4 | balrog | int32_t val; |
727 | 811d4cf4 | balrog | |
728 | 811d4cf4 | balrog | val = addr - (tcg_target_long) s->code_ptr; |
729 | 811d4cf4 | balrog | if (val - 8 < 0x01fffffd && val - 8 > -0x01fffffd) |
730 | 811d4cf4 | balrog | tcg_out_b(s, cond, val); |
731 | 811d4cf4 | balrog | else {
|
732 | 811d4cf4 | balrog | #if 1 |
733 | 811d4cf4 | balrog | tcg_abort(); |
734 | 811d4cf4 | balrog | #else
|
735 | 811d4cf4 | balrog | if (cond == COND_AL) {
|
736 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, 15, -4); |
737 | 811d4cf4 | balrog | tcg_out32(s, addr); /* XXX: This is l->u.value, can we use it? */
|
738 | 811d4cf4 | balrog | } else {
|
739 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R8, val - 8);
|
740 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_ADD, |
741 | 811d4cf4 | balrog | 15, 15, TCG_REG_R8, SHIFT_IMM_LSL(0)); |
742 | 811d4cf4 | balrog | } |
743 | 811d4cf4 | balrog | #endif
|
744 | 811d4cf4 | balrog | } |
745 | 811d4cf4 | balrog | } |
746 | 811d4cf4 | balrog | |
747 | 811d4cf4 | balrog | static inline void tcg_out_call(TCGContext *s, int cond, uint32_t addr) |
748 | 811d4cf4 | balrog | { |
749 | 811d4cf4 | balrog | int32_t val; |
750 | 811d4cf4 | balrog | |
751 | 811d4cf4 | balrog | #ifdef SAVE_LR
|
752 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, TCG_REG_R8, 0, 14, SHIFT_IMM_LSL(0)); |
753 | 811d4cf4 | balrog | #endif
|
754 | 811d4cf4 | balrog | |
755 | 811d4cf4 | balrog | val = addr - (tcg_target_long) s->code_ptr; |
756 | 811d4cf4 | balrog | if (val < 0x01fffffd && val > -0x01fffffd) |
757 | 811d4cf4 | balrog | tcg_out_bl(s, cond, val); |
758 | 811d4cf4 | balrog | else {
|
759 | 811d4cf4 | balrog | #if 1 |
760 | 811d4cf4 | balrog | tcg_abort(); |
761 | 811d4cf4 | balrog | #else
|
762 | 811d4cf4 | balrog | if (cond == COND_AL) {
|
763 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_ADD, 14, 15, 4); |
764 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, 15, -4); |
765 | 811d4cf4 | balrog | tcg_out32(s, addr); /* XXX: This is l->u.value, can we use it? */
|
766 | 811d4cf4 | balrog | } else {
|
767 | 811d4cf4 | balrog | tcg_out_movi32(s, cond, TCG_REG_R9, addr); |
768 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 14, 0, 15); |
769 | 811d4cf4 | balrog | tcg_out_bx(s, cond, TCG_REG_R9); |
770 | 811d4cf4 | balrog | } |
771 | 811d4cf4 | balrog | #endif
|
772 | 811d4cf4 | balrog | } |
773 | 811d4cf4 | balrog | |
774 | 811d4cf4 | balrog | #ifdef SAVE_LR
|
775 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 14, 0, TCG_REG_R8, SHIFT_IMM_LSL(0)); |
776 | 811d4cf4 | balrog | #endif
|
777 | 811d4cf4 | balrog | } |
778 | 811d4cf4 | balrog | |
779 | 811d4cf4 | balrog | static inline void tcg_out_callr(TCGContext *s, int cond, int arg) |
780 | 811d4cf4 | balrog | { |
781 | 811d4cf4 | balrog | #ifdef SAVE_LR
|
782 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, TCG_REG_R8, 0, 14, SHIFT_IMM_LSL(0)); |
783 | 811d4cf4 | balrog | #endif
|
784 | 811d4cf4 | balrog | /* TODO: on ARMv5 and ARMv6 replace with tcg_out_blx(s, cond, arg); */
|
785 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 14, 0, 15, SHIFT_IMM_LSL(0)); |
786 | 811d4cf4 | balrog | tcg_out_bx(s, cond, arg); |
787 | 811d4cf4 | balrog | #ifdef SAVE_LR
|
788 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 14, 0, TCG_REG_R8, SHIFT_IMM_LSL(0)); |
789 | 811d4cf4 | balrog | #endif
|
790 | 811d4cf4 | balrog | } |
791 | 811d4cf4 | balrog | |
792 | 811d4cf4 | balrog | static inline void tcg_out_goto_label(TCGContext *s, int cond, int label_index) |
793 | 811d4cf4 | balrog | { |
794 | 811d4cf4 | balrog | TCGLabel *l = &s->labels[label_index]; |
795 | 811d4cf4 | balrog | |
796 | 811d4cf4 | balrog | if (l->has_value)
|
797 | 811d4cf4 | balrog | tcg_out_goto(s, cond, l->u.value); |
798 | 811d4cf4 | balrog | else if (cond == COND_AL) { |
799 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, 15, -4); |
800 | 811d4cf4 | balrog | tcg_out_reloc(s, s->code_ptr, R_ARM_ABS32, label_index, 31337);
|
801 | 811d4cf4 | balrog | s->code_ptr += 4;
|
802 | 811d4cf4 | balrog | } else {
|
803 | 811d4cf4 | balrog | /* Probably this should be preferred even for COND_AL... */
|
804 | 811d4cf4 | balrog | tcg_out_reloc(s, s->code_ptr, R_ARM_PC24, label_index, 31337);
|
805 | e936243a | balrog | tcg_out_b_noaddr(s, cond); |
806 | 811d4cf4 | balrog | } |
807 | 811d4cf4 | balrog | } |
808 | 811d4cf4 | balrog | |
809 | 811d4cf4 | balrog | #ifdef CONFIG_SOFTMMU
|
810 | 79383c9c | blueswir1 | |
811 | 79383c9c | blueswir1 | #include "../../softmmu_defs.h" |
812 | 811d4cf4 | balrog | |
813 | 811d4cf4 | balrog | static void *qemu_ld_helpers[4] = { |
814 | 811d4cf4 | balrog | __ldb_mmu, |
815 | 811d4cf4 | balrog | __ldw_mmu, |
816 | 811d4cf4 | balrog | __ldl_mmu, |
817 | 811d4cf4 | balrog | __ldq_mmu, |
818 | 811d4cf4 | balrog | }; |
819 | 811d4cf4 | balrog | |
820 | 811d4cf4 | balrog | static void *qemu_st_helpers[4] = { |
821 | 811d4cf4 | balrog | __stb_mmu, |
822 | 811d4cf4 | balrog | __stw_mmu, |
823 | 811d4cf4 | balrog | __stl_mmu, |
824 | 811d4cf4 | balrog | __stq_mmu, |
825 | 811d4cf4 | balrog | }; |
826 | 811d4cf4 | balrog | #endif
|
827 | 811d4cf4 | balrog | |
828 | 3979144c | pbrook | #define TLB_SHIFT (CPU_TLB_ENTRY_BITS + CPU_TLB_BITS)
|
829 | 3979144c | pbrook | |
830 | 811d4cf4 | balrog | static inline void tcg_out_qemu_ld(TCGContext *s, int cond, |
831 | 811d4cf4 | balrog | const TCGArg *args, int opc) |
832 | 811d4cf4 | balrog | { |
833 | 811d4cf4 | balrog | int addr_reg, data_reg, data_reg2;
|
834 | 811d4cf4 | balrog | #ifdef CONFIG_SOFTMMU
|
835 | 811d4cf4 | balrog | int mem_index, s_bits;
|
836 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
837 | 811d4cf4 | balrog | int addr_reg2;
|
838 | 811d4cf4 | balrog | # endif
|
839 | 811d4cf4 | balrog | uint32_t *label_ptr; |
840 | 811d4cf4 | balrog | #endif
|
841 | 811d4cf4 | balrog | |
842 | 811d4cf4 | balrog | data_reg = *args++; |
843 | 811d4cf4 | balrog | if (opc == 3) |
844 | 811d4cf4 | balrog | data_reg2 = *args++; |
845 | 811d4cf4 | balrog | else
|
846 | d89c682f | Stefan Weil | data_reg2 = 0; /* suppress warning */ |
847 | 811d4cf4 | balrog | addr_reg = *args++; |
848 | 811d4cf4 | balrog | #ifdef CONFIG_SOFTMMU
|
849 | aef3a282 | balrog | # if TARGET_LONG_BITS == 64 |
850 | aef3a282 | balrog | addr_reg2 = *args++; |
851 | aef3a282 | balrog | # endif
|
852 | 811d4cf4 | balrog | mem_index = *args; |
853 | 811d4cf4 | balrog | s_bits = opc & 3;
|
854 | 811d4cf4 | balrog | |
855 | 91a3c1b0 | balrog | /* Should generate something like the following:
|
856 | 3979144c | pbrook | * shr r8, addr_reg, #TARGET_PAGE_BITS
|
857 | 91a3c1b0 | balrog | * and r0, r8, #(CPU_TLB_SIZE - 1) @ Assumption: CPU_TLB_BITS <= 8
|
858 | 3979144c | pbrook | * add r0, env, r0 lsl #CPU_TLB_ENTRY_BITS
|
859 | 91a3c1b0 | balrog | */
|
860 | 91a3c1b0 | balrog | # if CPU_TLB_BITS > 8 |
861 | 91a3c1b0 | balrog | # error
|
862 | 91a3c1b0 | balrog | # endif
|
863 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
864 | 3979144c | pbrook | 8, 0, addr_reg, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); |
865 | 811d4cf4 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_AND, |
866 | 811d4cf4 | balrog | 0, 8, CPU_TLB_SIZE - 1); |
867 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_ADD, |
868 | 811d4cf4 | balrog | 0, TCG_AREG0, 0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS)); |
869 | 91a3c1b0 | balrog | /* In the
|
870 | 91a3c1b0 | balrog | * ldr r1 [r0, #(offsetof(CPUState, tlb_table[mem_index][0].addr_read))]
|
871 | 91a3c1b0 | balrog | * below, the offset is likely to exceed 12 bits if mem_index != 0 and
|
872 | 91a3c1b0 | balrog | * not exceed otherwise, so use an
|
873 | 91a3c1b0 | balrog | * add r0, r0, #(mem_index * sizeof *CPUState.tlb_table)
|
874 | 91a3c1b0 | balrog | * before.
|
875 | 91a3c1b0 | balrog | */
|
876 | 225b4376 | balrog | if (mem_index)
|
877 | 225b4376 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_ADD, 0, 0, |
878 | 225b4376 | balrog | (mem_index << (TLB_SHIFT & 1)) |
|
879 | 225b4376 | balrog | ((16 - (TLB_SHIFT >> 1)) << 8)); |
880 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 1, 0, |
881 | 225b4376 | balrog | offsetof(CPUState, tlb_table[0][0].addr_read)); |
882 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_CMP, |
883 | 811d4cf4 | balrog | 0, 1, 8, SHIFT_IMM_LSL(TARGET_PAGE_BITS)); |
884 | 3979144c | pbrook | /* Check alignment. */
|
885 | 3979144c | pbrook | if (s_bits)
|
886 | 3979144c | pbrook | tcg_out_dat_imm(s, COND_EQ, ARITH_TST, |
887 | 3979144c | pbrook | 0, addr_reg, (1 << s_bits) - 1); |
888 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
889 | 811d4cf4 | balrog | /* XXX: possibly we could use a block data load or writeback in
|
890 | 811d4cf4 | balrog | * the first access. */
|
891 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_EQ, 1, 0, |
892 | 225b4376 | balrog | offsetof(CPUState, tlb_table[0][0].addr_read) + 4); |
893 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, |
894 | 811d4cf4 | balrog | 0, 1, addr_reg2, SHIFT_IMM_LSL(0)); |
895 | 811d4cf4 | balrog | # endif
|
896 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_EQ, 1, 0, |
897 | 225b4376 | balrog | offsetof(CPUState, tlb_table[0][0].addend)); |
898 | 811d4cf4 | balrog | |
899 | 811d4cf4 | balrog | switch (opc) {
|
900 | 811d4cf4 | balrog | case 0: |
901 | 811d4cf4 | balrog | tcg_out_ld8_r(s, COND_EQ, data_reg, addr_reg, 1);
|
902 | 811d4cf4 | balrog | break;
|
903 | 811d4cf4 | balrog | case 0 | 4: |
904 | 811d4cf4 | balrog | tcg_out_ld8s_r(s, COND_EQ, data_reg, addr_reg, 1);
|
905 | 811d4cf4 | balrog | break;
|
906 | 811d4cf4 | balrog | case 1: |
907 | 811d4cf4 | balrog | tcg_out_ld16u_r(s, COND_EQ, data_reg, addr_reg, 1);
|
908 | 811d4cf4 | balrog | break;
|
909 | 811d4cf4 | balrog | case 1 | 4: |
910 | 811d4cf4 | balrog | tcg_out_ld16s_r(s, COND_EQ, data_reg, addr_reg, 1);
|
911 | 811d4cf4 | balrog | break;
|
912 | 811d4cf4 | balrog | case 2: |
913 | 811d4cf4 | balrog | default:
|
914 | 811d4cf4 | balrog | tcg_out_ld32_r(s, COND_EQ, data_reg, addr_reg, 1);
|
915 | 811d4cf4 | balrog | break;
|
916 | 811d4cf4 | balrog | case 3: |
917 | 3979144c | pbrook | tcg_out_ld32_rwb(s, COND_EQ, data_reg, 1, addr_reg);
|
918 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_EQ, data_reg2, 1, 4); |
919 | 811d4cf4 | balrog | break;
|
920 | 811d4cf4 | balrog | } |
921 | 811d4cf4 | balrog | |
922 | 811d4cf4 | balrog | label_ptr = (void *) s->code_ptr;
|
923 | 811d4cf4 | balrog | tcg_out_b(s, COND_EQ, 8);
|
924 | 811d4cf4 | balrog | |
925 | 811d4cf4 | balrog | # ifdef SAVE_LR
|
926 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 8, 0, 14, SHIFT_IMM_LSL(0)); |
927 | 811d4cf4 | balrog | # endif
|
928 | 811d4cf4 | balrog | |
929 | 811d4cf4 | balrog | /* TODO: move this code to where the constants pool will be */
|
930 | 811d4cf4 | balrog | if (addr_reg)
|
931 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
932 | 811d4cf4 | balrog | 0, 0, addr_reg, SHIFT_IMM_LSL(0)); |
933 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 32 |
934 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 1, 0, mem_index); |
935 | 811d4cf4 | balrog | # else
|
936 | 811d4cf4 | balrog | if (addr_reg2 != 1) |
937 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
938 | 811d4cf4 | balrog | 1, 0, addr_reg2, SHIFT_IMM_LSL(0)); |
939 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 2, 0, mem_index); |
940 | 811d4cf4 | balrog | # endif
|
941 | 650bbb36 | balrog | tcg_out_bl(s, cond, (tcg_target_long) qemu_ld_helpers[s_bits] - |
942 | 811d4cf4 | balrog | (tcg_target_long) s->code_ptr); |
943 | 811d4cf4 | balrog | |
944 | 811d4cf4 | balrog | switch (opc) {
|
945 | 811d4cf4 | balrog | case 0 | 4: |
946 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
947 | 811d4cf4 | balrog | 0, 0, 0, SHIFT_IMM_LSL(24)); |
948 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
949 | 811d4cf4 | balrog | data_reg, 0, 0, SHIFT_IMM_ASR(24)); |
950 | 811d4cf4 | balrog | break;
|
951 | 811d4cf4 | balrog | case 1 | 4: |
952 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
953 | 811d4cf4 | balrog | 0, 0, 0, SHIFT_IMM_LSL(16)); |
954 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
955 | 811d4cf4 | balrog | data_reg, 0, 0, SHIFT_IMM_ASR(16)); |
956 | 811d4cf4 | balrog | break;
|
957 | 811d4cf4 | balrog | case 0: |
958 | 811d4cf4 | balrog | case 1: |
959 | 811d4cf4 | balrog | case 2: |
960 | 811d4cf4 | balrog | default:
|
961 | 811d4cf4 | balrog | if (data_reg)
|
962 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
963 | 811d4cf4 | balrog | data_reg, 0, 0, SHIFT_IMM_LSL(0)); |
964 | 811d4cf4 | balrog | break;
|
965 | 811d4cf4 | balrog | case 3: |
966 | d0660ed4 | balrog | if (data_reg != 0) |
967 | d0660ed4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
968 | d0660ed4 | balrog | data_reg, 0, 0, SHIFT_IMM_LSL(0)); |
969 | 811d4cf4 | balrog | if (data_reg2 != 1) |
970 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
971 | 811d4cf4 | balrog | data_reg2, 0, 1, SHIFT_IMM_LSL(0)); |
972 | 811d4cf4 | balrog | break;
|
973 | 811d4cf4 | balrog | } |
974 | 811d4cf4 | balrog | |
975 | 811d4cf4 | balrog | # ifdef SAVE_LR
|
976 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 14, 0, 8, SHIFT_IMM_LSL(0)); |
977 | 811d4cf4 | balrog | # endif
|
978 | 811d4cf4 | balrog | |
979 | 811d4cf4 | balrog | *label_ptr += ((void *) s->code_ptr - (void *) label_ptr - 8) >> 2; |
980 | 379f6698 | Paul Brook | #else /* !CONFIG_SOFTMMU */ |
981 | 379f6698 | Paul Brook | if (GUEST_BASE) {
|
982 | 379f6698 | Paul Brook | uint32_t offset = GUEST_BASE; |
983 | 379f6698 | Paul Brook | int i;
|
984 | 379f6698 | Paul Brook | int rot;
|
985 | 379f6698 | Paul Brook | |
986 | 379f6698 | Paul Brook | while (offset) {
|
987 | 379f6698 | Paul Brook | i = ctz32(offset) & ~1;
|
988 | 379f6698 | Paul Brook | rot = ((32 - i) << 7) & 0xf00; |
989 | 379f6698 | Paul Brook | |
990 | 379f6698 | Paul Brook | tcg_out_dat_imm(s, COND_AL, ARITH_ADD, 8, addr_reg,
|
991 | 379f6698 | Paul Brook | ((offset >> i) & 0xff) | rot);
|
992 | 379f6698 | Paul Brook | addr_reg = 8;
|
993 | 379f6698 | Paul Brook | offset &= ~(0xff << i);
|
994 | 379f6698 | Paul Brook | } |
995 | 379f6698 | Paul Brook | } |
996 | 811d4cf4 | balrog | switch (opc) {
|
997 | 811d4cf4 | balrog | case 0: |
998 | 811d4cf4 | balrog | tcg_out_ld8_12(s, COND_AL, data_reg, addr_reg, 0);
|
999 | 811d4cf4 | balrog | break;
|
1000 | 811d4cf4 | balrog | case 0 | 4: |
1001 | 811d4cf4 | balrog | tcg_out_ld8s_8(s, COND_AL, data_reg, addr_reg, 0);
|
1002 | 811d4cf4 | balrog | break;
|
1003 | 811d4cf4 | balrog | case 1: |
1004 | 811d4cf4 | balrog | tcg_out_ld16u_8(s, COND_AL, data_reg, addr_reg, 0);
|
1005 | 811d4cf4 | balrog | break;
|
1006 | 811d4cf4 | balrog | case 1 | 4: |
1007 | 811d4cf4 | balrog | tcg_out_ld16s_8(s, COND_AL, data_reg, addr_reg, 0);
|
1008 | 811d4cf4 | balrog | break;
|
1009 | 811d4cf4 | balrog | case 2: |
1010 | 811d4cf4 | balrog | default:
|
1011 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
|
1012 | 811d4cf4 | balrog | break;
|
1013 | 811d4cf4 | balrog | case 3: |
1014 | eae6ce52 | balrog | /* TODO: use block load -
|
1015 | eae6ce52 | balrog | * check that data_reg2 > data_reg or the other way */
|
1016 | 419bafa5 | aurel32 | if (data_reg == addr_reg) {
|
1017 | 419bafa5 | aurel32 | tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, 4);
|
1018 | 419bafa5 | aurel32 | tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
|
1019 | 419bafa5 | aurel32 | } else {
|
1020 | 419bafa5 | aurel32 | tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
|
1021 | 419bafa5 | aurel32 | tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, 4);
|
1022 | 419bafa5 | aurel32 | } |
1023 | 811d4cf4 | balrog | break;
|
1024 | 811d4cf4 | balrog | } |
1025 | 811d4cf4 | balrog | #endif
|
1026 | 811d4cf4 | balrog | } |
1027 | 811d4cf4 | balrog | |
1028 | 811d4cf4 | balrog | static inline void tcg_out_qemu_st(TCGContext *s, int cond, |
1029 | 811d4cf4 | balrog | const TCGArg *args, int opc) |
1030 | 811d4cf4 | balrog | { |
1031 | 811d4cf4 | balrog | int addr_reg, data_reg, data_reg2;
|
1032 | 811d4cf4 | balrog | #ifdef CONFIG_SOFTMMU
|
1033 | 811d4cf4 | balrog | int mem_index, s_bits;
|
1034 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
1035 | 811d4cf4 | balrog | int addr_reg2;
|
1036 | 811d4cf4 | balrog | # endif
|
1037 | 811d4cf4 | balrog | uint32_t *label_ptr; |
1038 | 811d4cf4 | balrog | #endif
|
1039 | 811d4cf4 | balrog | |
1040 | 811d4cf4 | balrog | data_reg = *args++; |
1041 | 811d4cf4 | balrog | if (opc == 3) |
1042 | 811d4cf4 | balrog | data_reg2 = *args++; |
1043 | 811d4cf4 | balrog | else
|
1044 | d89c682f | Stefan Weil | data_reg2 = 0; /* suppress warning */ |
1045 | 811d4cf4 | balrog | addr_reg = *args++; |
1046 | 811d4cf4 | balrog | #ifdef CONFIG_SOFTMMU
|
1047 | aef3a282 | balrog | # if TARGET_LONG_BITS == 64 |
1048 | aef3a282 | balrog | addr_reg2 = *args++; |
1049 | aef3a282 | balrog | # endif
|
1050 | 811d4cf4 | balrog | mem_index = *args; |
1051 | 811d4cf4 | balrog | s_bits = opc & 3;
|
1052 | 811d4cf4 | balrog | |
1053 | 91a3c1b0 | balrog | /* Should generate something like the following:
|
1054 | 3979144c | pbrook | * shr r8, addr_reg, #TARGET_PAGE_BITS
|
1055 | 91a3c1b0 | balrog | * and r0, r8, #(CPU_TLB_SIZE - 1) @ Assumption: CPU_TLB_BITS <= 8
|
1056 | 3979144c | pbrook | * add r0, env, r0 lsl #CPU_TLB_ENTRY_BITS
|
1057 | 91a3c1b0 | balrog | */
|
1058 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
1059 | 3979144c | pbrook | 8, 0, addr_reg, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); |
1060 | 811d4cf4 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_AND, |
1061 | 811d4cf4 | balrog | 0, 8, CPU_TLB_SIZE - 1); |
1062 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_ADD, |
1063 | 811d4cf4 | balrog | 0, TCG_AREG0, 0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS)); |
1064 | 91a3c1b0 | balrog | /* In the
|
1065 | 91a3c1b0 | balrog | * ldr r1 [r0, #(offsetof(CPUState, tlb_table[mem_index][0].addr_write))]
|
1066 | 91a3c1b0 | balrog | * below, the offset is likely to exceed 12 bits if mem_index != 0 and
|
1067 | 91a3c1b0 | balrog | * not exceed otherwise, so use an
|
1068 | 91a3c1b0 | balrog | * add r0, r0, #(mem_index * sizeof *CPUState.tlb_table)
|
1069 | 91a3c1b0 | balrog | * before.
|
1070 | 91a3c1b0 | balrog | */
|
1071 | 225b4376 | balrog | if (mem_index)
|
1072 | 225b4376 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_ADD, 0, 0, |
1073 | 225b4376 | balrog | (mem_index << (TLB_SHIFT & 1)) |
|
1074 | 225b4376 | balrog | ((16 - (TLB_SHIFT >> 1)) << 8)); |
1075 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 1, 0, |
1076 | 225b4376 | balrog | offsetof(CPUState, tlb_table[0][0].addr_write)); |
1077 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_CMP, |
1078 | 811d4cf4 | balrog | 0, 1, 8, SHIFT_IMM_LSL(TARGET_PAGE_BITS)); |
1079 | 3979144c | pbrook | /* Check alignment. */
|
1080 | 3979144c | pbrook | if (s_bits)
|
1081 | 3979144c | pbrook | tcg_out_dat_imm(s, COND_EQ, ARITH_TST, |
1082 | 3979144c | pbrook | 0, addr_reg, (1 << s_bits) - 1); |
1083 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
1084 | 811d4cf4 | balrog | /* XXX: possibly we could use a block data load or writeback in
|
1085 | 811d4cf4 | balrog | * the first access. */
|
1086 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_EQ, 1, 0, |
1087 | 225b4376 | balrog | offsetof(CPUState, tlb_table[0][0].addr_write) |
1088 | 811d4cf4 | balrog | + 4);
|
1089 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, |
1090 | 811d4cf4 | balrog | 0, 1, addr_reg2, SHIFT_IMM_LSL(0)); |
1091 | 811d4cf4 | balrog | # endif
|
1092 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_EQ, 1, 0, |
1093 | 225b4376 | balrog | offsetof(CPUState, tlb_table[0][0].addend)); |
1094 | 811d4cf4 | balrog | |
1095 | 811d4cf4 | balrog | switch (opc) {
|
1096 | 811d4cf4 | balrog | case 0: |
1097 | 811d4cf4 | balrog | tcg_out_st8_r(s, COND_EQ, data_reg, addr_reg, 1);
|
1098 | 811d4cf4 | balrog | break;
|
1099 | 811d4cf4 | balrog | case 0 | 4: |
1100 | 811d4cf4 | balrog | tcg_out_st8s_r(s, COND_EQ, data_reg, addr_reg, 1);
|
1101 | 811d4cf4 | balrog | break;
|
1102 | 811d4cf4 | balrog | case 1: |
1103 | 811d4cf4 | balrog | tcg_out_st16u_r(s, COND_EQ, data_reg, addr_reg, 1);
|
1104 | 811d4cf4 | balrog | break;
|
1105 | 811d4cf4 | balrog | case 1 | 4: |
1106 | 811d4cf4 | balrog | tcg_out_st16s_r(s, COND_EQ, data_reg, addr_reg, 1);
|
1107 | 811d4cf4 | balrog | break;
|
1108 | 811d4cf4 | balrog | case 2: |
1109 | 811d4cf4 | balrog | default:
|
1110 | 811d4cf4 | balrog | tcg_out_st32_r(s, COND_EQ, data_reg, addr_reg, 1);
|
1111 | 811d4cf4 | balrog | break;
|
1112 | 811d4cf4 | balrog | case 3: |
1113 | 3979144c | pbrook | tcg_out_st32_rwb(s, COND_EQ, data_reg, 1, addr_reg);
|
1114 | 811d4cf4 | balrog | tcg_out_st32_12(s, COND_EQ, data_reg2, 1, 4); |
1115 | 811d4cf4 | balrog | break;
|
1116 | 811d4cf4 | balrog | } |
1117 | 811d4cf4 | balrog | |
1118 | 811d4cf4 | balrog | label_ptr = (void *) s->code_ptr;
|
1119 | 811d4cf4 | balrog | tcg_out_b(s, COND_EQ, 8);
|
1120 | 811d4cf4 | balrog | |
1121 | 811d4cf4 | balrog | /* TODO: move this code to where the constants pool will be */
|
1122 | 811d4cf4 | balrog | if (addr_reg)
|
1123 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1124 | 811d4cf4 | balrog | 0, 0, addr_reg, SHIFT_IMM_LSL(0)); |
1125 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 32 |
1126 | 811d4cf4 | balrog | switch (opc) {
|
1127 | 811d4cf4 | balrog | case 0: |
1128 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_AND, 1, data_reg, 0xff); |
1129 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 2, 0, mem_index); |
1130 | 811d4cf4 | balrog | break;
|
1131 | 811d4cf4 | balrog | case 1: |
1132 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1133 | 811d4cf4 | balrog | 1, 0, data_reg, SHIFT_IMM_LSL(16)); |
1134 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1135 | 811d4cf4 | balrog | 1, 0, 1, SHIFT_IMM_LSR(16)); |
1136 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 2, 0, mem_index); |
1137 | 811d4cf4 | balrog | break;
|
1138 | 811d4cf4 | balrog | case 2: |
1139 | 811d4cf4 | balrog | if (data_reg != 1) |
1140 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1141 | 811d4cf4 | balrog | 1, 0, data_reg, SHIFT_IMM_LSL(0)); |
1142 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 2, 0, mem_index); |
1143 | 811d4cf4 | balrog | break;
|
1144 | 811d4cf4 | balrog | case 3: |
1145 | 811d4cf4 | balrog | if (data_reg != 1) |
1146 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1147 | 811d4cf4 | balrog | 1, 0, data_reg, SHIFT_IMM_LSL(0)); |
1148 | 811d4cf4 | balrog | if (data_reg2 != 2) |
1149 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1150 | 811d4cf4 | balrog | 2, 0, data_reg2, SHIFT_IMM_LSL(0)); |
1151 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 3, 0, mem_index); |
1152 | 811d4cf4 | balrog | break;
|
1153 | 811d4cf4 | balrog | } |
1154 | 811d4cf4 | balrog | # else
|
1155 | 811d4cf4 | balrog | if (addr_reg2 != 1) |
1156 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1157 | 811d4cf4 | balrog | 1, 0, addr_reg2, SHIFT_IMM_LSL(0)); |
1158 | 811d4cf4 | balrog | switch (opc) {
|
1159 | 811d4cf4 | balrog | case 0: |
1160 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_AND, 2, data_reg, 0xff); |
1161 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 3, 0, mem_index); |
1162 | 811d4cf4 | balrog | break;
|
1163 | 811d4cf4 | balrog | case 1: |
1164 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1165 | 811d4cf4 | balrog | 2, 0, data_reg, SHIFT_IMM_LSL(16)); |
1166 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1167 | 811d4cf4 | balrog | 2, 0, 2, SHIFT_IMM_LSR(16)); |
1168 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 3, 0, mem_index); |
1169 | 811d4cf4 | balrog | break;
|
1170 | 811d4cf4 | balrog | case 2: |
1171 | 811d4cf4 | balrog | if (data_reg != 2) |
1172 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1173 | 811d4cf4 | balrog | 2, 0, data_reg, SHIFT_IMM_LSL(0)); |
1174 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 3, 0, mem_index); |
1175 | 811d4cf4 | balrog | break;
|
1176 | 811d4cf4 | balrog | case 3: |
1177 | 91a3c1b0 | balrog | tcg_out_dat_imm(s, cond, ARITH_MOV, 8, 0, mem_index); |
1178 | 91a3c1b0 | balrog | tcg_out32(s, (cond << 28) | 0x052d8010); /* str r8, [sp, #-0x10]! */ |
1179 | 811d4cf4 | balrog | if (data_reg != 2) |
1180 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1181 | 811d4cf4 | balrog | 2, 0, data_reg, SHIFT_IMM_LSL(0)); |
1182 | 811d4cf4 | balrog | if (data_reg2 != 3) |
1183 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, |
1184 | 811d4cf4 | balrog | 3, 0, data_reg2, SHIFT_IMM_LSL(0)); |
1185 | 811d4cf4 | balrog | break;
|
1186 | 811d4cf4 | balrog | } |
1187 | 811d4cf4 | balrog | # endif
|
1188 | 811d4cf4 | balrog | |
1189 | 91a3c1b0 | balrog | # ifdef SAVE_LR
|
1190 | 91a3c1b0 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 8, 0, 14, SHIFT_IMM_LSL(0)); |
1191 | 91a3c1b0 | balrog | # endif
|
1192 | 91a3c1b0 | balrog | |
1193 | 204c1674 | balrog | tcg_out_bl(s, cond, (tcg_target_long) qemu_st_helpers[s_bits] - |
1194 | 811d4cf4 | balrog | (tcg_target_long) s->code_ptr); |
1195 | 811d4cf4 | balrog | # if TARGET_LONG_BITS == 64 |
1196 | 811d4cf4 | balrog | if (opc == 3) |
1197 | 811d4cf4 | balrog | tcg_out_dat_imm(s, cond, ARITH_ADD, 13, 13, 0x10); |
1198 | 811d4cf4 | balrog | # endif
|
1199 | 811d4cf4 | balrog | |
1200 | 811d4cf4 | balrog | # ifdef SAVE_LR
|
1201 | 811d4cf4 | balrog | tcg_out_dat_reg(s, cond, ARITH_MOV, 14, 0, 8, SHIFT_IMM_LSL(0)); |
1202 | 811d4cf4 | balrog | # endif
|
1203 | 811d4cf4 | balrog | |
1204 | 811d4cf4 | balrog | *label_ptr += ((void *) s->code_ptr - (void *) label_ptr - 8) >> 2; |
1205 | 379f6698 | Paul Brook | #else /* !CONFIG_SOFTMMU */ |
1206 | 379f6698 | Paul Brook | if (GUEST_BASE) {
|
1207 | 379f6698 | Paul Brook | uint32_t offset = GUEST_BASE; |
1208 | 379f6698 | Paul Brook | int i;
|
1209 | 379f6698 | Paul Brook | int rot;
|
1210 | 379f6698 | Paul Brook | |
1211 | 379f6698 | Paul Brook | while (offset) {
|
1212 | 379f6698 | Paul Brook | i = ctz32(offset) & ~1;
|
1213 | 379f6698 | Paul Brook | rot = ((32 - i) << 7) & 0xf00; |
1214 | 379f6698 | Paul Brook | |
1215 | 379f6698 | Paul Brook | tcg_out_dat_imm(s, COND_AL, ARITH_ADD, 8, addr_reg,
|
1216 | 379f6698 | Paul Brook | ((offset >> i) & 0xff) | rot);
|
1217 | 379f6698 | Paul Brook | addr_reg = 8;
|
1218 | 379f6698 | Paul Brook | offset &= ~(0xff << i);
|
1219 | 379f6698 | Paul Brook | } |
1220 | 379f6698 | Paul Brook | } |
1221 | 811d4cf4 | balrog | switch (opc) {
|
1222 | 811d4cf4 | balrog | case 0: |
1223 | 811d4cf4 | balrog | tcg_out_st8_12(s, COND_AL, data_reg, addr_reg, 0);
|
1224 | 811d4cf4 | balrog | break;
|
1225 | 811d4cf4 | balrog | case 0 | 4: |
1226 | 204c1674 | balrog | tcg_out_st8s_8(s, COND_AL, data_reg, addr_reg, 0);
|
1227 | 811d4cf4 | balrog | break;
|
1228 | 811d4cf4 | balrog | case 1: |
1229 | 811d4cf4 | balrog | tcg_out_st16u_8(s, COND_AL, data_reg, addr_reg, 0);
|
1230 | 811d4cf4 | balrog | break;
|
1231 | 811d4cf4 | balrog | case 1 | 4: |
1232 | 811d4cf4 | balrog | tcg_out_st16s_8(s, COND_AL, data_reg, addr_reg, 0);
|
1233 | 811d4cf4 | balrog | break;
|
1234 | 811d4cf4 | balrog | case 2: |
1235 | 811d4cf4 | balrog | default:
|
1236 | 811d4cf4 | balrog | tcg_out_st32_12(s, COND_AL, data_reg, addr_reg, 0);
|
1237 | 811d4cf4 | balrog | break;
|
1238 | 811d4cf4 | balrog | case 3: |
1239 | eae6ce52 | balrog | /* TODO: use block store -
|
1240 | eae6ce52 | balrog | * check that data_reg2 > data_reg or the other way */
|
1241 | 811d4cf4 | balrog | tcg_out_st32_12(s, COND_AL, data_reg, addr_reg, 0);
|
1242 | 811d4cf4 | balrog | tcg_out_st32_12(s, COND_AL, data_reg2, addr_reg, 4);
|
1243 | 811d4cf4 | balrog | break;
|
1244 | 811d4cf4 | balrog | } |
1245 | 811d4cf4 | balrog | #endif
|
1246 | 811d4cf4 | balrog | } |
1247 | 811d4cf4 | balrog | |
1248 | 811d4cf4 | balrog | static uint8_t *tb_ret_addr;
|
1249 | 811d4cf4 | balrog | |
1250 | 650bbb36 | balrog | static inline void tcg_out_op(TCGContext *s, int opc, |
1251 | 811d4cf4 | balrog | const TCGArg *args, const int *const_args) |
1252 | 811d4cf4 | balrog | { |
1253 | 811d4cf4 | balrog | int c;
|
1254 | 811d4cf4 | balrog | |
1255 | 811d4cf4 | balrog | switch (opc) {
|
1256 | 811d4cf4 | balrog | case INDEX_op_exit_tb:
|
1257 | 811d4cf4 | balrog | #ifdef SAVE_LR
|
1258 | 811d4cf4 | balrog | if (args[0] >> 8) |
1259 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, TCG_REG_R0, 15, 0); |
1260 | 811d4cf4 | balrog | else
|
1261 | 811d4cf4 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_MOV, TCG_REG_R0, 0, args[0]); |
1262 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, 15, 0, 14, SHIFT_IMM_LSL(0)); |
1263 | 811d4cf4 | balrog | if (args[0] >> 8) |
1264 | 811d4cf4 | balrog | tcg_out32(s, args[0]);
|
1265 | 811d4cf4 | balrog | #else
|
1266 | fe33867b | balrog | { |
1267 | fe33867b | balrog | uint8_t *ld_ptr = s->code_ptr; |
1268 | fe33867b | balrog | if (args[0] >> 8) |
1269 | fe33867b | balrog | tcg_out_ld32_12(s, COND_AL, 0, 15, 0); |
1270 | fe33867b | balrog | else
|
1271 | fe33867b | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_MOV, 0, 0, args[0]); |
1272 | fe33867b | balrog | tcg_out_goto(s, COND_AL, (tcg_target_ulong) tb_ret_addr); |
1273 | fe33867b | balrog | if (args[0] >> 8) { |
1274 | fe33867b | balrog | *ld_ptr = (uint8_t) (s->code_ptr - ld_ptr) - 8;
|
1275 | fe33867b | balrog | tcg_out32(s, args[0]);
|
1276 | fe33867b | balrog | } |
1277 | fe33867b | balrog | } |
1278 | 811d4cf4 | balrog | #endif
|
1279 | 811d4cf4 | balrog | break;
|
1280 | 811d4cf4 | balrog | case INDEX_op_goto_tb:
|
1281 | 811d4cf4 | balrog | if (s->tb_jmp_offset) {
|
1282 | 811d4cf4 | balrog | /* Direct jump method */
|
1283 | fe33867b | balrog | #if defined(USE_DIRECT_JUMP)
|
1284 | 811d4cf4 | balrog | s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
|
1285 | 811d4cf4 | balrog | tcg_out_b(s, COND_AL, 8);
|
1286 | 811d4cf4 | balrog | #else
|
1287 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, 15, -4); |
1288 | 811d4cf4 | balrog | s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
|
1289 | 811d4cf4 | balrog | tcg_out32(s, 0);
|
1290 | 811d4cf4 | balrog | #endif
|
1291 | 811d4cf4 | balrog | } else {
|
1292 | 811d4cf4 | balrog | /* Indirect jump method */
|
1293 | 811d4cf4 | balrog | #if 1 |
1294 | 811d4cf4 | balrog | c = (int) (s->tb_next + args[0]) - ((int) s->code_ptr + 8); |
1295 | 811d4cf4 | balrog | if (c > 0xfff || c < -0xfff) { |
1296 | 811d4cf4 | balrog | tcg_out_movi32(s, COND_AL, TCG_REG_R0, |
1297 | 811d4cf4 | balrog | (tcg_target_long) (s->tb_next + args[0]));
|
1298 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, TCG_REG_R0, 0); |
1299 | 811d4cf4 | balrog | } else
|
1300 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, 15, c); |
1301 | 811d4cf4 | balrog | #else
|
1302 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, TCG_REG_R0, 15, 0); |
1303 | 811d4cf4 | balrog | tcg_out_ld32_12(s, COND_AL, 15, TCG_REG_R0, 0); |
1304 | 811d4cf4 | balrog | tcg_out32(s, (tcg_target_long) (s->tb_next + args[0]));
|
1305 | 811d4cf4 | balrog | #endif
|
1306 | 811d4cf4 | balrog | } |
1307 | 811d4cf4 | balrog | s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
|
1308 | 811d4cf4 | balrog | break;
|
1309 | 811d4cf4 | balrog | case INDEX_op_call:
|
1310 | 811d4cf4 | balrog | if (const_args[0]) |
1311 | 811d4cf4 | balrog | tcg_out_call(s, COND_AL, args[0]);
|
1312 | 811d4cf4 | balrog | else
|
1313 | 811d4cf4 | balrog | tcg_out_callr(s, COND_AL, args[0]);
|
1314 | 811d4cf4 | balrog | break;
|
1315 | 811d4cf4 | balrog | case INDEX_op_jmp:
|
1316 | 811d4cf4 | balrog | if (const_args[0]) |
1317 | 811d4cf4 | balrog | tcg_out_goto(s, COND_AL, args[0]);
|
1318 | 811d4cf4 | balrog | else
|
1319 | 811d4cf4 | balrog | tcg_out_bx(s, COND_AL, args[0]);
|
1320 | 811d4cf4 | balrog | break;
|
1321 | 811d4cf4 | balrog | case INDEX_op_br:
|
1322 | 811d4cf4 | balrog | tcg_out_goto_label(s, COND_AL, args[0]);
|
1323 | 811d4cf4 | balrog | break;
|
1324 | 811d4cf4 | balrog | |
1325 | 811d4cf4 | balrog | case INDEX_op_ld8u_i32:
|
1326 | 811d4cf4 | balrog | tcg_out_ld8u(s, COND_AL, args[0], args[1], args[2]); |
1327 | 811d4cf4 | balrog | break;
|
1328 | 811d4cf4 | balrog | case INDEX_op_ld8s_i32:
|
1329 | 811d4cf4 | balrog | tcg_out_ld8s(s, COND_AL, args[0], args[1], args[2]); |
1330 | 811d4cf4 | balrog | break;
|
1331 | 811d4cf4 | balrog | case INDEX_op_ld16u_i32:
|
1332 | 811d4cf4 | balrog | tcg_out_ld16u(s, COND_AL, args[0], args[1], args[2]); |
1333 | 811d4cf4 | balrog | break;
|
1334 | 811d4cf4 | balrog | case INDEX_op_ld16s_i32:
|
1335 | 811d4cf4 | balrog | tcg_out_ld16s(s, COND_AL, args[0], args[1], args[2]); |
1336 | 811d4cf4 | balrog | break;
|
1337 | 811d4cf4 | balrog | case INDEX_op_ld_i32:
|
1338 | 811d4cf4 | balrog | tcg_out_ld32u(s, COND_AL, args[0], args[1], args[2]); |
1339 | 811d4cf4 | balrog | break;
|
1340 | 811d4cf4 | balrog | case INDEX_op_st8_i32:
|
1341 | 811d4cf4 | balrog | tcg_out_st8u(s, COND_AL, args[0], args[1], args[2]); |
1342 | 811d4cf4 | balrog | break;
|
1343 | 811d4cf4 | balrog | case INDEX_op_st16_i32:
|
1344 | 811d4cf4 | balrog | tcg_out_st16u(s, COND_AL, args[0], args[1], args[2]); |
1345 | 811d4cf4 | balrog | break;
|
1346 | 811d4cf4 | balrog | case INDEX_op_st_i32:
|
1347 | 811d4cf4 | balrog | tcg_out_st32(s, COND_AL, args[0], args[1], args[2]); |
1348 | 811d4cf4 | balrog | break;
|
1349 | 811d4cf4 | balrog | |
1350 | 811d4cf4 | balrog | case INDEX_op_mov_i32:
|
1351 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
1352 | 811d4cf4 | balrog | args[0], 0, args[1], SHIFT_IMM_LSL(0)); |
1353 | 811d4cf4 | balrog | break;
|
1354 | 811d4cf4 | balrog | case INDEX_op_movi_i32:
|
1355 | 811d4cf4 | balrog | tcg_out_movi32(s, COND_AL, args[0], args[1]); |
1356 | 811d4cf4 | balrog | break;
|
1357 | 811d4cf4 | balrog | case INDEX_op_add_i32:
|
1358 | 811d4cf4 | balrog | c = ARITH_ADD; |
1359 | 811d4cf4 | balrog | goto gen_arith;
|
1360 | 811d4cf4 | balrog | case INDEX_op_sub_i32:
|
1361 | 811d4cf4 | balrog | c = ARITH_SUB; |
1362 | 811d4cf4 | balrog | goto gen_arith;
|
1363 | 811d4cf4 | balrog | case INDEX_op_and_i32:
|
1364 | 811d4cf4 | balrog | c = ARITH_AND; |
1365 | 811d4cf4 | balrog | goto gen_arith;
|
1366 | 932234f6 | Aurelien Jarno | case INDEX_op_andc_i32:
|
1367 | 932234f6 | Aurelien Jarno | c = ARITH_BIC; |
1368 | 932234f6 | Aurelien Jarno | goto gen_arith;
|
1369 | 811d4cf4 | balrog | case INDEX_op_or_i32:
|
1370 | 811d4cf4 | balrog | c = ARITH_ORR; |
1371 | 811d4cf4 | balrog | goto gen_arith;
|
1372 | 811d4cf4 | balrog | case INDEX_op_xor_i32:
|
1373 | 811d4cf4 | balrog | c = ARITH_EOR; |
1374 | 811d4cf4 | balrog | /* Fall through. */
|
1375 | 811d4cf4 | balrog | gen_arith:
|
1376 | 94953e6d | Laurent Desnogues | if (const_args[2]) { |
1377 | 94953e6d | Laurent Desnogues | int rot;
|
1378 | 94953e6d | Laurent Desnogues | rot = encode_imm(args[2]);
|
1379 | cb4e581f | Laurent Desnogues | tcg_out_dat_imm(s, COND_AL, c, |
1380 | 94953e6d | Laurent Desnogues | args[0], args[1], rotl(args[2], rot) | (rot << 7)); |
1381 | 94953e6d | Laurent Desnogues | } else
|
1382 | cb4e581f | Laurent Desnogues | tcg_out_dat_reg(s, COND_AL, c, |
1383 | cb4e581f | Laurent Desnogues | args[0], args[1], args[2], SHIFT_IMM_LSL(0)); |
1384 | 811d4cf4 | balrog | break;
|
1385 | 811d4cf4 | balrog | case INDEX_op_add2_i32:
|
1386 | 811d4cf4 | balrog | tcg_out_dat_reg2(s, COND_AL, ARITH_ADD, ARITH_ADC, |
1387 | 811d4cf4 | balrog | args[0], args[1], args[2], args[3], |
1388 | 811d4cf4 | balrog | args[4], args[5], SHIFT_IMM_LSL(0)); |
1389 | 811d4cf4 | balrog | break;
|
1390 | 811d4cf4 | balrog | case INDEX_op_sub2_i32:
|
1391 | 811d4cf4 | balrog | tcg_out_dat_reg2(s, COND_AL, ARITH_SUB, ARITH_SBC, |
1392 | 811d4cf4 | balrog | args[0], args[1], args[2], args[3], |
1393 | 811d4cf4 | balrog | args[4], args[5], SHIFT_IMM_LSL(0)); |
1394 | 811d4cf4 | balrog | break;
|
1395 | 650bbb36 | balrog | case INDEX_op_neg_i32:
|
1396 | 650bbb36 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_RSB, args[0], args[1], 0); |
1397 | 650bbb36 | balrog | break;
|
1398 | f878d2d2 | Laurent Desnogues | case INDEX_op_not_i32:
|
1399 | f878d2d2 | Laurent Desnogues | tcg_out_dat_reg(s, COND_AL, |
1400 | f878d2d2 | Laurent Desnogues | ARITH_MVN, args[0], 0, args[1], SHIFT_IMM_LSL(0)); |
1401 | f878d2d2 | Laurent Desnogues | break;
|
1402 | 811d4cf4 | balrog | case INDEX_op_mul_i32:
|
1403 | 811d4cf4 | balrog | tcg_out_mul32(s, COND_AL, args[0], args[1], args[2]); |
1404 | 811d4cf4 | balrog | break;
|
1405 | 811d4cf4 | balrog | case INDEX_op_mulu2_i32:
|
1406 | 811d4cf4 | balrog | tcg_out_umull32(s, COND_AL, args[0], args[1], args[2], args[3]); |
1407 | 811d4cf4 | balrog | break;
|
1408 | 811d4cf4 | balrog | /* XXX: Perhaps args[2] & 0x1f is wrong */
|
1409 | 811d4cf4 | balrog | case INDEX_op_shl_i32:
|
1410 | 811d4cf4 | balrog | c = const_args[2] ?
|
1411 | 811d4cf4 | balrog | SHIFT_IMM_LSL(args[2] & 0x1f) : SHIFT_REG_LSL(args[2]); |
1412 | 811d4cf4 | balrog | goto gen_shift32;
|
1413 | 811d4cf4 | balrog | case INDEX_op_shr_i32:
|
1414 | 811d4cf4 | balrog | c = const_args[2] ? (args[2] & 0x1f) ? SHIFT_IMM_LSR(args[2] & 0x1f) : |
1415 | 811d4cf4 | balrog | SHIFT_IMM_LSL(0) : SHIFT_REG_LSR(args[2]); |
1416 | 811d4cf4 | balrog | goto gen_shift32;
|
1417 | 811d4cf4 | balrog | case INDEX_op_sar_i32:
|
1418 | 811d4cf4 | balrog | c = const_args[2] ? (args[2] & 0x1f) ? SHIFT_IMM_ASR(args[2] & 0x1f) : |
1419 | 811d4cf4 | balrog | SHIFT_IMM_LSL(0) : SHIFT_REG_ASR(args[2]); |
1420 | 811d4cf4 | balrog | /* Fall through. */
|
1421 | 811d4cf4 | balrog | gen_shift32:
|
1422 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, args[0], 0, args[1], c); |
1423 | 811d4cf4 | balrog | break;
|
1424 | 811d4cf4 | balrog | |
1425 | 811d4cf4 | balrog | case INDEX_op_brcond_i32:
|
1426 | 023e77f8 | Aurelien Jarno | if (const_args[1]) { |
1427 | 023e77f8 | Aurelien Jarno | int rot;
|
1428 | 023e77f8 | Aurelien Jarno | rot = encode_imm(args[1]);
|
1429 | 023e77f8 | Aurelien Jarno | tcg_out_dat_imm(s, COND_AL, ARITH_CMP, |
1430 | 023e77f8 | Aurelien Jarno | 0, args[0], rotl(args[1], rot) | (rot << 7)); |
1431 | 023e77f8 | Aurelien Jarno | } else {
|
1432 | 023e77f8 | Aurelien Jarno | tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0,
|
1433 | 023e77f8 | Aurelien Jarno | args[0], args[1], SHIFT_IMM_LSL(0)); |
1434 | 023e77f8 | Aurelien Jarno | } |
1435 | 811d4cf4 | balrog | tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[2]], args[3]); |
1436 | 811d4cf4 | balrog | break;
|
1437 | 811d4cf4 | balrog | case INDEX_op_brcond2_i32:
|
1438 | 811d4cf4 | balrog | /* The resulting conditions are:
|
1439 | 811d4cf4 | balrog | * TCG_COND_EQ --> a0 == a2 && a1 == a3,
|
1440 | 811d4cf4 | balrog | * TCG_COND_NE --> (a0 != a2 && a1 == a3) || a1 != a3,
|
1441 | 811d4cf4 | balrog | * TCG_COND_LT(U) --> (a0 < a2 && a1 == a3) || a1 < a3,
|
1442 | 811d4cf4 | balrog | * TCG_COND_GE(U) --> (a0 >= a2 && a1 == a3) || (a1 >= a3 && a1 != a3),
|
1443 | 811d4cf4 | balrog | * TCG_COND_LE(U) --> (a0 <= a2 && a1 == a3) || (a1 <= a3 && a1 != a3),
|
1444 | 811d4cf4 | balrog | * TCG_COND_GT(U) --> (a0 > a2 && a1 == a3) || a1 > a3,
|
1445 | 811d4cf4 | balrog | */
|
1446 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0,
|
1447 | 811d4cf4 | balrog | args[1], args[3], SHIFT_IMM_LSL(0)); |
1448 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,
|
1449 | 811d4cf4 | balrog | args[0], args[2], SHIFT_IMM_LSL(0)); |
1450 | 811d4cf4 | balrog | tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[4]], args[5]); |
1451 | 811d4cf4 | balrog | break;
|
1452 | f72a6cd7 | Aurelien Jarno | case INDEX_op_setcond_i32:
|
1453 | 023e77f8 | Aurelien Jarno | if (const_args[2]) { |
1454 | 023e77f8 | Aurelien Jarno | int rot;
|
1455 | 023e77f8 | Aurelien Jarno | rot = encode_imm(args[2]);
|
1456 | 023e77f8 | Aurelien Jarno | tcg_out_dat_imm(s, COND_AL, ARITH_CMP, |
1457 | 023e77f8 | Aurelien Jarno | 0, args[1], rotl(args[2], rot) | (rot << 7)); |
1458 | 023e77f8 | Aurelien Jarno | } else {
|
1459 | 023e77f8 | Aurelien Jarno | tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0,
|
1460 | 023e77f8 | Aurelien Jarno | args[1], args[2], SHIFT_IMM_LSL(0)); |
1461 | 023e77f8 | Aurelien Jarno | } |
1462 | f72a6cd7 | Aurelien Jarno | tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[3]],
|
1463 | f72a6cd7 | Aurelien Jarno | ARITH_MOV, args[0], 0, 1); |
1464 | f72a6cd7 | Aurelien Jarno | tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[3])],
|
1465 | f72a6cd7 | Aurelien Jarno | ARITH_MOV, args[0], 0, 0); |
1466 | f72a6cd7 | Aurelien Jarno | break;
|
1467 | e0404769 | Aurelien Jarno | case INDEX_op_setcond2_i32:
|
1468 | e0404769 | Aurelien Jarno | /* See brcond2_i32 comment */
|
1469 | e0404769 | Aurelien Jarno | tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0,
|
1470 | e0404769 | Aurelien Jarno | args[2], args[4], SHIFT_IMM_LSL(0)); |
1471 | e0404769 | Aurelien Jarno | tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,
|
1472 | e0404769 | Aurelien Jarno | args[1], args[3], SHIFT_IMM_LSL(0)); |
1473 | e0404769 | Aurelien Jarno | tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[5]],
|
1474 | e0404769 | Aurelien Jarno | ARITH_MOV, args[0], 0, 1); |
1475 | e0404769 | Aurelien Jarno | tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[5])],
|
1476 | e0404769 | Aurelien Jarno | ARITH_MOV, args[0], 0, 0); |
1477 | b525f0a9 | Andrzej Zaborowski | break;
|
1478 | 811d4cf4 | balrog | |
1479 | 811d4cf4 | balrog | case INDEX_op_qemu_ld8u:
|
1480 | 811d4cf4 | balrog | tcg_out_qemu_ld(s, COND_AL, args, 0);
|
1481 | 811d4cf4 | balrog | break;
|
1482 | 811d4cf4 | balrog | case INDEX_op_qemu_ld8s:
|
1483 | 811d4cf4 | balrog | tcg_out_qemu_ld(s, COND_AL, args, 0 | 4); |
1484 | 811d4cf4 | balrog | break;
|
1485 | 811d4cf4 | balrog | case INDEX_op_qemu_ld16u:
|
1486 | 811d4cf4 | balrog | tcg_out_qemu_ld(s, COND_AL, args, 1);
|
1487 | 811d4cf4 | balrog | break;
|
1488 | 811d4cf4 | balrog | case INDEX_op_qemu_ld16s:
|
1489 | 811d4cf4 | balrog | tcg_out_qemu_ld(s, COND_AL, args, 1 | 4); |
1490 | 811d4cf4 | balrog | break;
|
1491 | 811d4cf4 | balrog | case INDEX_op_qemu_ld32u:
|
1492 | 811d4cf4 | balrog | tcg_out_qemu_ld(s, COND_AL, args, 2);
|
1493 | 811d4cf4 | balrog | break;
|
1494 | 811d4cf4 | balrog | case INDEX_op_qemu_ld64:
|
1495 | 811d4cf4 | balrog | tcg_out_qemu_ld(s, COND_AL, args, 3);
|
1496 | 811d4cf4 | balrog | break;
|
1497 | 650bbb36 | balrog | |
1498 | 811d4cf4 | balrog | case INDEX_op_qemu_st8:
|
1499 | 811d4cf4 | balrog | tcg_out_qemu_st(s, COND_AL, args, 0);
|
1500 | 811d4cf4 | balrog | break;
|
1501 | 811d4cf4 | balrog | case INDEX_op_qemu_st16:
|
1502 | 811d4cf4 | balrog | tcg_out_qemu_st(s, COND_AL, args, 1);
|
1503 | 811d4cf4 | balrog | break;
|
1504 | 811d4cf4 | balrog | case INDEX_op_qemu_st32:
|
1505 | 811d4cf4 | balrog | tcg_out_qemu_st(s, COND_AL, args, 2);
|
1506 | 811d4cf4 | balrog | break;
|
1507 | 811d4cf4 | balrog | case INDEX_op_qemu_st64:
|
1508 | 811d4cf4 | balrog | tcg_out_qemu_st(s, COND_AL, args, 3);
|
1509 | 811d4cf4 | balrog | break;
|
1510 | 811d4cf4 | balrog | |
1511 | 811d4cf4 | balrog | case INDEX_op_ext8s_i32:
|
1512 | 7990496d | Laurent Desnogues | #ifdef __ARM_ARCH_7A__
|
1513 | 7990496d | Laurent Desnogues | /* sxtb */
|
1514 | 7990496d | Laurent Desnogues | tcg_out32(s, 0xe6af0070 | (args[0] << 12) | args[1]); |
1515 | 7990496d | Laurent Desnogues | #else
|
1516 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
1517 | 811d4cf4 | balrog | args[0], 0, args[1], SHIFT_IMM_LSL(24)); |
1518 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
1519 | 811d4cf4 | balrog | args[0], 0, args[0], SHIFT_IMM_ASR(24)); |
1520 | 7990496d | Laurent Desnogues | #endif
|
1521 | 811d4cf4 | balrog | break;
|
1522 | 811d4cf4 | balrog | case INDEX_op_ext16s_i32:
|
1523 | 7990496d | Laurent Desnogues | #ifdef __ARM_ARCH_7A__
|
1524 | 7990496d | Laurent Desnogues | /* sxth */
|
1525 | 7990496d | Laurent Desnogues | tcg_out32(s, 0xe6bf0070 | (args[0] << 12) | args[1]); |
1526 | 7990496d | Laurent Desnogues | #else
|
1527 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
1528 | 811d4cf4 | balrog | args[0], 0, args[1], SHIFT_IMM_LSL(16)); |
1529 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, |
1530 | 811d4cf4 | balrog | args[0], 0, args[0], SHIFT_IMM_ASR(16)); |
1531 | 7990496d | Laurent Desnogues | #endif
|
1532 | 811d4cf4 | balrog | break;
|
1533 | 811d4cf4 | balrog | |
1534 | 811d4cf4 | balrog | default:
|
1535 | 811d4cf4 | balrog | tcg_abort(); |
1536 | 811d4cf4 | balrog | } |
1537 | 811d4cf4 | balrog | } |
1538 | 811d4cf4 | balrog | |
1539 | 811d4cf4 | balrog | static const TCGTargetOpDef arm_op_defs[] = { |
1540 | 811d4cf4 | balrog | { INDEX_op_exit_tb, { } }, |
1541 | 811d4cf4 | balrog | { INDEX_op_goto_tb, { } }, |
1542 | 811d4cf4 | balrog | { INDEX_op_call, { "ri" } },
|
1543 | 811d4cf4 | balrog | { INDEX_op_jmp, { "ri" } },
|
1544 | 811d4cf4 | balrog | { INDEX_op_br, { } }, |
1545 | 811d4cf4 | balrog | |
1546 | 811d4cf4 | balrog | { INDEX_op_mov_i32, { "r", "r" } }, |
1547 | 811d4cf4 | balrog | { INDEX_op_movi_i32, { "r" } },
|
1548 | 811d4cf4 | balrog | |
1549 | 811d4cf4 | balrog | { INDEX_op_ld8u_i32, { "r", "r" } }, |
1550 | 811d4cf4 | balrog | { INDEX_op_ld8s_i32, { "r", "r" } }, |
1551 | 811d4cf4 | balrog | { INDEX_op_ld16u_i32, { "r", "r" } }, |
1552 | 811d4cf4 | balrog | { INDEX_op_ld16s_i32, { "r", "r" } }, |
1553 | 811d4cf4 | balrog | { INDEX_op_ld_i32, { "r", "r" } }, |
1554 | 811d4cf4 | balrog | { INDEX_op_st8_i32, { "r", "r" } }, |
1555 | 811d4cf4 | balrog | { INDEX_op_st16_i32, { "r", "r" } }, |
1556 | 811d4cf4 | balrog | { INDEX_op_st_i32, { "r", "r" } }, |
1557 | 811d4cf4 | balrog | |
1558 | 811d4cf4 | balrog | /* TODO: "r", "r", "ri" */
|
1559 | cb4e581f | Laurent Desnogues | { INDEX_op_add_i32, { "r", "r", "rI" } }, |
1560 | cb4e581f | Laurent Desnogues | { INDEX_op_sub_i32, { "r", "r", "rI" } }, |
1561 | 811d4cf4 | balrog | { INDEX_op_mul_i32, { "r", "r", "r" } }, |
1562 | 811d4cf4 | balrog | { INDEX_op_mulu2_i32, { "r", "r", "r", "r" } }, |
1563 | cb4e581f | Laurent Desnogues | { INDEX_op_and_i32, { "r", "r", "rI" } }, |
1564 | 932234f6 | Aurelien Jarno | { INDEX_op_andc_i32, { "r", "r", "rI" } }, |
1565 | cb4e581f | Laurent Desnogues | { INDEX_op_or_i32, { "r", "r", "rI" } }, |
1566 | cb4e581f | Laurent Desnogues | { INDEX_op_xor_i32, { "r", "r", "rI" } }, |
1567 | 650bbb36 | balrog | { INDEX_op_neg_i32, { "r", "r" } }, |
1568 | f878d2d2 | Laurent Desnogues | { INDEX_op_not_i32, { "r", "r" } }, |
1569 | 811d4cf4 | balrog | |
1570 | 811d4cf4 | balrog | { INDEX_op_shl_i32, { "r", "r", "ri" } }, |
1571 | 811d4cf4 | balrog | { INDEX_op_shr_i32, { "r", "r", "ri" } }, |
1572 | 811d4cf4 | balrog | { INDEX_op_sar_i32, { "r", "r", "ri" } }, |
1573 | 811d4cf4 | balrog | |
1574 | 023e77f8 | Aurelien Jarno | { INDEX_op_brcond_i32, { "r", "rI" } }, |
1575 | 023e77f8 | Aurelien Jarno | { INDEX_op_setcond_i32, { "r", "r", "rI" } }, |
1576 | 811d4cf4 | balrog | |
1577 | 811d4cf4 | balrog | /* TODO: "r", "r", "r", "r", "ri", "ri" */
|
1578 | 811d4cf4 | balrog | { INDEX_op_add2_i32, { "r", "r", "r", "r", "r", "r" } }, |
1579 | 811d4cf4 | balrog | { INDEX_op_sub2_i32, { "r", "r", "r", "r", "r", "r" } }, |
1580 | 811d4cf4 | balrog | { INDEX_op_brcond2_i32, { "r", "r", "r", "r" } }, |
1581 | e0404769 | Aurelien Jarno | { INDEX_op_setcond2_i32, { "r", "r", "r", "r", "r" } }, |
1582 | 811d4cf4 | balrog | |
1583 | 26c5d372 | Aurelien Jarno | #if TARGET_LONG_BITS == 32 |
1584 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_ld8u, { "r", "x" } }, |
1585 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_ld8s, { "r", "x" } }, |
1586 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_ld16u, { "r", "x" } }, |
1587 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_ld16s, { "r", "x" } }, |
1588 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_ld32u, { "r", "x" } }, |
1589 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_ld64, { "d", "r", "x" } }, |
1590 | 26c5d372 | Aurelien Jarno | |
1591 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_st8, { "x", "x" } }, |
1592 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_st16, { "x", "x" } }, |
1593 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_st32, { "x", "x" } }, |
1594 | 26c5d372 | Aurelien Jarno | { INDEX_op_qemu_st64, { "x", "D", "x" } }, |
1595 | 26c5d372 | Aurelien Jarno | #else
|
1596 | 811d4cf4 | balrog | { INDEX_op_qemu_ld8u, { "r", "x", "X" } }, |
1597 | 811d4cf4 | balrog | { INDEX_op_qemu_ld8s, { "r", "x", "X" } }, |
1598 | 811d4cf4 | balrog | { INDEX_op_qemu_ld16u, { "r", "x", "X" } }, |
1599 | 811d4cf4 | balrog | { INDEX_op_qemu_ld16s, { "r", "x", "X" } }, |
1600 | 811d4cf4 | balrog | { INDEX_op_qemu_ld32u, { "r", "x", "X" } }, |
1601 | d0660ed4 | balrog | { INDEX_op_qemu_ld64, { "d", "r", "x", "X" } }, |
1602 | 811d4cf4 | balrog | |
1603 | 3979144c | pbrook | { INDEX_op_qemu_st8, { "x", "x", "X" } }, |
1604 | 3979144c | pbrook | { INDEX_op_qemu_st16, { "x", "x", "X" } }, |
1605 | 3979144c | pbrook | { INDEX_op_qemu_st32, { "x", "x", "X" } }, |
1606 | 3979144c | pbrook | { INDEX_op_qemu_st64, { "x", "D", "x", "X" } }, |
1607 | 26c5d372 | Aurelien Jarno | #endif
|
1608 | 811d4cf4 | balrog | |
1609 | 811d4cf4 | balrog | { INDEX_op_ext8s_i32, { "r", "r" } }, |
1610 | 811d4cf4 | balrog | { INDEX_op_ext16s_i32, { "r", "r" } }, |
1611 | 811d4cf4 | balrog | |
1612 | 811d4cf4 | balrog | { -1 },
|
1613 | 811d4cf4 | balrog | }; |
1614 | 811d4cf4 | balrog | |
1615 | 811d4cf4 | balrog | void tcg_target_init(TCGContext *s)
|
1616 | 811d4cf4 | balrog | { |
1617 | 20cb400d | Paul Brook | #if !defined(CONFIG_USER_ONLY)
|
1618 | 811d4cf4 | balrog | /* fail safe */
|
1619 | 811d4cf4 | balrog | if ((1 << CPU_TLB_ENTRY_BITS) != sizeof(CPUTLBEntry)) |
1620 | 811d4cf4 | balrog | tcg_abort(); |
1621 | 20cb400d | Paul Brook | #endif
|
1622 | 811d4cf4 | balrog | |
1623 | 811d4cf4 | balrog | tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0,
|
1624 | 811d4cf4 | balrog | ((2 << TCG_REG_R14) - 1) & ~(1 << TCG_REG_R8)); |
1625 | 811d4cf4 | balrog | tcg_regset_set32(tcg_target_call_clobber_regs, 0,
|
1626 | 811d4cf4 | balrog | ((2 << TCG_REG_R3) - 1) | |
1627 | 811d4cf4 | balrog | (1 << TCG_REG_R12) | (1 << TCG_REG_R14)); |
1628 | 811d4cf4 | balrog | |
1629 | 811d4cf4 | balrog | tcg_regset_clear(s->reserved_regs); |
1630 | 811d4cf4 | balrog | #ifdef SAVE_LR
|
1631 | 811d4cf4 | balrog | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R14); |
1632 | 811d4cf4 | balrog | #endif
|
1633 | 811d4cf4 | balrog | tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK); |
1634 | 811d4cf4 | balrog | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R8); |
1635 | 811d4cf4 | balrog | |
1636 | 811d4cf4 | balrog | tcg_add_target_add_op_defs(arm_op_defs); |
1637 | 811d4cf4 | balrog | } |
1638 | 811d4cf4 | balrog | |
1639 | 811d4cf4 | balrog | static inline void tcg_out_ld(TCGContext *s, TCGType type, int arg, |
1640 | 811d4cf4 | balrog | int arg1, tcg_target_long arg2)
|
1641 | 811d4cf4 | balrog | { |
1642 | 811d4cf4 | balrog | tcg_out_ld32u(s, COND_AL, arg, arg1, arg2); |
1643 | 811d4cf4 | balrog | } |
1644 | 811d4cf4 | balrog | |
1645 | 811d4cf4 | balrog | static inline void tcg_out_st(TCGContext *s, TCGType type, int arg, |
1646 | 811d4cf4 | balrog | int arg1, tcg_target_long arg2)
|
1647 | 811d4cf4 | balrog | { |
1648 | 811d4cf4 | balrog | tcg_out_st32(s, COND_AL, arg, arg1, arg2); |
1649 | 811d4cf4 | balrog | } |
1650 | 811d4cf4 | balrog | |
1651 | 2d69f359 | Paul Brook | static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val) |
1652 | 811d4cf4 | balrog | { |
1653 | 811d4cf4 | balrog | if (val > 0) |
1654 | 811d4cf4 | balrog | if (val < 0x100) |
1655 | 811d4cf4 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_ADD, reg, reg, val); |
1656 | 811d4cf4 | balrog | else
|
1657 | 811d4cf4 | balrog | tcg_abort(); |
1658 | 811d4cf4 | balrog | else if (val < 0) { |
1659 | 811d4cf4 | balrog | if (val > -0x100) |
1660 | 811d4cf4 | balrog | tcg_out_dat_imm(s, COND_AL, ARITH_SUB, reg, reg, -val); |
1661 | 811d4cf4 | balrog | else
|
1662 | 811d4cf4 | balrog | tcg_abort(); |
1663 | 811d4cf4 | balrog | } |
1664 | 811d4cf4 | balrog | } |
1665 | 811d4cf4 | balrog | |
1666 | 811d4cf4 | balrog | static inline void tcg_out_mov(TCGContext *s, int ret, int arg) |
1667 | 811d4cf4 | balrog | { |
1668 | 811d4cf4 | balrog | tcg_out_dat_reg(s, COND_AL, ARITH_MOV, ret, 0, arg, SHIFT_IMM_LSL(0)); |
1669 | 811d4cf4 | balrog | } |
1670 | 811d4cf4 | balrog | |
1671 | 811d4cf4 | balrog | static inline void tcg_out_movi(TCGContext *s, TCGType type, |
1672 | 811d4cf4 | balrog | int ret, tcg_target_long arg)
|
1673 | 811d4cf4 | balrog | { |
1674 | 811d4cf4 | balrog | tcg_out_movi32(s, COND_AL, ret, arg); |
1675 | 811d4cf4 | balrog | } |
1676 | 811d4cf4 | balrog | |
1677 | 811d4cf4 | balrog | void tcg_target_qemu_prologue(TCGContext *s)
|
1678 | 811d4cf4 | balrog | { |
1679 | 4e17eae9 | Aurelien Jarno | /* Theoretically there is no need to save r12, but an
|
1680 | 4e17eae9 | Aurelien Jarno | even number of registers to be saved as per EABI */
|
1681 | 4e17eae9 | Aurelien Jarno | |
1682 | 4e17eae9 | Aurelien Jarno | /* stmdb sp!, { r4 - r12, lr } */
|
1683 | 4e17eae9 | Aurelien Jarno | tcg_out32(s, (COND_AL << 28) | 0x092d5ff0); |
1684 | 811d4cf4 | balrog | |
1685 | 811d4cf4 | balrog | tcg_out_bx(s, COND_AL, TCG_REG_R0); |
1686 | 811d4cf4 | balrog | tb_ret_addr = s->code_ptr; |
1687 | 811d4cf4 | balrog | |
1688 | 4e17eae9 | Aurelien Jarno | /* ldmia sp!, { r4 - r12, pc } */
|
1689 | 4e17eae9 | Aurelien Jarno | tcg_out32(s, (COND_AL << 28) | 0x08bd9ff0); |
1690 | 811d4cf4 | balrog | } |