4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2005-2007 CodeSourcery
6 * Copyright (c) 2007 OpenedHand, Ltd.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
37 #define ENABLE_ARCH_4T arm_feature(env, ARM_FEATURE_V4T)
38 #define ENABLE_ARCH_5 arm_feature(env, ARM_FEATURE_V5)
39 /* currently all emulated v5 cores are also v5TE, so don't bother */
40 #define ENABLE_ARCH_5TE arm_feature(env, ARM_FEATURE_V5)
41 #define ENABLE_ARCH_5J 0
42 #define ENABLE_ARCH_6 arm_feature(env, ARM_FEATURE_V6)
43 #define ENABLE_ARCH_6K arm_feature(env, ARM_FEATURE_V6K)
44 #define ENABLE_ARCH_6T2 arm_feature(env, ARM_FEATURE_THUMB2)
45 #define ENABLE_ARCH_7 arm_feature(env, ARM_FEATURE_V7)
47 #define ARCH(x) do { if (!ENABLE_ARCH_##x) goto illegal_op; } while(0)
49 /* internal defines */
50 typedef struct DisasContext
{
53 /* Nonzero if this instruction has been conditionally skipped. */
55 /* The label that will be jumped to when the instruction is skipped. */
57 /* Thumb-2 condtional execution bits. */
60 struct TranslationBlock
*tb
;
61 int singlestep_enabled
;
63 #if !defined(CONFIG_USER_ONLY)
71 static uint32_t gen_opc_condexec_bits
[OPC_BUF_SIZE
];
73 #if defined(CONFIG_USER_ONLY)
76 #define IS_USER(s) (s->user)
79 /* These instructions trap after executing, so defer them until after the
80 conditional executions state has been updated. */
84 static TCGv_ptr cpu_env
;
85 /* We reuse the same 64-bit temporaries for efficiency. */
86 static TCGv_i64 cpu_V0
, cpu_V1
, cpu_M0
;
87 static TCGv_i32 cpu_R
[16];
88 static TCGv_i32 cpu_exclusive_addr
;
89 static TCGv_i32 cpu_exclusive_val
;
90 static TCGv_i32 cpu_exclusive_high
;
91 #ifdef CONFIG_USER_ONLY
92 static TCGv_i32 cpu_exclusive_test
;
93 static TCGv_i32 cpu_exclusive_info
;
96 /* FIXME: These should be removed. */
97 static TCGv cpu_F0s
, cpu_F1s
;
98 static TCGv_i64 cpu_F0d
, cpu_F1d
;
100 #include "gen-icount.h"
102 static const char *regnames
[] =
103 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
104 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" };
106 /* initialize TCG globals. */
107 void arm_translate_init(void)
111 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
113 for (i
= 0; i
< 16; i
++) {
114 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
115 offsetof(CPUState
, regs
[i
]),
118 cpu_exclusive_addr
= tcg_global_mem_new_i32(TCG_AREG0
,
119 offsetof(CPUState
, exclusive_addr
), "exclusive_addr");
120 cpu_exclusive_val
= tcg_global_mem_new_i32(TCG_AREG0
,
121 offsetof(CPUState
, exclusive_val
), "exclusive_val");
122 cpu_exclusive_high
= tcg_global_mem_new_i32(TCG_AREG0
,
123 offsetof(CPUState
, exclusive_high
), "exclusive_high");
124 #ifdef CONFIG_USER_ONLY
125 cpu_exclusive_test
= tcg_global_mem_new_i32(TCG_AREG0
,
126 offsetof(CPUState
, exclusive_test
), "exclusive_test");
127 cpu_exclusive_info
= tcg_global_mem_new_i32(TCG_AREG0
,
128 offsetof(CPUState
, exclusive_info
), "exclusive_info");
135 static inline TCGv
load_cpu_offset(int offset
)
137 TCGv tmp
= tcg_temp_new_i32();
138 tcg_gen_ld_i32(tmp
, cpu_env
, offset
);
142 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUState, name))
144 static inline void store_cpu_offset(TCGv var
, int offset
)
146 tcg_gen_st_i32(var
, cpu_env
, offset
);
147 tcg_temp_free_i32(var
);
150 #define store_cpu_field(var, name) \
151 store_cpu_offset(var, offsetof(CPUState, name))
153 /* Set a variable to the value of a CPU register. */
154 static void load_reg_var(DisasContext
*s
, TCGv var
, int reg
)
158 /* normaly, since we updated PC, we need only to add one insn */
160 addr
= (long)s
->pc
+ 2;
162 addr
= (long)s
->pc
+ 4;
163 tcg_gen_movi_i32(var
, addr
);
165 tcg_gen_mov_i32(var
, cpu_R
[reg
]);
169 /* Create a new temporary and set it to the value of a CPU register. */
170 static inline TCGv
load_reg(DisasContext
*s
, int reg
)
172 TCGv tmp
= tcg_temp_new_i32();
173 load_reg_var(s
, tmp
, reg
);
177 /* Set a CPU register. The source must be a temporary and will be
179 static void store_reg(DisasContext
*s
, int reg
, TCGv var
)
182 tcg_gen_andi_i32(var
, var
, ~1);
183 s
->is_jmp
= DISAS_JUMP
;
185 tcg_gen_mov_i32(cpu_R
[reg
], var
);
186 tcg_temp_free_i32(var
);
189 /* Value extensions. */
190 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
191 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
192 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
193 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
195 #define gen_sxtb16(var) gen_helper_sxtb16(var, var)
196 #define gen_uxtb16(var) gen_helper_uxtb16(var, var)
199 static inline void gen_set_cpsr(TCGv var
, uint32_t mask
)
201 TCGv tmp_mask
= tcg_const_i32(mask
);
202 gen_helper_cpsr_write(var
, tmp_mask
);
203 tcg_temp_free_i32(tmp_mask
);
205 /* Set NZCV flags from the high 4 bits of var. */
206 #define gen_set_nzcv(var) gen_set_cpsr(var, CPSR_NZCV)
208 static void gen_exception(int excp
)
210 TCGv tmp
= tcg_temp_new_i32();
211 tcg_gen_movi_i32(tmp
, excp
);
212 gen_helper_exception(tmp
);
213 tcg_temp_free_i32(tmp
);
216 static void gen_smul_dual(TCGv a
, TCGv b
)
218 TCGv tmp1
= tcg_temp_new_i32();
219 TCGv tmp2
= tcg_temp_new_i32();
220 tcg_gen_ext16s_i32(tmp1
, a
);
221 tcg_gen_ext16s_i32(tmp2
, b
);
222 tcg_gen_mul_i32(tmp1
, tmp1
, tmp2
);
223 tcg_temp_free_i32(tmp2
);
224 tcg_gen_sari_i32(a
, a
, 16);
225 tcg_gen_sari_i32(b
, b
, 16);
226 tcg_gen_mul_i32(b
, b
, a
);
227 tcg_gen_mov_i32(a
, tmp1
);
228 tcg_temp_free_i32(tmp1
);
231 /* Byteswap each halfword. */
232 static void gen_rev16(TCGv var
)
234 TCGv tmp
= tcg_temp_new_i32();
235 tcg_gen_shri_i32(tmp
, var
, 8);
236 tcg_gen_andi_i32(tmp
, tmp
, 0x00ff00ff);
237 tcg_gen_shli_i32(var
, var
, 8);
238 tcg_gen_andi_i32(var
, var
, 0xff00ff00);
239 tcg_gen_or_i32(var
, var
, tmp
);
240 tcg_temp_free_i32(tmp
);
243 /* Byteswap low halfword and sign extend. */
244 static void gen_revsh(TCGv var
)
246 tcg_gen_ext16u_i32(var
, var
);
247 tcg_gen_bswap16_i32(var
, var
);
248 tcg_gen_ext16s_i32(var
, var
);
251 /* Unsigned bitfield extract. */
252 static void gen_ubfx(TCGv var
, int shift
, uint32_t mask
)
255 tcg_gen_shri_i32(var
, var
, shift
);
256 tcg_gen_andi_i32(var
, var
, mask
);
259 /* Signed bitfield extract. */
260 static void gen_sbfx(TCGv var
, int shift
, int width
)
265 tcg_gen_sari_i32(var
, var
, shift
);
266 if (shift
+ width
< 32) {
267 signbit
= 1u << (width
- 1);
268 tcg_gen_andi_i32(var
, var
, (1u << width
) - 1);
269 tcg_gen_xori_i32(var
, var
, signbit
);
270 tcg_gen_subi_i32(var
, var
, signbit
);
274 /* Bitfield insertion. Insert val into base. Clobbers base and val. */
275 static void gen_bfi(TCGv dest
, TCGv base
, TCGv val
, int shift
, uint32_t mask
)
277 tcg_gen_andi_i32(val
, val
, mask
);
278 tcg_gen_shli_i32(val
, val
, shift
);
279 tcg_gen_andi_i32(base
, base
, ~(mask
<< shift
));
280 tcg_gen_or_i32(dest
, base
, val
);
283 /* Return (b << 32) + a. Mark inputs as dead */
284 static TCGv_i64
gen_addq_msw(TCGv_i64 a
, TCGv b
)
286 TCGv_i64 tmp64
= tcg_temp_new_i64();
288 tcg_gen_extu_i32_i64(tmp64
, b
);
289 tcg_temp_free_i32(b
);
290 tcg_gen_shli_i64(tmp64
, tmp64
, 32);
291 tcg_gen_add_i64(a
, tmp64
, a
);
293 tcg_temp_free_i64(tmp64
);
297 /* Return (b << 32) - a. Mark inputs as dead. */
298 static TCGv_i64
gen_subq_msw(TCGv_i64 a
, TCGv b
)
300 TCGv_i64 tmp64
= tcg_temp_new_i64();
302 tcg_gen_extu_i32_i64(tmp64
, b
);
303 tcg_temp_free_i32(b
);
304 tcg_gen_shli_i64(tmp64
, tmp64
, 32);
305 tcg_gen_sub_i64(a
, tmp64
, a
);
307 tcg_temp_free_i64(tmp64
);
311 /* FIXME: Most targets have native widening multiplication.
312 It would be good to use that instead of a full wide multiply. */
313 /* 32x32->64 multiply. Marks inputs as dead. */
314 static TCGv_i64
gen_mulu_i64_i32(TCGv a
, TCGv b
)
316 TCGv_i64 tmp1
= tcg_temp_new_i64();
317 TCGv_i64 tmp2
= tcg_temp_new_i64();
319 tcg_gen_extu_i32_i64(tmp1
, a
);
320 tcg_temp_free_i32(a
);
321 tcg_gen_extu_i32_i64(tmp2
, b
);
322 tcg_temp_free_i32(b
);
323 tcg_gen_mul_i64(tmp1
, tmp1
, tmp2
);
324 tcg_temp_free_i64(tmp2
);
328 static TCGv_i64
gen_muls_i64_i32(TCGv a
, TCGv b
)
330 TCGv_i64 tmp1
= tcg_temp_new_i64();
331 TCGv_i64 tmp2
= tcg_temp_new_i64();
333 tcg_gen_ext_i32_i64(tmp1
, a
);
334 tcg_temp_free_i32(a
);
335 tcg_gen_ext_i32_i64(tmp2
, b
);
336 tcg_temp_free_i32(b
);
337 tcg_gen_mul_i64(tmp1
, tmp1
, tmp2
);
338 tcg_temp_free_i64(tmp2
);
342 /* Swap low and high halfwords. */
343 static void gen_swap_half(TCGv var
)
345 TCGv tmp
= tcg_temp_new_i32();
346 tcg_gen_shri_i32(tmp
, var
, 16);
347 tcg_gen_shli_i32(var
, var
, 16);
348 tcg_gen_or_i32(var
, var
, tmp
);
349 tcg_temp_free_i32(tmp
);
352 /* Dual 16-bit add. Result placed in t0 and t1 is marked as dead.
353 tmp = (t0 ^ t1) & 0x8000;
356 t0 = (t0 + t1) ^ tmp;
359 static void gen_add16(TCGv t0
, TCGv t1
)
361 TCGv tmp
= tcg_temp_new_i32();
362 tcg_gen_xor_i32(tmp
, t0
, t1
);
363 tcg_gen_andi_i32(tmp
, tmp
, 0x8000);
364 tcg_gen_andi_i32(t0
, t0
, ~0x8000);
365 tcg_gen_andi_i32(t1
, t1
, ~0x8000);
366 tcg_gen_add_i32(t0
, t0
, t1
);
367 tcg_gen_xor_i32(t0
, t0
, tmp
);
368 tcg_temp_free_i32(tmp
);
369 tcg_temp_free_i32(t1
);
372 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, CF))
374 /* Set CF to the top bit of var. */
375 static void gen_set_CF_bit31(TCGv var
)
377 TCGv tmp
= tcg_temp_new_i32();
378 tcg_gen_shri_i32(tmp
, var
, 31);
380 tcg_temp_free_i32(tmp
);
383 /* Set N and Z flags from var. */
384 static inline void gen_logic_CC(TCGv var
)
386 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, NF
));
387 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, ZF
));
391 static void gen_adc(TCGv t0
, TCGv t1
)
394 tcg_gen_add_i32(t0
, t0
, t1
);
395 tmp
= load_cpu_field(CF
);
396 tcg_gen_add_i32(t0
, t0
, tmp
);
397 tcg_temp_free_i32(tmp
);
400 /* dest = T0 + T1 + CF. */
401 static void gen_add_carry(TCGv dest
, TCGv t0
, TCGv t1
)
404 tcg_gen_add_i32(dest
, t0
, t1
);
405 tmp
= load_cpu_field(CF
);
406 tcg_gen_add_i32(dest
, dest
, tmp
);
407 tcg_temp_free_i32(tmp
);
410 /* dest = T0 - T1 + CF - 1. */
411 static void gen_sub_carry(TCGv dest
, TCGv t0
, TCGv t1
)
414 tcg_gen_sub_i32(dest
, t0
, t1
);
415 tmp
= load_cpu_field(CF
);
416 tcg_gen_add_i32(dest
, dest
, tmp
);
417 tcg_gen_subi_i32(dest
, dest
, 1);
418 tcg_temp_free_i32(tmp
);
421 /* FIXME: Implement this natively. */
422 #define tcg_gen_abs_i32(t0, t1) gen_helper_abs(t0, t1)
424 static void shifter_out_im(TCGv var
, int shift
)
426 TCGv tmp
= tcg_temp_new_i32();
428 tcg_gen_andi_i32(tmp
, var
, 1);
430 tcg_gen_shri_i32(tmp
, var
, shift
);
432 tcg_gen_andi_i32(tmp
, tmp
, 1);
435 tcg_temp_free_i32(tmp
);
438 /* Shift by immediate. Includes special handling for shift == 0. */
439 static inline void gen_arm_shift_im(TCGv var
, int shiftop
, int shift
, int flags
)
445 shifter_out_im(var
, 32 - shift
);
446 tcg_gen_shli_i32(var
, var
, shift
);
452 tcg_gen_shri_i32(var
, var
, 31);
455 tcg_gen_movi_i32(var
, 0);
458 shifter_out_im(var
, shift
- 1);
459 tcg_gen_shri_i32(var
, var
, shift
);
466 shifter_out_im(var
, shift
- 1);
469 tcg_gen_sari_i32(var
, var
, shift
);
471 case 3: /* ROR/RRX */
474 shifter_out_im(var
, shift
- 1);
475 tcg_gen_rotri_i32(var
, var
, shift
); break;
477 TCGv tmp
= load_cpu_field(CF
);
479 shifter_out_im(var
, 0);
480 tcg_gen_shri_i32(var
, var
, 1);
481 tcg_gen_shli_i32(tmp
, tmp
, 31);
482 tcg_gen_or_i32(var
, var
, tmp
);
483 tcg_temp_free_i32(tmp
);
488 static inline void gen_arm_shift_reg(TCGv var
, int shiftop
,
489 TCGv shift
, int flags
)
493 case 0: gen_helper_shl_cc(var
, var
, shift
); break;
494 case 1: gen_helper_shr_cc(var
, var
, shift
); break;
495 case 2: gen_helper_sar_cc(var
, var
, shift
); break;
496 case 3: gen_helper_ror_cc(var
, var
, shift
); break;
500 case 0: gen_helper_shl(var
, var
, shift
); break;
501 case 1: gen_helper_shr(var
, var
, shift
); break;
502 case 2: gen_helper_sar(var
, var
, shift
); break;
503 case 3: tcg_gen_andi_i32(shift
, shift
, 0x1f);
504 tcg_gen_rotr_i32(var
, var
, shift
); break;
507 tcg_temp_free_i32(shift
);
510 #define PAS_OP(pfx) \
512 case 0: gen_pas_helper(glue(pfx,add16)); break; \
513 case 1: gen_pas_helper(glue(pfx,addsubx)); break; \
514 case 2: gen_pas_helper(glue(pfx,subaddx)); break; \
515 case 3: gen_pas_helper(glue(pfx,sub16)); break; \
516 case 4: gen_pas_helper(glue(pfx,add8)); break; \
517 case 7: gen_pas_helper(glue(pfx,sub8)); break; \
519 static void gen_arm_parallel_addsub(int op1
, int op2
, TCGv a
, TCGv b
)
524 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
526 tmp
= tcg_temp_new_ptr();
527 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
529 tcg_temp_free_ptr(tmp
);
532 tmp
= tcg_temp_new_ptr();
533 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
535 tcg_temp_free_ptr(tmp
);
537 #undef gen_pas_helper
538 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b)
551 #undef gen_pas_helper
556 /* For unknown reasons Arm and Thumb-2 use arbitrarily different encodings. */
557 #define PAS_OP(pfx) \
559 case 0: gen_pas_helper(glue(pfx,add8)); break; \
560 case 1: gen_pas_helper(glue(pfx,add16)); break; \
561 case 2: gen_pas_helper(glue(pfx,addsubx)); break; \
562 case 4: gen_pas_helper(glue(pfx,sub8)); break; \
563 case 5: gen_pas_helper(glue(pfx,sub16)); break; \
564 case 6: gen_pas_helper(glue(pfx,subaddx)); break; \
566 static void gen_thumb2_parallel_addsub(int op1
, int op2
, TCGv a
, TCGv b
)
571 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
573 tmp
= tcg_temp_new_ptr();
574 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
576 tcg_temp_free_ptr(tmp
);
579 tmp
= tcg_temp_new_ptr();
580 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
582 tcg_temp_free_ptr(tmp
);
584 #undef gen_pas_helper
585 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b)
598 #undef gen_pas_helper
603 static void gen_test_cc(int cc
, int label
)
611 tmp
= load_cpu_field(ZF
);
612 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
615 tmp
= load_cpu_field(ZF
);
616 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
619 tmp
= load_cpu_field(CF
);
620 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
623 tmp
= load_cpu_field(CF
);
624 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
627 tmp
= load_cpu_field(NF
);
628 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
631 tmp
= load_cpu_field(NF
);
632 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
635 tmp
= load_cpu_field(VF
);
636 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
639 tmp
= load_cpu_field(VF
);
640 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
642 case 8: /* hi: C && !Z */
643 inv
= gen_new_label();
644 tmp
= load_cpu_field(CF
);
645 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
646 tcg_temp_free_i32(tmp
);
647 tmp
= load_cpu_field(ZF
);
648 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
651 case 9: /* ls: !C || Z */
652 tmp
= load_cpu_field(CF
);
653 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
654 tcg_temp_free_i32(tmp
);
655 tmp
= load_cpu_field(ZF
);
656 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
658 case 10: /* ge: N == V -> N ^ V == 0 */
659 tmp
= load_cpu_field(VF
);
660 tmp2
= load_cpu_field(NF
);
661 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
662 tcg_temp_free_i32(tmp2
);
663 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
665 case 11: /* lt: N != V -> N ^ V != 0 */
666 tmp
= load_cpu_field(VF
);
667 tmp2
= load_cpu_field(NF
);
668 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
669 tcg_temp_free_i32(tmp2
);
670 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
672 case 12: /* gt: !Z && N == V */
673 inv
= gen_new_label();
674 tmp
= load_cpu_field(ZF
);
675 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
676 tcg_temp_free_i32(tmp
);
677 tmp
= load_cpu_field(VF
);
678 tmp2
= load_cpu_field(NF
);
679 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
680 tcg_temp_free_i32(tmp2
);
681 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
684 case 13: /* le: Z || N != V */
685 tmp
= load_cpu_field(ZF
);
686 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
687 tcg_temp_free_i32(tmp
);
688 tmp
= load_cpu_field(VF
);
689 tmp2
= load_cpu_field(NF
);
690 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
691 tcg_temp_free_i32(tmp2
);
692 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
695 fprintf(stderr
, "Bad condition code 0x%x\n", cc
);
698 tcg_temp_free_i32(tmp
);
701 static const uint8_t table_logic_cc
[16] = {
720 /* Set PC and Thumb state from an immediate address. */
721 static inline void gen_bx_im(DisasContext
*s
, uint32_t addr
)
725 s
->is_jmp
= DISAS_UPDATE
;
726 if (s
->thumb
!= (addr
& 1)) {
727 tmp
= tcg_temp_new_i32();
728 tcg_gen_movi_i32(tmp
, addr
& 1);
729 tcg_gen_st_i32(tmp
, cpu_env
, offsetof(CPUState
, thumb
));
730 tcg_temp_free_i32(tmp
);
732 tcg_gen_movi_i32(cpu_R
[15], addr
& ~1);
735 /* Set PC and Thumb state from var. var is marked as dead. */
736 static inline void gen_bx(DisasContext
*s
, TCGv var
)
738 s
->is_jmp
= DISAS_UPDATE
;
739 tcg_gen_andi_i32(cpu_R
[15], var
, ~1);
740 tcg_gen_andi_i32(var
, var
, 1);
741 store_cpu_field(var
, thumb
);
744 /* Variant of store_reg which uses branch&exchange logic when storing
745 to r15 in ARM architecture v7 and above. The source must be a temporary
746 and will be marked as dead. */
747 static inline void store_reg_bx(CPUState
*env
, DisasContext
*s
,
750 if (reg
== 15 && ENABLE_ARCH_7
) {
753 store_reg(s
, reg
, var
);
757 /* Variant of store_reg which uses branch&exchange logic when storing
758 * to r15 in ARM architecture v5T and above. This is used for storing
759 * the results of a LDR/LDM/POP into r15, and corresponds to the cases
760 * in the ARM ARM which use the LoadWritePC() pseudocode function. */
761 static inline void store_reg_from_load(CPUState
*env
, DisasContext
*s
,
764 if (reg
== 15 && ENABLE_ARCH_5
) {
767 store_reg(s
, reg
, var
);
771 static inline TCGv
gen_ld8s(TCGv addr
, int index
)
773 TCGv tmp
= tcg_temp_new_i32();
774 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
777 static inline TCGv
gen_ld8u(TCGv addr
, int index
)
779 TCGv tmp
= tcg_temp_new_i32();
780 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
783 static inline TCGv
gen_ld16s(TCGv addr
, int index
)
785 TCGv tmp
= tcg_temp_new_i32();
786 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
789 static inline TCGv
gen_ld16u(TCGv addr
, int index
)
791 TCGv tmp
= tcg_temp_new_i32();
792 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
795 static inline TCGv
gen_ld32(TCGv addr
, int index
)
797 TCGv tmp
= tcg_temp_new_i32();
798 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
801 static inline TCGv_i64
gen_ld64(TCGv addr
, int index
)
803 TCGv_i64 tmp
= tcg_temp_new_i64();
804 tcg_gen_qemu_ld64(tmp
, addr
, index
);
807 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
809 tcg_gen_qemu_st8(val
, addr
, index
);
810 tcg_temp_free_i32(val
);
812 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
814 tcg_gen_qemu_st16(val
, addr
, index
);
815 tcg_temp_free_i32(val
);
817 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
819 tcg_gen_qemu_st32(val
, addr
, index
);
820 tcg_temp_free_i32(val
);
822 static inline void gen_st64(TCGv_i64 val
, TCGv addr
, int index
)
824 tcg_gen_qemu_st64(val
, addr
, index
);
825 tcg_temp_free_i64(val
);
828 static inline void gen_set_pc_im(uint32_t val
)
830 tcg_gen_movi_i32(cpu_R
[15], val
);
833 /* Force a TB lookup after an instruction that changes the CPU state. */
834 static inline void gen_lookup_tb(DisasContext
*s
)
836 tcg_gen_movi_i32(cpu_R
[15], s
->pc
& ~1);
837 s
->is_jmp
= DISAS_UPDATE
;
840 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
843 int val
, rm
, shift
, shiftop
;
846 if (!(insn
& (1 << 25))) {
849 if (!(insn
& (1 << 23)))
852 tcg_gen_addi_i32(var
, var
, val
);
856 shift
= (insn
>> 7) & 0x1f;
857 shiftop
= (insn
>> 5) & 3;
858 offset
= load_reg(s
, rm
);
859 gen_arm_shift_im(offset
, shiftop
, shift
, 0);
860 if (!(insn
& (1 << 23)))
861 tcg_gen_sub_i32(var
, var
, offset
);
863 tcg_gen_add_i32(var
, var
, offset
);
864 tcg_temp_free_i32(offset
);
868 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
874 if (insn
& (1 << 22)) {
876 val
= (insn
& 0xf) | ((insn
>> 4) & 0xf0);
877 if (!(insn
& (1 << 23)))
881 tcg_gen_addi_i32(var
, var
, val
);
885 tcg_gen_addi_i32(var
, var
, extra
);
887 offset
= load_reg(s
, rm
);
888 if (!(insn
& (1 << 23)))
889 tcg_gen_sub_i32(var
, var
, offset
);
891 tcg_gen_add_i32(var
, var
, offset
);
892 tcg_temp_free_i32(offset
);
896 #define VFP_OP2(name) \
897 static inline void gen_vfp_##name(int dp) \
900 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, cpu_F1d, cpu_env); \
902 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, cpu_F1s, cpu_env); \
912 static inline void gen_vfp_F1_mul(int dp
)
914 /* Like gen_vfp_mul() but put result in F1 */
916 gen_helper_vfp_muld(cpu_F1d
, cpu_F0d
, cpu_F1d
, cpu_env
);
918 gen_helper_vfp_muls(cpu_F1s
, cpu_F0s
, cpu_F1s
, cpu_env
);
922 static inline void gen_vfp_F1_neg(int dp
)
924 /* Like gen_vfp_neg() but put result in F1 */
926 gen_helper_vfp_negd(cpu_F1d
, cpu_F0d
);
928 gen_helper_vfp_negs(cpu_F1s
, cpu_F0s
);
932 static inline void gen_vfp_abs(int dp
)
935 gen_helper_vfp_absd(cpu_F0d
, cpu_F0d
);
937 gen_helper_vfp_abss(cpu_F0s
, cpu_F0s
);
940 static inline void gen_vfp_neg(int dp
)
943 gen_helper_vfp_negd(cpu_F0d
, cpu_F0d
);
945 gen_helper_vfp_negs(cpu_F0s
, cpu_F0s
);
948 static inline void gen_vfp_sqrt(int dp
)
951 gen_helper_vfp_sqrtd(cpu_F0d
, cpu_F0d
, cpu_env
);
953 gen_helper_vfp_sqrts(cpu_F0s
, cpu_F0s
, cpu_env
);
956 static inline void gen_vfp_cmp(int dp
)
959 gen_helper_vfp_cmpd(cpu_F0d
, cpu_F1d
, cpu_env
);
961 gen_helper_vfp_cmps(cpu_F0s
, cpu_F1s
, cpu_env
);
964 static inline void gen_vfp_cmpe(int dp
)
967 gen_helper_vfp_cmped(cpu_F0d
, cpu_F1d
, cpu_env
);
969 gen_helper_vfp_cmpes(cpu_F0s
, cpu_F1s
, cpu_env
);
972 static inline void gen_vfp_F1_ld0(int dp
)
975 tcg_gen_movi_i64(cpu_F1d
, 0);
977 tcg_gen_movi_i32(cpu_F1s
, 0);
980 #define VFP_GEN_ITOF(name) \
981 static inline void gen_vfp_##name(int dp, int neon) \
983 TCGv statusptr = tcg_temp_new_i32(); \
986 offset = offsetof(CPUState, vfp.standard_fp_status); \
988 offset = offsetof(CPUState, vfp.fp_status); \
990 tcg_gen_addi_i32(statusptr, cpu_env, offset); \
992 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0s, statusptr); \
994 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, statusptr); \
996 tcg_temp_free_i32(statusptr); \
1003 #define VFP_GEN_FTOI(name) \
1004 static inline void gen_vfp_##name(int dp, int neon) \
1006 TCGv statusptr = tcg_temp_new_i32(); \
1009 offset = offsetof(CPUState, vfp.standard_fp_status); \
1011 offset = offsetof(CPUState, vfp.fp_status); \
1013 tcg_gen_addi_i32(statusptr, cpu_env, offset); \
1015 gen_helper_vfp_##name##d(cpu_F0s, cpu_F0d, statusptr); \
1017 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, statusptr); \
1019 tcg_temp_free_i32(statusptr); \
1028 #define VFP_GEN_FIX(name) \
1029 static inline void gen_vfp_##name(int dp, int shift, int neon) \
1031 TCGv tmp_shift = tcg_const_i32(shift); \
1032 TCGv statusptr = tcg_temp_new_i32(); \
1035 offset = offsetof(CPUState, vfp.standard_fp_status); \
1037 offset = offsetof(CPUState, vfp.fp_status); \
1039 tcg_gen_addi_i32(statusptr, cpu_env, offset); \
1041 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, tmp_shift, statusptr); \
1043 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, tmp_shift, statusptr); \
1045 tcg_temp_free_i32(tmp_shift); \
1046 tcg_temp_free_i32(statusptr); \
1058 static inline void gen_vfp_ld(DisasContext
*s
, int dp
, TCGv addr
)
1061 tcg_gen_qemu_ld64(cpu_F0d
, addr
, IS_USER(s
));
1063 tcg_gen_qemu_ld32u(cpu_F0s
, addr
, IS_USER(s
));
1066 static inline void gen_vfp_st(DisasContext
*s
, int dp
, TCGv addr
)
1069 tcg_gen_qemu_st64(cpu_F0d
, addr
, IS_USER(s
));
1071 tcg_gen_qemu_st32(cpu_F0s
, addr
, IS_USER(s
));
1075 vfp_reg_offset (int dp
, int reg
)
1078 return offsetof(CPUARMState
, vfp
.regs
[reg
]);
1080 return offsetof(CPUARMState
, vfp
.regs
[reg
>> 1])
1081 + offsetof(CPU_DoubleU
, l
.upper
);
1083 return offsetof(CPUARMState
, vfp
.regs
[reg
>> 1])
1084 + offsetof(CPU_DoubleU
, l
.lower
);
1088 /* Return the offset of a 32-bit piece of a NEON register.
1089 zero is the least significant end of the register. */
1091 neon_reg_offset (int reg
, int n
)
1095 return vfp_reg_offset(0, sreg
);
1098 static TCGv
neon_load_reg(int reg
, int pass
)
1100 TCGv tmp
= tcg_temp_new_i32();
1101 tcg_gen_ld_i32(tmp
, cpu_env
, neon_reg_offset(reg
, pass
));
1105 static void neon_store_reg(int reg
, int pass
, TCGv var
)
1107 tcg_gen_st_i32(var
, cpu_env
, neon_reg_offset(reg
, pass
));
1108 tcg_temp_free_i32(var
);
1111 static inline void neon_load_reg64(TCGv_i64 var
, int reg
)
1113 tcg_gen_ld_i64(var
, cpu_env
, vfp_reg_offset(1, reg
));
1116 static inline void neon_store_reg64(TCGv_i64 var
, int reg
)
1118 tcg_gen_st_i64(var
, cpu_env
, vfp_reg_offset(1, reg
));
1121 #define tcg_gen_ld_f32 tcg_gen_ld_i32
1122 #define tcg_gen_ld_f64 tcg_gen_ld_i64
1123 #define tcg_gen_st_f32 tcg_gen_st_i32
1124 #define tcg_gen_st_f64 tcg_gen_st_i64
1126 static inline void gen_mov_F0_vreg(int dp
, int reg
)
1129 tcg_gen_ld_f64(cpu_F0d
, cpu_env
, vfp_reg_offset(dp
, reg
));
1131 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, vfp_reg_offset(dp
, reg
));
1134 static inline void gen_mov_F1_vreg(int dp
, int reg
)
1137 tcg_gen_ld_f64(cpu_F1d
, cpu_env
, vfp_reg_offset(dp
, reg
));
1139 tcg_gen_ld_f32(cpu_F1s
, cpu_env
, vfp_reg_offset(dp
, reg
));
1142 static inline void gen_mov_vreg_F0(int dp
, int reg
)
1145 tcg_gen_st_f64(cpu_F0d
, cpu_env
, vfp_reg_offset(dp
, reg
));
1147 tcg_gen_st_f32(cpu_F0s
, cpu_env
, vfp_reg_offset(dp
, reg
));
1150 #define ARM_CP_RW_BIT (1 << 20)
1152 static inline void iwmmxt_load_reg(TCGv_i64 var
, int reg
)
1154 tcg_gen_ld_i64(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.regs
[reg
]));
1157 static inline void iwmmxt_store_reg(TCGv_i64 var
, int reg
)
1159 tcg_gen_st_i64(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.regs
[reg
]));
1162 static inline TCGv
iwmmxt_load_creg(int reg
)
1164 TCGv var
= tcg_temp_new_i32();
1165 tcg_gen_ld_i32(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.cregs
[reg
]));
1169 static inline void iwmmxt_store_creg(int reg
, TCGv var
)
1171 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.cregs
[reg
]));
1172 tcg_temp_free_i32(var
);
1175 static inline void gen_op_iwmmxt_movq_wRn_M0(int rn
)
1177 iwmmxt_store_reg(cpu_M0
, rn
);
1180 static inline void gen_op_iwmmxt_movq_M0_wRn(int rn
)
1182 iwmmxt_load_reg(cpu_M0
, rn
);
1185 static inline void gen_op_iwmmxt_orq_M0_wRn(int rn
)
1187 iwmmxt_load_reg(cpu_V1
, rn
);
1188 tcg_gen_or_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1191 static inline void gen_op_iwmmxt_andq_M0_wRn(int rn
)
1193 iwmmxt_load_reg(cpu_V1
, rn
);
1194 tcg_gen_and_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1197 static inline void gen_op_iwmmxt_xorq_M0_wRn(int rn
)
1199 iwmmxt_load_reg(cpu_V1
, rn
);
1200 tcg_gen_xor_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1203 #define IWMMXT_OP(name) \
1204 static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
1206 iwmmxt_load_reg(cpu_V1, rn); \
1207 gen_helper_iwmmxt_##name(cpu_M0, cpu_M0, cpu_V1); \
1210 #define IWMMXT_OP_SIZE(name) \
1211 IWMMXT_OP(name##b) \
1212 IWMMXT_OP(name##w) \
1215 #define IWMMXT_OP_1(name) \
1216 static inline void gen_op_iwmmxt_##name##_M0(void) \
1218 gen_helper_iwmmxt_##name(cpu_M0, cpu_M0); \
1232 IWMMXT_OP_SIZE(unpackl
)
1233 IWMMXT_OP_SIZE(unpackh
)
1235 IWMMXT_OP_1(unpacklub
)
1236 IWMMXT_OP_1(unpackluw
)
1237 IWMMXT_OP_1(unpacklul
)
1238 IWMMXT_OP_1(unpackhub
)
1239 IWMMXT_OP_1(unpackhuw
)
1240 IWMMXT_OP_1(unpackhul
)
1241 IWMMXT_OP_1(unpacklsb
)
1242 IWMMXT_OP_1(unpacklsw
)
1243 IWMMXT_OP_1(unpacklsl
)
1244 IWMMXT_OP_1(unpackhsb
)
1245 IWMMXT_OP_1(unpackhsw
)
1246 IWMMXT_OP_1(unpackhsl
)
1248 IWMMXT_OP_SIZE(cmpeq
)
1249 IWMMXT_OP_SIZE(cmpgtu
)
1250 IWMMXT_OP_SIZE(cmpgts
)
1252 IWMMXT_OP_SIZE(mins
)
1253 IWMMXT_OP_SIZE(minu
)
1254 IWMMXT_OP_SIZE(maxs
)
1255 IWMMXT_OP_SIZE(maxu
)
1257 IWMMXT_OP_SIZE(subn
)
1258 IWMMXT_OP_SIZE(addn
)
1259 IWMMXT_OP_SIZE(subu
)
1260 IWMMXT_OP_SIZE(addu
)
1261 IWMMXT_OP_SIZE(subs
)
1262 IWMMXT_OP_SIZE(adds
)
1278 static void gen_op_iwmmxt_set_mup(void)
1281 tmp
= load_cpu_field(iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1282 tcg_gen_ori_i32(tmp
, tmp
, 2);
1283 store_cpu_field(tmp
, iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1286 static void gen_op_iwmmxt_set_cup(void)
1289 tmp
= load_cpu_field(iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1290 tcg_gen_ori_i32(tmp
, tmp
, 1);
1291 store_cpu_field(tmp
, iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1294 static void gen_op_iwmmxt_setpsr_nz(void)
1296 TCGv tmp
= tcg_temp_new_i32();
1297 gen_helper_iwmmxt_setpsr_nz(tmp
, cpu_M0
);
1298 store_cpu_field(tmp
, iwmmxt
.cregs
[ARM_IWMMXT_wCASF
]);
1301 static inline void gen_op_iwmmxt_addl_M0_wRn(int rn
)
1303 iwmmxt_load_reg(cpu_V1
, rn
);
1304 tcg_gen_ext32u_i64(cpu_V1
, cpu_V1
);
1305 tcg_gen_add_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1308 static inline int gen_iwmmxt_address(DisasContext
*s
, uint32_t insn
, TCGv dest
)
1314 rd
= (insn
>> 16) & 0xf;
1315 tmp
= load_reg(s
, rd
);
1317 offset
= (insn
& 0xff) << ((insn
>> 7) & 2);
1318 if (insn
& (1 << 24)) {
1320 if (insn
& (1 << 23))
1321 tcg_gen_addi_i32(tmp
, tmp
, offset
);
1323 tcg_gen_addi_i32(tmp
, tmp
, -offset
);
1324 tcg_gen_mov_i32(dest
, tmp
);
1325 if (insn
& (1 << 21))
1326 store_reg(s
, rd
, tmp
);
1328 tcg_temp_free_i32(tmp
);
1329 } else if (insn
& (1 << 21)) {
1331 tcg_gen_mov_i32(dest
, tmp
);
1332 if (insn
& (1 << 23))
1333 tcg_gen_addi_i32(tmp
, tmp
, offset
);
1335 tcg_gen_addi_i32(tmp
, tmp
, -offset
);
1336 store_reg(s
, rd
, tmp
);
1337 } else if (!(insn
& (1 << 23)))
1342 static inline int gen_iwmmxt_shift(uint32_t insn
, uint32_t mask
, TCGv dest
)
1344 int rd
= (insn
>> 0) & 0xf;
1347 if (insn
& (1 << 8)) {
1348 if (rd
< ARM_IWMMXT_wCGR0
|| rd
> ARM_IWMMXT_wCGR3
) {
1351 tmp
= iwmmxt_load_creg(rd
);
1354 tmp
= tcg_temp_new_i32();
1355 iwmmxt_load_reg(cpu_V0
, rd
);
1356 tcg_gen_trunc_i64_i32(tmp
, cpu_V0
);
1358 tcg_gen_andi_i32(tmp
, tmp
, mask
);
1359 tcg_gen_mov_i32(dest
, tmp
);
1360 tcg_temp_free_i32(tmp
);
1364 /* Disassemble an iwMMXt instruction. Returns nonzero if an error occurred
1365 (ie. an undefined instruction). */
1366 static int disas_iwmmxt_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1369 int rdhi
, rdlo
, rd0
, rd1
, i
;
1371 TCGv tmp
, tmp2
, tmp3
;
1373 if ((insn
& 0x0e000e00) == 0x0c000000) {
1374 if ((insn
& 0x0fe00ff0) == 0x0c400000) {
1376 rdlo
= (insn
>> 12) & 0xf;
1377 rdhi
= (insn
>> 16) & 0xf;
1378 if (insn
& ARM_CP_RW_BIT
) { /* TMRRC */
1379 iwmmxt_load_reg(cpu_V0
, wrd
);
1380 tcg_gen_trunc_i64_i32(cpu_R
[rdlo
], cpu_V0
);
1381 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
1382 tcg_gen_trunc_i64_i32(cpu_R
[rdhi
], cpu_V0
);
1383 } else { /* TMCRR */
1384 tcg_gen_concat_i32_i64(cpu_V0
, cpu_R
[rdlo
], cpu_R
[rdhi
]);
1385 iwmmxt_store_reg(cpu_V0
, wrd
);
1386 gen_op_iwmmxt_set_mup();
1391 wrd
= (insn
>> 12) & 0xf;
1392 addr
= tcg_temp_new_i32();
1393 if (gen_iwmmxt_address(s
, insn
, addr
)) {
1394 tcg_temp_free_i32(addr
);
1397 if (insn
& ARM_CP_RW_BIT
) {
1398 if ((insn
>> 28) == 0xf) { /* WLDRW wCx */
1399 tmp
= tcg_temp_new_i32();
1400 tcg_gen_qemu_ld32u(tmp
, addr
, IS_USER(s
));
1401 iwmmxt_store_creg(wrd
, tmp
);
1404 if (insn
& (1 << 8)) {
1405 if (insn
& (1 << 22)) { /* WLDRD */
1406 tcg_gen_qemu_ld64(cpu_M0
, addr
, IS_USER(s
));
1408 } else { /* WLDRW wRd */
1409 tmp
= gen_ld32(addr
, IS_USER(s
));
1412 if (insn
& (1 << 22)) { /* WLDRH */
1413 tmp
= gen_ld16u(addr
, IS_USER(s
));
1414 } else { /* WLDRB */
1415 tmp
= gen_ld8u(addr
, IS_USER(s
));
1419 tcg_gen_extu_i32_i64(cpu_M0
, tmp
);
1420 tcg_temp_free_i32(tmp
);
1422 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1425 if ((insn
>> 28) == 0xf) { /* WSTRW wCx */
1426 tmp
= iwmmxt_load_creg(wrd
);
1427 gen_st32(tmp
, addr
, IS_USER(s
));
1429 gen_op_iwmmxt_movq_M0_wRn(wrd
);
1430 tmp
= tcg_temp_new_i32();
1431 if (insn
& (1 << 8)) {
1432 if (insn
& (1 << 22)) { /* WSTRD */
1433 tcg_temp_free_i32(tmp
);
1434 tcg_gen_qemu_st64(cpu_M0
, addr
, IS_USER(s
));
1435 } else { /* WSTRW wRd */
1436 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1437 gen_st32(tmp
, addr
, IS_USER(s
));
1440 if (insn
& (1 << 22)) { /* WSTRH */
1441 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1442 gen_st16(tmp
, addr
, IS_USER(s
));
1443 } else { /* WSTRB */
1444 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1445 gen_st8(tmp
, addr
, IS_USER(s
));
1450 tcg_temp_free_i32(addr
);
1454 if ((insn
& 0x0f000000) != 0x0e000000)
1457 switch (((insn
>> 12) & 0xf00) | ((insn
>> 4) & 0xff)) {
1458 case 0x000: /* WOR */
1459 wrd
= (insn
>> 12) & 0xf;
1460 rd0
= (insn
>> 0) & 0xf;
1461 rd1
= (insn
>> 16) & 0xf;
1462 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1463 gen_op_iwmmxt_orq_M0_wRn(rd1
);
1464 gen_op_iwmmxt_setpsr_nz();
1465 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1466 gen_op_iwmmxt_set_mup();
1467 gen_op_iwmmxt_set_cup();
1469 case 0x011: /* TMCR */
1472 rd
= (insn
>> 12) & 0xf;
1473 wrd
= (insn
>> 16) & 0xf;
1475 case ARM_IWMMXT_wCID
:
1476 case ARM_IWMMXT_wCASF
:
1478 case ARM_IWMMXT_wCon
:
1479 gen_op_iwmmxt_set_cup();
1481 case ARM_IWMMXT_wCSSF
:
1482 tmp
= iwmmxt_load_creg(wrd
);
1483 tmp2
= load_reg(s
, rd
);
1484 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1485 tcg_temp_free_i32(tmp2
);
1486 iwmmxt_store_creg(wrd
, tmp
);
1488 case ARM_IWMMXT_wCGR0
:
1489 case ARM_IWMMXT_wCGR1
:
1490 case ARM_IWMMXT_wCGR2
:
1491 case ARM_IWMMXT_wCGR3
:
1492 gen_op_iwmmxt_set_cup();
1493 tmp
= load_reg(s
, rd
);
1494 iwmmxt_store_creg(wrd
, tmp
);
1500 case 0x100: /* WXOR */
1501 wrd
= (insn
>> 12) & 0xf;
1502 rd0
= (insn
>> 0) & 0xf;
1503 rd1
= (insn
>> 16) & 0xf;
1504 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1505 gen_op_iwmmxt_xorq_M0_wRn(rd1
);
1506 gen_op_iwmmxt_setpsr_nz();
1507 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1508 gen_op_iwmmxt_set_mup();
1509 gen_op_iwmmxt_set_cup();
1511 case 0x111: /* TMRC */
1514 rd
= (insn
>> 12) & 0xf;
1515 wrd
= (insn
>> 16) & 0xf;
1516 tmp
= iwmmxt_load_creg(wrd
);
1517 store_reg(s
, rd
, tmp
);
1519 case 0x300: /* WANDN */
1520 wrd
= (insn
>> 12) & 0xf;
1521 rd0
= (insn
>> 0) & 0xf;
1522 rd1
= (insn
>> 16) & 0xf;
1523 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1524 tcg_gen_neg_i64(cpu_M0
, cpu_M0
);
1525 gen_op_iwmmxt_andq_M0_wRn(rd1
);
1526 gen_op_iwmmxt_setpsr_nz();
1527 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1528 gen_op_iwmmxt_set_mup();
1529 gen_op_iwmmxt_set_cup();
1531 case 0x200: /* WAND */
1532 wrd
= (insn
>> 12) & 0xf;
1533 rd0
= (insn
>> 0) & 0xf;
1534 rd1
= (insn
>> 16) & 0xf;
1535 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1536 gen_op_iwmmxt_andq_M0_wRn(rd1
);
1537 gen_op_iwmmxt_setpsr_nz();
1538 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1539 gen_op_iwmmxt_set_mup();
1540 gen_op_iwmmxt_set_cup();
1542 case 0x810: case 0xa10: /* WMADD */
1543 wrd
= (insn
>> 12) & 0xf;
1544 rd0
= (insn
>> 0) & 0xf;
1545 rd1
= (insn
>> 16) & 0xf;
1546 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1547 if (insn
& (1 << 21))
1548 gen_op_iwmmxt_maddsq_M0_wRn(rd1
);
1550 gen_op_iwmmxt_madduq_M0_wRn(rd1
);
1551 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1552 gen_op_iwmmxt_set_mup();
1554 case 0x10e: case 0x50e: case 0x90e: case 0xd0e: /* WUNPCKIL */
1555 wrd
= (insn
>> 12) & 0xf;
1556 rd0
= (insn
>> 16) & 0xf;
1557 rd1
= (insn
>> 0) & 0xf;
1558 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1559 switch ((insn
>> 22) & 3) {
1561 gen_op_iwmmxt_unpacklb_M0_wRn(rd1
);
1564 gen_op_iwmmxt_unpacklw_M0_wRn(rd1
);
1567 gen_op_iwmmxt_unpackll_M0_wRn(rd1
);
1572 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1573 gen_op_iwmmxt_set_mup();
1574 gen_op_iwmmxt_set_cup();
1576 case 0x10c: case 0x50c: case 0x90c: case 0xd0c: /* WUNPCKIH */
1577 wrd
= (insn
>> 12) & 0xf;
1578 rd0
= (insn
>> 16) & 0xf;
1579 rd1
= (insn
>> 0) & 0xf;
1580 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1581 switch ((insn
>> 22) & 3) {
1583 gen_op_iwmmxt_unpackhb_M0_wRn(rd1
);
1586 gen_op_iwmmxt_unpackhw_M0_wRn(rd1
);
1589 gen_op_iwmmxt_unpackhl_M0_wRn(rd1
);
1594 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1595 gen_op_iwmmxt_set_mup();
1596 gen_op_iwmmxt_set_cup();
1598 case 0x012: case 0x112: case 0x412: case 0x512: /* WSAD */
1599 wrd
= (insn
>> 12) & 0xf;
1600 rd0
= (insn
>> 16) & 0xf;
1601 rd1
= (insn
>> 0) & 0xf;
1602 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1603 if (insn
& (1 << 22))
1604 gen_op_iwmmxt_sadw_M0_wRn(rd1
);
1606 gen_op_iwmmxt_sadb_M0_wRn(rd1
);
1607 if (!(insn
& (1 << 20)))
1608 gen_op_iwmmxt_addl_M0_wRn(wrd
);
1609 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1610 gen_op_iwmmxt_set_mup();
1612 case 0x010: case 0x110: case 0x210: case 0x310: /* WMUL */
1613 wrd
= (insn
>> 12) & 0xf;
1614 rd0
= (insn
>> 16) & 0xf;
1615 rd1
= (insn
>> 0) & 0xf;
1616 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1617 if (insn
& (1 << 21)) {
1618 if (insn
& (1 << 20))
1619 gen_op_iwmmxt_mulshw_M0_wRn(rd1
);
1621 gen_op_iwmmxt_mulslw_M0_wRn(rd1
);
1623 if (insn
& (1 << 20))
1624 gen_op_iwmmxt_muluhw_M0_wRn(rd1
);
1626 gen_op_iwmmxt_mululw_M0_wRn(rd1
);
1628 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1629 gen_op_iwmmxt_set_mup();
1631 case 0x410: case 0x510: case 0x610: case 0x710: /* WMAC */
1632 wrd
= (insn
>> 12) & 0xf;
1633 rd0
= (insn
>> 16) & 0xf;
1634 rd1
= (insn
>> 0) & 0xf;
1635 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1636 if (insn
& (1 << 21))
1637 gen_op_iwmmxt_macsw_M0_wRn(rd1
);
1639 gen_op_iwmmxt_macuw_M0_wRn(rd1
);
1640 if (!(insn
& (1 << 20))) {
1641 iwmmxt_load_reg(cpu_V1
, wrd
);
1642 tcg_gen_add_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1644 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1645 gen_op_iwmmxt_set_mup();
1647 case 0x006: case 0x406: case 0x806: case 0xc06: /* WCMPEQ */
1648 wrd
= (insn
>> 12) & 0xf;
1649 rd0
= (insn
>> 16) & 0xf;
1650 rd1
= (insn
>> 0) & 0xf;
1651 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1652 switch ((insn
>> 22) & 3) {
1654 gen_op_iwmmxt_cmpeqb_M0_wRn(rd1
);
1657 gen_op_iwmmxt_cmpeqw_M0_wRn(rd1
);
1660 gen_op_iwmmxt_cmpeql_M0_wRn(rd1
);
1665 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1666 gen_op_iwmmxt_set_mup();
1667 gen_op_iwmmxt_set_cup();
1669 case 0x800: case 0x900: case 0xc00: case 0xd00: /* WAVG2 */
1670 wrd
= (insn
>> 12) & 0xf;
1671 rd0
= (insn
>> 16) & 0xf;
1672 rd1
= (insn
>> 0) & 0xf;
1673 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1674 if (insn
& (1 << 22)) {
1675 if (insn
& (1 << 20))
1676 gen_op_iwmmxt_avgw1_M0_wRn(rd1
);
1678 gen_op_iwmmxt_avgw0_M0_wRn(rd1
);
1680 if (insn
& (1 << 20))
1681 gen_op_iwmmxt_avgb1_M0_wRn(rd1
);
1683 gen_op_iwmmxt_avgb0_M0_wRn(rd1
);
1685 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1686 gen_op_iwmmxt_set_mup();
1687 gen_op_iwmmxt_set_cup();
1689 case 0x802: case 0x902: case 0xa02: case 0xb02: /* WALIGNR */
1690 wrd
= (insn
>> 12) & 0xf;
1691 rd0
= (insn
>> 16) & 0xf;
1692 rd1
= (insn
>> 0) & 0xf;
1693 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1694 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCGR0
+ ((insn
>> 20) & 3));
1695 tcg_gen_andi_i32(tmp
, tmp
, 7);
1696 iwmmxt_load_reg(cpu_V1
, rd1
);
1697 gen_helper_iwmmxt_align(cpu_M0
, cpu_M0
, cpu_V1
, tmp
);
1698 tcg_temp_free_i32(tmp
);
1699 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1700 gen_op_iwmmxt_set_mup();
1702 case 0x601: case 0x605: case 0x609: case 0x60d: /* TINSR */
1703 if (((insn
>> 6) & 3) == 3)
1705 rd
= (insn
>> 12) & 0xf;
1706 wrd
= (insn
>> 16) & 0xf;
1707 tmp
= load_reg(s
, rd
);
1708 gen_op_iwmmxt_movq_M0_wRn(wrd
);
1709 switch ((insn
>> 6) & 3) {
1711 tmp2
= tcg_const_i32(0xff);
1712 tmp3
= tcg_const_i32((insn
& 7) << 3);
1715 tmp2
= tcg_const_i32(0xffff);
1716 tmp3
= tcg_const_i32((insn
& 3) << 4);
1719 tmp2
= tcg_const_i32(0xffffffff);
1720 tmp3
= tcg_const_i32((insn
& 1) << 5);
1726 gen_helper_iwmmxt_insr(cpu_M0
, cpu_M0
, tmp
, tmp2
, tmp3
);
1727 tcg_temp_free(tmp3
);
1728 tcg_temp_free(tmp2
);
1729 tcg_temp_free_i32(tmp
);
1730 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1731 gen_op_iwmmxt_set_mup();
1733 case 0x107: case 0x507: case 0x907: case 0xd07: /* TEXTRM */
1734 rd
= (insn
>> 12) & 0xf;
1735 wrd
= (insn
>> 16) & 0xf;
1736 if (rd
== 15 || ((insn
>> 22) & 3) == 3)
1738 gen_op_iwmmxt_movq_M0_wRn(wrd
);
1739 tmp
= tcg_temp_new_i32();
1740 switch ((insn
>> 22) & 3) {
1742 tcg_gen_shri_i64(cpu_M0
, cpu_M0
, (insn
& 7) << 3);
1743 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1745 tcg_gen_ext8s_i32(tmp
, tmp
);
1747 tcg_gen_andi_i32(tmp
, tmp
, 0xff);
1751 tcg_gen_shri_i64(cpu_M0
, cpu_M0
, (insn
& 3) << 4);
1752 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1754 tcg_gen_ext16s_i32(tmp
, tmp
);
1756 tcg_gen_andi_i32(tmp
, tmp
, 0xffff);
1760 tcg_gen_shri_i64(cpu_M0
, cpu_M0
, (insn
& 1) << 5);
1761 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1764 store_reg(s
, rd
, tmp
);
1766 case 0x117: case 0x517: case 0x917: case 0xd17: /* TEXTRC */
1767 if ((insn
& 0x000ff008) != 0x0003f000 || ((insn
>> 22) & 3) == 3)
1769 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCASF
);
1770 switch ((insn
>> 22) & 3) {
1772 tcg_gen_shri_i32(tmp
, tmp
, ((insn
& 7) << 2) + 0);
1775 tcg_gen_shri_i32(tmp
, tmp
, ((insn
& 3) << 3) + 4);
1778 tcg_gen_shri_i32(tmp
, tmp
, ((insn
& 1) << 4) + 12);
1781 tcg_gen_shli_i32(tmp
, tmp
, 28);
1783 tcg_temp_free_i32(tmp
);
1785 case 0x401: case 0x405: case 0x409: case 0x40d: /* TBCST */
1786 if (((insn
>> 6) & 3) == 3)
1788 rd
= (insn
>> 12) & 0xf;
1789 wrd
= (insn
>> 16) & 0xf;
1790 tmp
= load_reg(s
, rd
);
1791 switch ((insn
>> 6) & 3) {
1793 gen_helper_iwmmxt_bcstb(cpu_M0
, tmp
);
1796 gen_helper_iwmmxt_bcstw(cpu_M0
, tmp
);
1799 gen_helper_iwmmxt_bcstl(cpu_M0
, tmp
);
1802 tcg_temp_free_i32(tmp
);
1803 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1804 gen_op_iwmmxt_set_mup();
1806 case 0x113: case 0x513: case 0x913: case 0xd13: /* TANDC */
1807 if ((insn
& 0x000ff00f) != 0x0003f000 || ((insn
>> 22) & 3) == 3)
1809 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCASF
);
1810 tmp2
= tcg_temp_new_i32();
1811 tcg_gen_mov_i32(tmp2
, tmp
);
1812 switch ((insn
>> 22) & 3) {
1814 for (i
= 0; i
< 7; i
++) {
1815 tcg_gen_shli_i32(tmp2
, tmp2
, 4);
1816 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1820 for (i
= 0; i
< 3; i
++) {
1821 tcg_gen_shli_i32(tmp2
, tmp2
, 8);
1822 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1826 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
1827 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1831 tcg_temp_free_i32(tmp2
);
1832 tcg_temp_free_i32(tmp
);
1834 case 0x01c: case 0x41c: case 0x81c: case 0xc1c: /* WACC */
1835 wrd
= (insn
>> 12) & 0xf;
1836 rd0
= (insn
>> 16) & 0xf;
1837 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1838 switch ((insn
>> 22) & 3) {
1840 gen_helper_iwmmxt_addcb(cpu_M0
, cpu_M0
);
1843 gen_helper_iwmmxt_addcw(cpu_M0
, cpu_M0
);
1846 gen_helper_iwmmxt_addcl(cpu_M0
, cpu_M0
);
1851 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1852 gen_op_iwmmxt_set_mup();
1854 case 0x115: case 0x515: case 0x915: case 0xd15: /* TORC */
1855 if ((insn
& 0x000ff00f) != 0x0003f000 || ((insn
>> 22) & 3) == 3)
1857 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCASF
);
1858 tmp2
= tcg_temp_new_i32();
1859 tcg_gen_mov_i32(tmp2
, tmp
);
1860 switch ((insn
>> 22) & 3) {
1862 for (i
= 0; i
< 7; i
++) {
1863 tcg_gen_shli_i32(tmp2
, tmp2
, 4);
1864 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1868 for (i
= 0; i
< 3; i
++) {
1869 tcg_gen_shli_i32(tmp2
, tmp2
, 8);
1870 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1874 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
1875 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1879 tcg_temp_free_i32(tmp2
);
1880 tcg_temp_free_i32(tmp
);
1882 case 0x103: case 0x503: case 0x903: case 0xd03: /* TMOVMSK */
1883 rd
= (insn
>> 12) & 0xf;
1884 rd0
= (insn
>> 16) & 0xf;
1885 if ((insn
& 0xf) != 0 || ((insn
>> 22) & 3) == 3)
1887 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1888 tmp
= tcg_temp_new_i32();
1889 switch ((insn
>> 22) & 3) {
1891 gen_helper_iwmmxt_msbb(tmp
, cpu_M0
);
1894 gen_helper_iwmmxt_msbw(tmp
, cpu_M0
);
1897 gen_helper_iwmmxt_msbl(tmp
, cpu_M0
);
1900 store_reg(s
, rd
, tmp
);
1902 case 0x106: case 0x306: case 0x506: case 0x706: /* WCMPGT */
1903 case 0x906: case 0xb06: case 0xd06: case 0xf06:
1904 wrd
= (insn
>> 12) & 0xf;
1905 rd0
= (insn
>> 16) & 0xf;
1906 rd1
= (insn
>> 0) & 0xf;
1907 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1908 switch ((insn
>> 22) & 3) {
1910 if (insn
& (1 << 21))
1911 gen_op_iwmmxt_cmpgtsb_M0_wRn(rd1
);
1913 gen_op_iwmmxt_cmpgtub_M0_wRn(rd1
);
1916 if (insn
& (1 << 21))
1917 gen_op_iwmmxt_cmpgtsw_M0_wRn(rd1
);
1919 gen_op_iwmmxt_cmpgtuw_M0_wRn(rd1
);
1922 if (insn
& (1 << 21))
1923 gen_op_iwmmxt_cmpgtsl_M0_wRn(rd1
);
1925 gen_op_iwmmxt_cmpgtul_M0_wRn(rd1
);
1930 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1931 gen_op_iwmmxt_set_mup();
1932 gen_op_iwmmxt_set_cup();
1934 case 0x00e: case 0x20e: case 0x40e: case 0x60e: /* WUNPCKEL */
1935 case 0x80e: case 0xa0e: case 0xc0e: case 0xe0e:
1936 wrd
= (insn
>> 12) & 0xf;
1937 rd0
= (insn
>> 16) & 0xf;
1938 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1939 switch ((insn
>> 22) & 3) {
1941 if (insn
& (1 << 21))
1942 gen_op_iwmmxt_unpacklsb_M0();
1944 gen_op_iwmmxt_unpacklub_M0();
1947 if (insn
& (1 << 21))
1948 gen_op_iwmmxt_unpacklsw_M0();
1950 gen_op_iwmmxt_unpackluw_M0();
1953 if (insn
& (1 << 21))
1954 gen_op_iwmmxt_unpacklsl_M0();
1956 gen_op_iwmmxt_unpacklul_M0();
1961 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1962 gen_op_iwmmxt_set_mup();
1963 gen_op_iwmmxt_set_cup();
1965 case 0x00c: case 0x20c: case 0x40c: case 0x60c: /* WUNPCKEH */
1966 case 0x80c: case 0xa0c: case 0xc0c: case 0xe0c:
1967 wrd
= (insn
>> 12) & 0xf;
1968 rd0
= (insn
>> 16) & 0xf;
1969 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1970 switch ((insn
>> 22) & 3) {
1972 if (insn
& (1 << 21))
1973 gen_op_iwmmxt_unpackhsb_M0();
1975 gen_op_iwmmxt_unpackhub_M0();
1978 if (insn
& (1 << 21))
1979 gen_op_iwmmxt_unpackhsw_M0();
1981 gen_op_iwmmxt_unpackhuw_M0();
1984 if (insn
& (1 << 21))
1985 gen_op_iwmmxt_unpackhsl_M0();
1987 gen_op_iwmmxt_unpackhul_M0();
1992 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1993 gen_op_iwmmxt_set_mup();
1994 gen_op_iwmmxt_set_cup();
1996 case 0x204: case 0x604: case 0xa04: case 0xe04: /* WSRL */
1997 case 0x214: case 0x614: case 0xa14: case 0xe14:
1998 if (((insn
>> 22) & 3) == 0)
2000 wrd
= (insn
>> 12) & 0xf;
2001 rd0
= (insn
>> 16) & 0xf;
2002 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2003 tmp
= tcg_temp_new_i32();
2004 if (gen_iwmmxt_shift(insn
, 0xff, tmp
)) {
2005 tcg_temp_free_i32(tmp
);
2008 switch ((insn
>> 22) & 3) {
2010 gen_helper_iwmmxt_srlw(cpu_M0
, cpu_M0
, tmp
);
2013 gen_helper_iwmmxt_srll(cpu_M0
, cpu_M0
, tmp
);
2016 gen_helper_iwmmxt_srlq(cpu_M0
, cpu_M0
, tmp
);
2019 tcg_temp_free_i32(tmp
);
2020 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2021 gen_op_iwmmxt_set_mup();
2022 gen_op_iwmmxt_set_cup();
2024 case 0x004: case 0x404: case 0x804: case 0xc04: /* WSRA */
2025 case 0x014: case 0x414: case 0x814: case 0xc14:
2026 if (((insn
>> 22) & 3) == 0)
2028 wrd
= (insn
>> 12) & 0xf;
2029 rd0
= (insn
>> 16) & 0xf;
2030 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2031 tmp
= tcg_temp_new_i32();
2032 if (gen_iwmmxt_shift(insn
, 0xff, tmp
)) {
2033 tcg_temp_free_i32(tmp
);
2036 switch ((insn
>> 22) & 3) {
2038 gen_helper_iwmmxt_sraw(cpu_M0
, cpu_M0
, tmp
);
2041 gen_helper_iwmmxt_sral(cpu_M0
, cpu_M0
, tmp
);
2044 gen_helper_iwmmxt_sraq(cpu_M0
, cpu_M0
, tmp
);
2047 tcg_temp_free_i32(tmp
);
2048 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2049 gen_op_iwmmxt_set_mup();
2050 gen_op_iwmmxt_set_cup();
2052 case 0x104: case 0x504: case 0x904: case 0xd04: /* WSLL */
2053 case 0x114: case 0x514: case 0x914: case 0xd14:
2054 if (((insn
>> 22) & 3) == 0)
2056 wrd
= (insn
>> 12) & 0xf;
2057 rd0
= (insn
>> 16) & 0xf;
2058 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2059 tmp
= tcg_temp_new_i32();
2060 if (gen_iwmmxt_shift(insn
, 0xff, tmp
)) {
2061 tcg_temp_free_i32(tmp
);
2064 switch ((insn
>> 22) & 3) {
2066 gen_helper_iwmmxt_sllw(cpu_M0
, cpu_M0
, tmp
);
2069 gen_helper_iwmmxt_slll(cpu_M0
, cpu_M0
, tmp
);
2072 gen_helper_iwmmxt_sllq(cpu_M0
, cpu_M0
, tmp
);
2075 tcg_temp_free_i32(tmp
);
2076 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2077 gen_op_iwmmxt_set_mup();
2078 gen_op_iwmmxt_set_cup();
2080 case 0x304: case 0x704: case 0xb04: case 0xf04: /* WROR */
2081 case 0x314: case 0x714: case 0xb14: case 0xf14:
2082 if (((insn
>> 22) & 3) == 0)
2084 wrd
= (insn
>> 12) & 0xf;
2085 rd0
= (insn
>> 16) & 0xf;
2086 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2087 tmp
= tcg_temp_new_i32();
2088 switch ((insn
>> 22) & 3) {
2090 if (gen_iwmmxt_shift(insn
, 0xf, tmp
)) {
2091 tcg_temp_free_i32(tmp
);
2094 gen_helper_iwmmxt_rorw(cpu_M0
, cpu_M0
, tmp
);
2097 if (gen_iwmmxt_shift(insn
, 0x1f, tmp
)) {
2098 tcg_temp_free_i32(tmp
);
2101 gen_helper_iwmmxt_rorl(cpu_M0
, cpu_M0
, tmp
);
2104 if (gen_iwmmxt_shift(insn
, 0x3f, tmp
)) {
2105 tcg_temp_free_i32(tmp
);
2108 gen_helper_iwmmxt_rorq(cpu_M0
, cpu_M0
, tmp
);
2111 tcg_temp_free_i32(tmp
);
2112 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2113 gen_op_iwmmxt_set_mup();
2114 gen_op_iwmmxt_set_cup();
2116 case 0x116: case 0x316: case 0x516: case 0x716: /* WMIN */
2117 case 0x916: case 0xb16: case 0xd16: case 0xf16:
2118 wrd
= (insn
>> 12) & 0xf;
2119 rd0
= (insn
>> 16) & 0xf;
2120 rd1
= (insn
>> 0) & 0xf;
2121 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2122 switch ((insn
>> 22) & 3) {
2124 if (insn
& (1 << 21))
2125 gen_op_iwmmxt_minsb_M0_wRn(rd1
);
2127 gen_op_iwmmxt_minub_M0_wRn(rd1
);
2130 if (insn
& (1 << 21))
2131 gen_op_iwmmxt_minsw_M0_wRn(rd1
);
2133 gen_op_iwmmxt_minuw_M0_wRn(rd1
);
2136 if (insn
& (1 << 21))
2137 gen_op_iwmmxt_minsl_M0_wRn(rd1
);
2139 gen_op_iwmmxt_minul_M0_wRn(rd1
);
2144 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2145 gen_op_iwmmxt_set_mup();
2147 case 0x016: case 0x216: case 0x416: case 0x616: /* WMAX */
2148 case 0x816: case 0xa16: case 0xc16: case 0xe16:
2149 wrd
= (insn
>> 12) & 0xf;
2150 rd0
= (insn
>> 16) & 0xf;
2151 rd1
= (insn
>> 0) & 0xf;
2152 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2153 switch ((insn
>> 22) & 3) {
2155 if (insn
& (1 << 21))
2156 gen_op_iwmmxt_maxsb_M0_wRn(rd1
);
2158 gen_op_iwmmxt_maxub_M0_wRn(rd1
);
2161 if (insn
& (1 << 21))
2162 gen_op_iwmmxt_maxsw_M0_wRn(rd1
);
2164 gen_op_iwmmxt_maxuw_M0_wRn(rd1
);
2167 if (insn
& (1 << 21))
2168 gen_op_iwmmxt_maxsl_M0_wRn(rd1
);
2170 gen_op_iwmmxt_maxul_M0_wRn(rd1
);
2175 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2176 gen_op_iwmmxt_set_mup();
2178 case 0x002: case 0x102: case 0x202: case 0x302: /* WALIGNI */
2179 case 0x402: case 0x502: case 0x602: case 0x702:
2180 wrd
= (insn
>> 12) & 0xf;
2181 rd0
= (insn
>> 16) & 0xf;
2182 rd1
= (insn
>> 0) & 0xf;
2183 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2184 tmp
= tcg_const_i32((insn
>> 20) & 3);
2185 iwmmxt_load_reg(cpu_V1
, rd1
);
2186 gen_helper_iwmmxt_align(cpu_M0
, cpu_M0
, cpu_V1
, tmp
);
2188 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2189 gen_op_iwmmxt_set_mup();
2191 case 0x01a: case 0x11a: case 0x21a: case 0x31a: /* WSUB */
2192 case 0x41a: case 0x51a: case 0x61a: case 0x71a:
2193 case 0x81a: case 0x91a: case 0xa1a: case 0xb1a:
2194 case 0xc1a: case 0xd1a: case 0xe1a: case 0xf1a:
2195 wrd
= (insn
>> 12) & 0xf;
2196 rd0
= (insn
>> 16) & 0xf;
2197 rd1
= (insn
>> 0) & 0xf;
2198 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2199 switch ((insn
>> 20) & 0xf) {
2201 gen_op_iwmmxt_subnb_M0_wRn(rd1
);
2204 gen_op_iwmmxt_subub_M0_wRn(rd1
);
2207 gen_op_iwmmxt_subsb_M0_wRn(rd1
);
2210 gen_op_iwmmxt_subnw_M0_wRn(rd1
);
2213 gen_op_iwmmxt_subuw_M0_wRn(rd1
);
2216 gen_op_iwmmxt_subsw_M0_wRn(rd1
);
2219 gen_op_iwmmxt_subnl_M0_wRn(rd1
);
2222 gen_op_iwmmxt_subul_M0_wRn(rd1
);
2225 gen_op_iwmmxt_subsl_M0_wRn(rd1
);
2230 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2231 gen_op_iwmmxt_set_mup();
2232 gen_op_iwmmxt_set_cup();
2234 case 0x01e: case 0x11e: case 0x21e: case 0x31e: /* WSHUFH */
2235 case 0x41e: case 0x51e: case 0x61e: case 0x71e:
2236 case 0x81e: case 0x91e: case 0xa1e: case 0xb1e:
2237 case 0xc1e: case 0xd1e: case 0xe1e: case 0xf1e:
2238 wrd
= (insn
>> 12) & 0xf;
2239 rd0
= (insn
>> 16) & 0xf;
2240 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2241 tmp
= tcg_const_i32(((insn
>> 16) & 0xf0) | (insn
& 0x0f));
2242 gen_helper_iwmmxt_shufh(cpu_M0
, cpu_M0
, tmp
);
2244 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2245 gen_op_iwmmxt_set_mup();
2246 gen_op_iwmmxt_set_cup();
2248 case 0x018: case 0x118: case 0x218: case 0x318: /* WADD */
2249 case 0x418: case 0x518: case 0x618: case 0x718:
2250 case 0x818: case 0x918: case 0xa18: case 0xb18:
2251 case 0xc18: case 0xd18: case 0xe18: case 0xf18:
2252 wrd
= (insn
>> 12) & 0xf;
2253 rd0
= (insn
>> 16) & 0xf;
2254 rd1
= (insn
>> 0) & 0xf;
2255 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2256 switch ((insn
>> 20) & 0xf) {
2258 gen_op_iwmmxt_addnb_M0_wRn(rd1
);
2261 gen_op_iwmmxt_addub_M0_wRn(rd1
);
2264 gen_op_iwmmxt_addsb_M0_wRn(rd1
);
2267 gen_op_iwmmxt_addnw_M0_wRn(rd1
);
2270 gen_op_iwmmxt_adduw_M0_wRn(rd1
);
2273 gen_op_iwmmxt_addsw_M0_wRn(rd1
);
2276 gen_op_iwmmxt_addnl_M0_wRn(rd1
);
2279 gen_op_iwmmxt_addul_M0_wRn(rd1
);
2282 gen_op_iwmmxt_addsl_M0_wRn(rd1
);
2287 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2288 gen_op_iwmmxt_set_mup();
2289 gen_op_iwmmxt_set_cup();
2291 case 0x008: case 0x108: case 0x208: case 0x308: /* WPACK */
2292 case 0x408: case 0x508: case 0x608: case 0x708:
2293 case 0x808: case 0x908: case 0xa08: case 0xb08:
2294 case 0xc08: case 0xd08: case 0xe08: case 0xf08:
2295 if (!(insn
& (1 << 20)) || ((insn
>> 22) & 3) == 0)
2297 wrd
= (insn
>> 12) & 0xf;
2298 rd0
= (insn
>> 16) & 0xf;
2299 rd1
= (insn
>> 0) & 0xf;
2300 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2301 switch ((insn
>> 22) & 3) {
2303 if (insn
& (1 << 21))
2304 gen_op_iwmmxt_packsw_M0_wRn(rd1
);
2306 gen_op_iwmmxt_packuw_M0_wRn(rd1
);
2309 if (insn
& (1 << 21))
2310 gen_op_iwmmxt_packsl_M0_wRn(rd1
);
2312 gen_op_iwmmxt_packul_M0_wRn(rd1
);
2315 if (insn
& (1 << 21))
2316 gen_op_iwmmxt_packsq_M0_wRn(rd1
);
2318 gen_op_iwmmxt_packuq_M0_wRn(rd1
);
2321 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2322 gen_op_iwmmxt_set_mup();
2323 gen_op_iwmmxt_set_cup();
2325 case 0x201: case 0x203: case 0x205: case 0x207:
2326 case 0x209: case 0x20b: case 0x20d: case 0x20f:
2327 case 0x211: case 0x213: case 0x215: case 0x217:
2328 case 0x219: case 0x21b: case 0x21d: case 0x21f:
2329 wrd
= (insn
>> 5) & 0xf;
2330 rd0
= (insn
>> 12) & 0xf;
2331 rd1
= (insn
>> 0) & 0xf;
2332 if (rd0
== 0xf || rd1
== 0xf)
2334 gen_op_iwmmxt_movq_M0_wRn(wrd
);
2335 tmp
= load_reg(s
, rd0
);
2336 tmp2
= load_reg(s
, rd1
);
2337 switch ((insn
>> 16) & 0xf) {
2338 case 0x0: /* TMIA */
2339 gen_helper_iwmmxt_muladdsl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2341 case 0x8: /* TMIAPH */
2342 gen_helper_iwmmxt_muladdsw(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2344 case 0xc: case 0xd: case 0xe: case 0xf: /* TMIAxy */
2345 if (insn
& (1 << 16))
2346 tcg_gen_shri_i32(tmp
, tmp
, 16);
2347 if (insn
& (1 << 17))
2348 tcg_gen_shri_i32(tmp2
, tmp2
, 16);
2349 gen_helper_iwmmxt_muladdswl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2352 tcg_temp_free_i32(tmp2
);
2353 tcg_temp_free_i32(tmp
);
2356 tcg_temp_free_i32(tmp2
);
2357 tcg_temp_free_i32(tmp
);
2358 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2359 gen_op_iwmmxt_set_mup();
2368 /* Disassemble an XScale DSP instruction. Returns nonzero if an error occurred
2369 (ie. an undefined instruction). */
2370 static int disas_dsp_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
2372 int acc
, rd0
, rd1
, rdhi
, rdlo
;
2375 if ((insn
& 0x0ff00f10) == 0x0e200010) {
2376 /* Multiply with Internal Accumulate Format */
2377 rd0
= (insn
>> 12) & 0xf;
2379 acc
= (insn
>> 5) & 7;
2384 tmp
= load_reg(s
, rd0
);
2385 tmp2
= load_reg(s
, rd1
);
2386 switch ((insn
>> 16) & 0xf) {
2388 gen_helper_iwmmxt_muladdsl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2390 case 0x8: /* MIAPH */
2391 gen_helper_iwmmxt_muladdsw(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2393 case 0xc: /* MIABB */
2394 case 0xd: /* MIABT */
2395 case 0xe: /* MIATB */
2396 case 0xf: /* MIATT */
2397 if (insn
& (1 << 16))
2398 tcg_gen_shri_i32(tmp
, tmp
, 16);
2399 if (insn
& (1 << 17))
2400 tcg_gen_shri_i32(tmp2
, tmp2
, 16);
2401 gen_helper_iwmmxt_muladdswl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2406 tcg_temp_free_i32(tmp2
);
2407 tcg_temp_free_i32(tmp
);
2409 gen_op_iwmmxt_movq_wRn_M0(acc
);
2413 if ((insn
& 0x0fe00ff8) == 0x0c400000) {
2414 /* Internal Accumulator Access Format */
2415 rdhi
= (insn
>> 16) & 0xf;
2416 rdlo
= (insn
>> 12) & 0xf;
2422 if (insn
& ARM_CP_RW_BIT
) { /* MRA */
2423 iwmmxt_load_reg(cpu_V0
, acc
);
2424 tcg_gen_trunc_i64_i32(cpu_R
[rdlo
], cpu_V0
);
2425 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
2426 tcg_gen_trunc_i64_i32(cpu_R
[rdhi
], cpu_V0
);
2427 tcg_gen_andi_i32(cpu_R
[rdhi
], cpu_R
[rdhi
], (1 << (40 - 32)) - 1);
2429 tcg_gen_concat_i32_i64(cpu_V0
, cpu_R
[rdlo
], cpu_R
[rdhi
]);
2430 iwmmxt_store_reg(cpu_V0
, acc
);
2438 /* Disassemble system coprocessor instruction. Return nonzero if
2439 instruction is not defined. */
2440 static int disas_cp_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
2443 uint32_t rd
= (insn
>> 12) & 0xf;
2444 uint32_t cp
= (insn
>> 8) & 0xf;
2449 if (insn
& ARM_CP_RW_BIT
) {
2450 if (!env
->cp
[cp
].cp_read
)
2452 gen_set_pc_im(s
->pc
);
2453 tmp
= tcg_temp_new_i32();
2454 tmp2
= tcg_const_i32(insn
);
2455 gen_helper_get_cp(tmp
, cpu_env
, tmp2
);
2456 tcg_temp_free(tmp2
);
2457 store_reg(s
, rd
, tmp
);
2459 if (!env
->cp
[cp
].cp_write
)
2461 gen_set_pc_im(s
->pc
);
2462 tmp
= load_reg(s
, rd
);
2463 tmp2
= tcg_const_i32(insn
);
2464 gen_helper_set_cp(cpu_env
, tmp2
, tmp
);
2465 tcg_temp_free(tmp2
);
2466 tcg_temp_free_i32(tmp
);
2471 static int cp15_user_ok(uint32_t insn
)
2473 int cpn
= (insn
>> 16) & 0xf;
2474 int cpm
= insn
& 0xf;
2475 int op
= ((insn
>> 5) & 7) | ((insn
>> 18) & 0x38);
2477 if (cpn
== 13 && cpm
== 0) {
2479 if (op
== 2 || (op
== 3 && (insn
& ARM_CP_RW_BIT
)))
2483 /* ISB, DSB, DMB. */
2484 if ((cpm
== 5 && op
== 4)
2485 || (cpm
== 10 && (op
== 4 || op
== 5)))
2491 static int cp15_tls_load_store(CPUState
*env
, DisasContext
*s
, uint32_t insn
, uint32_t rd
)
2494 int cpn
= (insn
>> 16) & 0xf;
2495 int cpm
= insn
& 0xf;
2496 int op
= ((insn
>> 5) & 7) | ((insn
>> 18) & 0x38);
2498 if (!arm_feature(env
, ARM_FEATURE_V6K
))
2501 if (!(cpn
== 13 && cpm
== 0))
2504 if (insn
& ARM_CP_RW_BIT
) {
2507 tmp
= load_cpu_field(cp15
.c13_tls1
);
2510 tmp
= load_cpu_field(cp15
.c13_tls2
);
2513 tmp
= load_cpu_field(cp15
.c13_tls3
);
2518 store_reg(s
, rd
, tmp
);
2521 tmp
= load_reg(s
, rd
);
2524 store_cpu_field(tmp
, cp15
.c13_tls1
);
2527 store_cpu_field(tmp
, cp15
.c13_tls2
);
2530 store_cpu_field(tmp
, cp15
.c13_tls3
);
2533 tcg_temp_free_i32(tmp
);
2540 /* Disassemble system coprocessor (cp15) instruction. Return nonzero if
2541 instruction is not defined. */
2542 static int disas_cp15_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
2547 /* M profile cores use memory mapped registers instead of cp15. */
2548 if (arm_feature(env
, ARM_FEATURE_M
))
2551 if ((insn
& (1 << 25)) == 0) {
2552 if (insn
& (1 << 20)) {
2556 /* mcrr. Used for block cache operations, so implement as no-op. */
2559 if ((insn
& (1 << 4)) == 0) {
2563 if (IS_USER(s
) && !cp15_user_ok(insn
)) {
2567 /* Pre-v7 versions of the architecture implemented WFI via coprocessor
2568 * instructions rather than a separate instruction.
2570 if ((insn
& 0x0fff0fff) == 0x0e070f90) {
2571 /* 0,c7,c0,4: Standard v6 WFI (also used in some pre-v6 cores).
2572 * In v7, this must NOP.
2574 if (!arm_feature(env
, ARM_FEATURE_V7
)) {
2575 /* Wait for interrupt. */
2576 gen_set_pc_im(s
->pc
);
2577 s
->is_jmp
= DISAS_WFI
;
2582 if ((insn
& 0x0fff0fff) == 0x0e070f58) {
2583 /* 0,c7,c8,2: Not all pre-v6 cores implemented this WFI,
2584 * so this is slightly over-broad.
2586 if (!arm_feature(env
, ARM_FEATURE_V6
)) {
2587 /* Wait for interrupt. */
2588 gen_set_pc_im(s
->pc
);
2589 s
->is_jmp
= DISAS_WFI
;
2592 /* Otherwise fall through to handle via helper function.
2593 * In particular, on v7 and some v6 cores this is one of
2594 * the VA-PA registers.
2598 rd
= (insn
>> 12) & 0xf;
2600 if (cp15_tls_load_store(env
, s
, insn
, rd
))
2603 tmp2
= tcg_const_i32(insn
);
2604 if (insn
& ARM_CP_RW_BIT
) {
2605 tmp
= tcg_temp_new_i32();
2606 gen_helper_get_cp15(tmp
, cpu_env
, tmp2
);
2607 /* If the destination register is r15 then sets condition codes. */
2609 store_reg(s
, rd
, tmp
);
2611 tcg_temp_free_i32(tmp
);
2613 tmp
= load_reg(s
, rd
);
2614 gen_helper_set_cp15(cpu_env
, tmp2
, tmp
);
2615 tcg_temp_free_i32(tmp
);
2616 /* Normally we would always end the TB here, but Linux
2617 * arch/arm/mach-pxa/sleep.S expects two instructions following
2618 * an MMU enable to execute from cache. Imitate this behaviour. */
2619 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) ||
2620 (insn
& 0x0fff0fff) != 0x0e010f10)
2623 tcg_temp_free_i32(tmp2
);
2627 #define VFP_REG_SHR(x, n) (((n) > 0) ? (x) >> (n) : (x) << -(n))
2628 #define VFP_SREG(insn, bigbit, smallbit) \
2629 ((VFP_REG_SHR(insn, bigbit - 1) & 0x1e) | (((insn) >> (smallbit)) & 1))
2630 #define VFP_DREG(reg, insn, bigbit, smallbit) do { \
2631 if (arm_feature(env, ARM_FEATURE_VFP3)) { \
2632 reg = (((insn) >> (bigbit)) & 0x0f) \
2633 | (((insn) >> ((smallbit) - 4)) & 0x10); \
2635 if (insn & (1 << (smallbit))) \
2637 reg = ((insn) >> (bigbit)) & 0x0f; \
2640 #define VFP_SREG_D(insn) VFP_SREG(insn, 12, 22)
2641 #define VFP_DREG_D(reg, insn) VFP_DREG(reg, insn, 12, 22)
2642 #define VFP_SREG_N(insn) VFP_SREG(insn, 16, 7)
2643 #define VFP_DREG_N(reg, insn) VFP_DREG(reg, insn, 16, 7)
2644 #define VFP_SREG_M(insn) VFP_SREG(insn, 0, 5)
2645 #define VFP_DREG_M(reg, insn) VFP_DREG(reg, insn, 0, 5)
2647 /* Move between integer and VFP cores. */
2648 static TCGv
gen_vfp_mrs(void)
2650 TCGv tmp
= tcg_temp_new_i32();
2651 tcg_gen_mov_i32(tmp
, cpu_F0s
);
2655 static void gen_vfp_msr(TCGv tmp
)
2657 tcg_gen_mov_i32(cpu_F0s
, tmp
);
2658 tcg_temp_free_i32(tmp
);
2661 static void gen_neon_dup_u8(TCGv var
, int shift
)
2663 TCGv tmp
= tcg_temp_new_i32();
2665 tcg_gen_shri_i32(var
, var
, shift
);
2666 tcg_gen_ext8u_i32(var
, var
);
2667 tcg_gen_shli_i32(tmp
, var
, 8);
2668 tcg_gen_or_i32(var
, var
, tmp
);
2669 tcg_gen_shli_i32(tmp
, var
, 16);
2670 tcg_gen_or_i32(var
, var
, tmp
);
2671 tcg_temp_free_i32(tmp
);
2674 static void gen_neon_dup_low16(TCGv var
)
2676 TCGv tmp
= tcg_temp_new_i32();
2677 tcg_gen_ext16u_i32(var
, var
);
2678 tcg_gen_shli_i32(tmp
, var
, 16);
2679 tcg_gen_or_i32(var
, var
, tmp
);
2680 tcg_temp_free_i32(tmp
);
2683 static void gen_neon_dup_high16(TCGv var
)
2685 TCGv tmp
= tcg_temp_new_i32();
2686 tcg_gen_andi_i32(var
, var
, 0xffff0000);
2687 tcg_gen_shri_i32(tmp
, var
, 16);
2688 tcg_gen_or_i32(var
, var
, tmp
);
2689 tcg_temp_free_i32(tmp
);
2692 static TCGv
gen_load_and_replicate(DisasContext
*s
, TCGv addr
, int size
)
2694 /* Load a single Neon element and replicate into a 32 bit TCG reg */
2698 tmp
= gen_ld8u(addr
, IS_USER(s
));
2699 gen_neon_dup_u8(tmp
, 0);
2702 tmp
= gen_ld16u(addr
, IS_USER(s
));
2703 gen_neon_dup_low16(tmp
);
2706 tmp
= gen_ld32(addr
, IS_USER(s
));
2708 default: /* Avoid compiler warnings. */
2714 /* Disassemble a VFP instruction. Returns nonzero if an error occurred
2715 (ie. an undefined instruction). */
2716 static int disas_vfp_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
2718 uint32_t rd
, rn
, rm
, op
, i
, n
, offset
, delta_d
, delta_m
, bank_mask
;
2724 if (!arm_feature(env
, ARM_FEATURE_VFP
))
2727 if (!s
->vfp_enabled
) {
2728 /* VFP disabled. Only allow fmxr/fmrx to/from some control regs. */
2729 if ((insn
& 0x0fe00fff) != 0x0ee00a10)
2731 rn
= (insn
>> 16) & 0xf;
2732 if (rn
!= ARM_VFP_FPSID
&& rn
!= ARM_VFP_FPEXC
2733 && rn
!= ARM_VFP_MVFR1
&& rn
!= ARM_VFP_MVFR0
)
2736 dp
= ((insn
& 0xf00) == 0xb00);
2737 switch ((insn
>> 24) & 0xf) {
2739 if (insn
& (1 << 4)) {
2740 /* single register transfer */
2741 rd
= (insn
>> 12) & 0xf;
2746 VFP_DREG_N(rn
, insn
);
2749 if (insn
& 0x00c00060
2750 && !arm_feature(env
, ARM_FEATURE_NEON
))
2753 pass
= (insn
>> 21) & 1;
2754 if (insn
& (1 << 22)) {
2756 offset
= ((insn
>> 5) & 3) * 8;
2757 } else if (insn
& (1 << 5)) {
2759 offset
= (insn
& (1 << 6)) ? 16 : 0;
2764 if (insn
& ARM_CP_RW_BIT
) {
2766 tmp
= neon_load_reg(rn
, pass
);
2770 tcg_gen_shri_i32(tmp
, tmp
, offset
);
2771 if (insn
& (1 << 23))
2777 if (insn
& (1 << 23)) {
2779 tcg_gen_shri_i32(tmp
, tmp
, 16);
2785 tcg_gen_sari_i32(tmp
, tmp
, 16);
2794 store_reg(s
, rd
, tmp
);
2797 tmp
= load_reg(s
, rd
);
2798 if (insn
& (1 << 23)) {
2801 gen_neon_dup_u8(tmp
, 0);
2802 } else if (size
== 1) {
2803 gen_neon_dup_low16(tmp
);
2805 for (n
= 0; n
<= pass
* 2; n
++) {
2806 tmp2
= tcg_temp_new_i32();
2807 tcg_gen_mov_i32(tmp2
, tmp
);
2808 neon_store_reg(rn
, n
, tmp2
);
2810 neon_store_reg(rn
, n
, tmp
);
2815 tmp2
= neon_load_reg(rn
, pass
);
2816 gen_bfi(tmp
, tmp2
, tmp
, offset
, 0xff);
2817 tcg_temp_free_i32(tmp2
);
2820 tmp2
= neon_load_reg(rn
, pass
);
2821 gen_bfi(tmp
, tmp2
, tmp
, offset
, 0xffff);
2822 tcg_temp_free_i32(tmp2
);
2827 neon_store_reg(rn
, pass
, tmp
);
2831 if ((insn
& 0x6f) != 0x00)
2833 rn
= VFP_SREG_N(insn
);
2834 if (insn
& ARM_CP_RW_BIT
) {
2836 if (insn
& (1 << 21)) {
2837 /* system register */
2842 /* VFP2 allows access to FSID from userspace.
2843 VFP3 restricts all id registers to privileged
2846 && arm_feature(env
, ARM_FEATURE_VFP3
))
2848 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2853 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2855 case ARM_VFP_FPINST
:
2856 case ARM_VFP_FPINST2
:
2857 /* Not present in VFP3. */
2859 || arm_feature(env
, ARM_FEATURE_VFP3
))
2861 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2865 tmp
= load_cpu_field(vfp
.xregs
[ARM_VFP_FPSCR
]);
2866 tcg_gen_andi_i32(tmp
, tmp
, 0xf0000000);
2868 tmp
= tcg_temp_new_i32();
2869 gen_helper_vfp_get_fpscr(tmp
, cpu_env
);
2875 || !arm_feature(env
, ARM_FEATURE_VFP3
))
2877 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2883 gen_mov_F0_vreg(0, rn
);
2884 tmp
= gen_vfp_mrs();
2887 /* Set the 4 flag bits in the CPSR. */
2889 tcg_temp_free_i32(tmp
);
2891 store_reg(s
, rd
, tmp
);
2895 tmp
= load_reg(s
, rd
);
2896 if (insn
& (1 << 21)) {
2898 /* system register */
2903 /* Writes are ignored. */
2906 gen_helper_vfp_set_fpscr(cpu_env
, tmp
);
2907 tcg_temp_free_i32(tmp
);
2913 /* TODO: VFP subarchitecture support.
2914 * For now, keep the EN bit only */
2915 tcg_gen_andi_i32(tmp
, tmp
, 1 << 30);
2916 store_cpu_field(tmp
, vfp
.xregs
[rn
]);
2919 case ARM_VFP_FPINST
:
2920 case ARM_VFP_FPINST2
:
2921 store_cpu_field(tmp
, vfp
.xregs
[rn
]);
2928 gen_mov_vreg_F0(0, rn
);
2933 /* data processing */
2934 /* The opcode is in bits 23, 21, 20 and 6. */
2935 op
= ((insn
>> 20) & 8) | ((insn
>> 19) & 6) | ((insn
>> 6) & 1);
2939 rn
= ((insn
>> 15) & 0x1e) | ((insn
>> 7) & 1);
2941 /* rn is register number */
2942 VFP_DREG_N(rn
, insn
);
2945 if (op
== 15 && (rn
== 15 || ((rn
& 0x1c) == 0x18))) {
2946 /* Integer or single precision destination. */
2947 rd
= VFP_SREG_D(insn
);
2949 VFP_DREG_D(rd
, insn
);
2952 (((rn
& 0x1c) == 0x10) || ((rn
& 0x14) == 0x14))) {
2953 /* VCVT from int is always from S reg regardless of dp bit.
2954 * VCVT with immediate frac_bits has same format as SREG_M
2956 rm
= VFP_SREG_M(insn
);
2958 VFP_DREG_M(rm
, insn
);
2961 rn
= VFP_SREG_N(insn
);
2962 if (op
== 15 && rn
== 15) {
2963 /* Double precision destination. */
2964 VFP_DREG_D(rd
, insn
);
2966 rd
= VFP_SREG_D(insn
);
2968 /* NB that we implicitly rely on the encoding for the frac_bits
2969 * in VCVT of fixed to float being the same as that of an SREG_M
2971 rm
= VFP_SREG_M(insn
);
2974 veclen
= s
->vec_len
;
2975 if (op
== 15 && rn
> 3)
2978 /* Shut up compiler warnings. */
2989 /* Figure out what type of vector operation this is. */
2990 if ((rd
& bank_mask
) == 0) {
2995 delta_d
= (s
->vec_stride
>> 1) + 1;
2997 delta_d
= s
->vec_stride
+ 1;
2999 if ((rm
& bank_mask
) == 0) {
3000 /* mixed scalar/vector */
3009 /* Load the initial operands. */
3014 /* Integer source */
3015 gen_mov_F0_vreg(0, rm
);
3020 gen_mov_F0_vreg(dp
, rd
);
3021 gen_mov_F1_vreg(dp
, rm
);
3025 /* Compare with zero */
3026 gen_mov_F0_vreg(dp
, rd
);
3037 /* Source and destination the same. */
3038 gen_mov_F0_vreg(dp
, rd
);
3041 /* One source operand. */
3042 gen_mov_F0_vreg(dp
, rm
);
3046 /* Two source operands. */
3047 gen_mov_F0_vreg(dp
, rn
);
3048 gen_mov_F1_vreg(dp
, rm
);
3052 /* Perform the calculation. */
3054 case 0: /* VMLA: fd + (fn * fm) */
3055 /* Note that order of inputs to the add matters for NaNs */
3057 gen_mov_F0_vreg(dp
, rd
);
3060 case 1: /* VMLS: fd + -(fn * fm) */
3063 gen_mov_F0_vreg(dp
, rd
);
3066 case 2: /* VNMLS: -fd + (fn * fm) */
3067 /* Note that it isn't valid to replace (-A + B) with (B - A)
3068 * or similar plausible looking simplifications
3069 * because this will give wrong results for NaNs.
3072 gen_mov_F0_vreg(dp
, rd
);
3076 case 3: /* VNMLA: -fd + -(fn * fm) */
3079 gen_mov_F0_vreg(dp
, rd
);
3083 case 4: /* mul: fn * fm */
3086 case 5: /* nmul: -(fn * fm) */
3090 case 6: /* add: fn + fm */
3093 case 7: /* sub: fn - fm */
3096 case 8: /* div: fn / fm */
3099 case 14: /* fconst */
3100 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3103 n
= (insn
<< 12) & 0x80000000;
3104 i
= ((insn
>> 12) & 0x70) | (insn
& 0xf);
3111 tcg_gen_movi_i64(cpu_F0d
, ((uint64_t)n
) << 32);
3118 tcg_gen_movi_i32(cpu_F0s
, n
);
3121 case 15: /* extension space */
3135 case 4: /* vcvtb.f32.f16 */
3136 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3138 tmp
= gen_vfp_mrs();
3139 tcg_gen_ext16u_i32(tmp
, tmp
);
3140 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp
, cpu_env
);
3141 tcg_temp_free_i32(tmp
);
3143 case 5: /* vcvtt.f32.f16 */
3144 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3146 tmp
= gen_vfp_mrs();
3147 tcg_gen_shri_i32(tmp
, tmp
, 16);
3148 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp
, cpu_env
);
3149 tcg_temp_free_i32(tmp
);
3151 case 6: /* vcvtb.f16.f32 */
3152 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3154 tmp
= tcg_temp_new_i32();
3155 gen_helper_vfp_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
3156 gen_mov_F0_vreg(0, rd
);
3157 tmp2
= gen_vfp_mrs();
3158 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffff0000);
3159 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3160 tcg_temp_free_i32(tmp2
);
3163 case 7: /* vcvtt.f16.f32 */
3164 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3166 tmp
= tcg_temp_new_i32();
3167 gen_helper_vfp_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
3168 tcg_gen_shli_i32(tmp
, tmp
, 16);
3169 gen_mov_F0_vreg(0, rd
);
3170 tmp2
= gen_vfp_mrs();
3171 tcg_gen_ext16u_i32(tmp2
, tmp2
);
3172 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3173 tcg_temp_free_i32(tmp2
);
3185 case 11: /* cmpez */
3189 case 15: /* single<->double conversion */
3191 gen_helper_vfp_fcvtsd(cpu_F0s
, cpu_F0d
, cpu_env
);
3193 gen_helper_vfp_fcvtds(cpu_F0d
, cpu_F0s
, cpu_env
);
3195 case 16: /* fuito */
3196 gen_vfp_uito(dp
, 0);
3198 case 17: /* fsito */
3199 gen_vfp_sito(dp
, 0);
3201 case 20: /* fshto */
3202 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3204 gen_vfp_shto(dp
, 16 - rm
, 0);
3206 case 21: /* fslto */
3207 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3209 gen_vfp_slto(dp
, 32 - rm
, 0);
3211 case 22: /* fuhto */
3212 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3214 gen_vfp_uhto(dp
, 16 - rm
, 0);
3216 case 23: /* fulto */
3217 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3219 gen_vfp_ulto(dp
, 32 - rm
, 0);
3221 case 24: /* ftoui */
3222 gen_vfp_toui(dp
, 0);
3224 case 25: /* ftouiz */
3225 gen_vfp_touiz(dp
, 0);
3227 case 26: /* ftosi */
3228 gen_vfp_tosi(dp
, 0);
3230 case 27: /* ftosiz */
3231 gen_vfp_tosiz(dp
, 0);
3233 case 28: /* ftosh */
3234 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3236 gen_vfp_tosh(dp
, 16 - rm
, 0);
3238 case 29: /* ftosl */
3239 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3241 gen_vfp_tosl(dp
, 32 - rm
, 0);
3243 case 30: /* ftouh */
3244 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3246 gen_vfp_touh(dp
, 16 - rm
, 0);
3248 case 31: /* ftoul */
3249 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3251 gen_vfp_toul(dp
, 32 - rm
, 0);
3253 default: /* undefined */
3254 printf ("rn:%d\n", rn
);
3258 default: /* undefined */
3259 printf ("op:%d\n", op
);
3263 /* Write back the result. */
3264 if (op
== 15 && (rn
>= 8 && rn
<= 11))
3265 ; /* Comparison, do nothing. */
3266 else if (op
== 15 && dp
&& ((rn
& 0x1c) == 0x18))
3267 /* VCVT double to int: always integer result. */
3268 gen_mov_vreg_F0(0, rd
);
3269 else if (op
== 15 && rn
== 15)
3271 gen_mov_vreg_F0(!dp
, rd
);
3273 gen_mov_vreg_F0(dp
, rd
);
3275 /* break out of the loop if we have finished */
3279 if (op
== 15 && delta_m
== 0) {
3280 /* single source one-many */
3282 rd
= ((rd
+ delta_d
) & (bank_mask
- 1))
3284 gen_mov_vreg_F0(dp
, rd
);
3288 /* Setup the next operands. */
3290 rd
= ((rd
+ delta_d
) & (bank_mask
- 1))
3294 /* One source operand. */
3295 rm
= ((rm
+ delta_m
) & (bank_mask
- 1))
3297 gen_mov_F0_vreg(dp
, rm
);
3299 /* Two source operands. */
3300 rn
= ((rn
+ delta_d
) & (bank_mask
- 1))
3302 gen_mov_F0_vreg(dp
, rn
);
3304 rm
= ((rm
+ delta_m
) & (bank_mask
- 1))
3306 gen_mov_F1_vreg(dp
, rm
);
3314 if ((insn
& 0x03e00000) == 0x00400000) {
3315 /* two-register transfer */
3316 rn
= (insn
>> 16) & 0xf;
3317 rd
= (insn
>> 12) & 0xf;
3319 VFP_DREG_M(rm
, insn
);
3321 rm
= VFP_SREG_M(insn
);
3324 if (insn
& ARM_CP_RW_BIT
) {
3327 gen_mov_F0_vreg(0, rm
* 2);
3328 tmp
= gen_vfp_mrs();
3329 store_reg(s
, rd
, tmp
);
3330 gen_mov_F0_vreg(0, rm
* 2 + 1);
3331 tmp
= gen_vfp_mrs();
3332 store_reg(s
, rn
, tmp
);
3334 gen_mov_F0_vreg(0, rm
);
3335 tmp
= gen_vfp_mrs();
3336 store_reg(s
, rd
, tmp
);
3337 gen_mov_F0_vreg(0, rm
+ 1);
3338 tmp
= gen_vfp_mrs();
3339 store_reg(s
, rn
, tmp
);
3344 tmp
= load_reg(s
, rd
);
3346 gen_mov_vreg_F0(0, rm
* 2);
3347 tmp
= load_reg(s
, rn
);
3349 gen_mov_vreg_F0(0, rm
* 2 + 1);
3351 tmp
= load_reg(s
, rd
);
3353 gen_mov_vreg_F0(0, rm
);
3354 tmp
= load_reg(s
, rn
);
3356 gen_mov_vreg_F0(0, rm
+ 1);
3361 rn
= (insn
>> 16) & 0xf;
3363 VFP_DREG_D(rd
, insn
);
3365 rd
= VFP_SREG_D(insn
);
3366 if (s
->thumb
&& rn
== 15) {
3367 addr
= tcg_temp_new_i32();
3368 tcg_gen_movi_i32(addr
, s
->pc
& ~2);
3370 addr
= load_reg(s
, rn
);
3372 if ((insn
& 0x01200000) == 0x01000000) {
3373 /* Single load/store */
3374 offset
= (insn
& 0xff) << 2;
3375 if ((insn
& (1 << 23)) == 0)
3377 tcg_gen_addi_i32(addr
, addr
, offset
);
3378 if (insn
& (1 << 20)) {
3379 gen_vfp_ld(s
, dp
, addr
);
3380 gen_mov_vreg_F0(dp
, rd
);
3382 gen_mov_F0_vreg(dp
, rd
);
3383 gen_vfp_st(s
, dp
, addr
);
3385 tcg_temp_free_i32(addr
);
3387 /* load/store multiple */
3389 n
= (insn
>> 1) & 0x7f;
3393 if (insn
& (1 << 24)) /* pre-decrement */
3394 tcg_gen_addi_i32(addr
, addr
, -((insn
& 0xff) << 2));
3400 for (i
= 0; i
< n
; i
++) {
3401 if (insn
& ARM_CP_RW_BIT
) {
3403 gen_vfp_ld(s
, dp
, addr
);
3404 gen_mov_vreg_F0(dp
, rd
+ i
);
3407 gen_mov_F0_vreg(dp
, rd
+ i
);
3408 gen_vfp_st(s
, dp
, addr
);
3410 tcg_gen_addi_i32(addr
, addr
, offset
);
3412 if (insn
& (1 << 21)) {
3414 if (insn
& (1 << 24))
3415 offset
= -offset
* n
;
3416 else if (dp
&& (insn
& 1))
3422 tcg_gen_addi_i32(addr
, addr
, offset
);
3423 store_reg(s
, rn
, addr
);
3425 tcg_temp_free_i32(addr
);
3431 /* Should never happen. */
3437 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
3439 TranslationBlock
*tb
;
3442 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
3444 gen_set_pc_im(dest
);
3445 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3447 gen_set_pc_im(dest
);
3452 static inline void gen_jmp (DisasContext
*s
, uint32_t dest
)
3454 if (unlikely(s
->singlestep_enabled
)) {
3455 /* An indirect jump so that we still trigger the debug exception. */
3460 gen_goto_tb(s
, 0, dest
);
3461 s
->is_jmp
= DISAS_TB_JUMP
;
3465 static inline void gen_mulxy(TCGv t0
, TCGv t1
, int x
, int y
)
3468 tcg_gen_sari_i32(t0
, t0
, 16);
3472 tcg_gen_sari_i32(t1
, t1
, 16);
3475 tcg_gen_mul_i32(t0
, t0
, t1
);
3478 /* Return the mask of PSR bits set by a MSR instruction. */
3479 static uint32_t msr_mask(CPUState
*env
, DisasContext
*s
, int flags
, int spsr
) {
3483 if (flags
& (1 << 0))
3485 if (flags
& (1 << 1))
3487 if (flags
& (1 << 2))
3489 if (flags
& (1 << 3))
3492 /* Mask out undefined bits. */
3493 mask
&= ~CPSR_RESERVED
;
3494 if (!arm_feature(env
, ARM_FEATURE_V4T
))
3496 if (!arm_feature(env
, ARM_FEATURE_V5
))
3497 mask
&= ~CPSR_Q
; /* V5TE in reality*/
3498 if (!arm_feature(env
, ARM_FEATURE_V6
))
3499 mask
&= ~(CPSR_E
| CPSR_GE
);
3500 if (!arm_feature(env
, ARM_FEATURE_THUMB2
))
3502 /* Mask out execution state bits. */
3505 /* Mask out privileged bits. */
3511 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
3512 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int spsr
, TCGv t0
)
3516 /* ??? This is also undefined in system mode. */
3520 tmp
= load_cpu_field(spsr
);
3521 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
3522 tcg_gen_andi_i32(t0
, t0
, mask
);
3523 tcg_gen_or_i32(tmp
, tmp
, t0
);
3524 store_cpu_field(tmp
, spsr
);
3526 gen_set_cpsr(t0
, mask
);
3528 tcg_temp_free_i32(t0
);
3533 /* Returns nonzero if access to the PSR is not permitted. */
3534 static int gen_set_psr_im(DisasContext
*s
, uint32_t mask
, int spsr
, uint32_t val
)
3537 tmp
= tcg_temp_new_i32();
3538 tcg_gen_movi_i32(tmp
, val
);
3539 return gen_set_psr(s
, mask
, spsr
, tmp
);
3542 /* Generate an old-style exception return. Marks pc as dead. */
3543 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
3546 store_reg(s
, 15, pc
);
3547 tmp
= load_cpu_field(spsr
);
3548 gen_set_cpsr(tmp
, 0xffffffff);
3549 tcg_temp_free_i32(tmp
);
3550 s
->is_jmp
= DISAS_UPDATE
;
3553 /* Generate a v6 exception return. Marks both values as dead. */
3554 static void gen_rfe(DisasContext
*s
, TCGv pc
, TCGv cpsr
)
3556 gen_set_cpsr(cpsr
, 0xffffffff);
3557 tcg_temp_free_i32(cpsr
);
3558 store_reg(s
, 15, pc
);
3559 s
->is_jmp
= DISAS_UPDATE
;
3563 gen_set_condexec (DisasContext
*s
)
3565 if (s
->condexec_mask
) {
3566 uint32_t val
= (s
->condexec_cond
<< 4) | (s
->condexec_mask
>> 1);
3567 TCGv tmp
= tcg_temp_new_i32();
3568 tcg_gen_movi_i32(tmp
, val
);
3569 store_cpu_field(tmp
, condexec_bits
);
3573 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
)
3575 gen_set_condexec(s
);
3576 gen_set_pc_im(s
->pc
- offset
);
3577 gen_exception(excp
);
3578 s
->is_jmp
= DISAS_JUMP
;
3581 static void gen_nop_hint(DisasContext
*s
, int val
)
3585 gen_set_pc_im(s
->pc
);
3586 s
->is_jmp
= DISAS_WFI
;
3590 /* TODO: Implement SEV and WFE. May help SMP performance. */
3596 #define CPU_V001 cpu_V0, cpu_V0, cpu_V1
3598 static inline void gen_neon_add(int size
, TCGv t0
, TCGv t1
)
3601 case 0: gen_helper_neon_add_u8(t0
, t0
, t1
); break;
3602 case 1: gen_helper_neon_add_u16(t0
, t0
, t1
); break;
3603 case 2: tcg_gen_add_i32(t0
, t0
, t1
); break;
3608 static inline void gen_neon_rsb(int size
, TCGv t0
, TCGv t1
)
3611 case 0: gen_helper_neon_sub_u8(t0
, t1
, t0
); break;
3612 case 1: gen_helper_neon_sub_u16(t0
, t1
, t0
); break;
3613 case 2: tcg_gen_sub_i32(t0
, t1
, t0
); break;
3618 /* 32-bit pairwise ops end up the same as the elementwise versions. */
3619 #define gen_helper_neon_pmax_s32 gen_helper_neon_max_s32
3620 #define gen_helper_neon_pmax_u32 gen_helper_neon_max_u32
3621 #define gen_helper_neon_pmin_s32 gen_helper_neon_min_s32
3622 #define gen_helper_neon_pmin_u32 gen_helper_neon_min_u32
3624 #define GEN_NEON_INTEGER_OP_ENV(name) do { \
3625 switch ((size << 1) | u) { \
3627 gen_helper_neon_##name##_s8(tmp, cpu_env, tmp, tmp2); \
3630 gen_helper_neon_##name##_u8(tmp, cpu_env, tmp, tmp2); \
3633 gen_helper_neon_##name##_s16(tmp, cpu_env, tmp, tmp2); \
3636 gen_helper_neon_##name##_u16(tmp, cpu_env, tmp, tmp2); \
3639 gen_helper_neon_##name##_s32(tmp, cpu_env, tmp, tmp2); \
3642 gen_helper_neon_##name##_u32(tmp, cpu_env, tmp, tmp2); \
3644 default: return 1; \
3647 #define GEN_NEON_INTEGER_OP(name) do { \
3648 switch ((size << 1) | u) { \
3650 gen_helper_neon_##name##_s8(tmp, tmp, tmp2); \
3653 gen_helper_neon_##name##_u8(tmp, tmp, tmp2); \
3656 gen_helper_neon_##name##_s16(tmp, tmp, tmp2); \
3659 gen_helper_neon_##name##_u16(tmp, tmp, tmp2); \
3662 gen_helper_neon_##name##_s32(tmp, tmp, tmp2); \
3665 gen_helper_neon_##name##_u32(tmp, tmp, tmp2); \
3667 default: return 1; \
3670 static TCGv
neon_load_scratch(int scratch
)
3672 TCGv tmp
= tcg_temp_new_i32();
3673 tcg_gen_ld_i32(tmp
, cpu_env
, offsetof(CPUARMState
, vfp
.scratch
[scratch
]));
3677 static void neon_store_scratch(int scratch
, TCGv var
)
3679 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUARMState
, vfp
.scratch
[scratch
]));
3680 tcg_temp_free_i32(var
);
3683 static inline TCGv
neon_get_scalar(int size
, int reg
)
3687 tmp
= neon_load_reg(reg
& 7, reg
>> 4);
3689 gen_neon_dup_high16(tmp
);
3691 gen_neon_dup_low16(tmp
);
3694 tmp
= neon_load_reg(reg
& 15, reg
>> 4);
3699 static int gen_neon_unzip(int rd
, int rm
, int size
, int q
)
3702 if (!q
&& size
== 2) {
3705 tmp
= tcg_const_i32(rd
);
3706 tmp2
= tcg_const_i32(rm
);
3710 gen_helper_neon_qunzip8(tmp
, tmp2
);
3713 gen_helper_neon_qunzip16(tmp
, tmp2
);
3716 gen_helper_neon_qunzip32(tmp
, tmp2
);
3724 gen_helper_neon_unzip8(tmp
, tmp2
);
3727 gen_helper_neon_unzip16(tmp
, tmp2
);
3733 tcg_temp_free_i32(tmp
);
3734 tcg_temp_free_i32(tmp2
);
3738 static int gen_neon_zip(int rd
, int rm
, int size
, int q
)
3741 if (!q
&& size
== 2) {
3744 tmp
= tcg_const_i32(rd
);
3745 tmp2
= tcg_const_i32(rm
);
3749 gen_helper_neon_qzip8(tmp
, tmp2
);
3752 gen_helper_neon_qzip16(tmp
, tmp2
);
3755 gen_helper_neon_qzip32(tmp
, tmp2
);
3763 gen_helper_neon_zip8(tmp
, tmp2
);
3766 gen_helper_neon_zip16(tmp
, tmp2
);
3772 tcg_temp_free_i32(tmp
);
3773 tcg_temp_free_i32(tmp2
);
3777 static void gen_neon_trn_u8(TCGv t0
, TCGv t1
)
3781 rd
= tcg_temp_new_i32();
3782 tmp
= tcg_temp_new_i32();
3784 tcg_gen_shli_i32(rd
, t0
, 8);
3785 tcg_gen_andi_i32(rd
, rd
, 0xff00ff00);
3786 tcg_gen_andi_i32(tmp
, t1
, 0x00ff00ff);
3787 tcg_gen_or_i32(rd
, rd
, tmp
);
3789 tcg_gen_shri_i32(t1
, t1
, 8);
3790 tcg_gen_andi_i32(t1
, t1
, 0x00ff00ff);
3791 tcg_gen_andi_i32(tmp
, t0
, 0xff00ff00);
3792 tcg_gen_or_i32(t1
, t1
, tmp
);
3793 tcg_gen_mov_i32(t0
, rd
);
3795 tcg_temp_free_i32(tmp
);
3796 tcg_temp_free_i32(rd
);
3799 static void gen_neon_trn_u16(TCGv t0
, TCGv t1
)
3803 rd
= tcg_temp_new_i32();
3804 tmp
= tcg_temp_new_i32();
3806 tcg_gen_shli_i32(rd
, t0
, 16);
3807 tcg_gen_andi_i32(tmp
, t1
, 0xffff);
3808 tcg_gen_or_i32(rd
, rd
, tmp
);
3809 tcg_gen_shri_i32(t1
, t1
, 16);
3810 tcg_gen_andi_i32(tmp
, t0
, 0xffff0000);
3811 tcg_gen_or_i32(t1
, t1
, tmp
);
3812 tcg_gen_mov_i32(t0
, rd
);
3814 tcg_temp_free_i32(tmp
);
3815 tcg_temp_free_i32(rd
);
3823 } neon_ls_element_type
[11] = {
3837 /* Translate a NEON load/store element instruction. Return nonzero if the
3838 instruction is invalid. */
3839 static int disas_neon_ls_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
3858 if (!s
->vfp_enabled
)
3860 VFP_DREG_D(rd
, insn
);
3861 rn
= (insn
>> 16) & 0xf;
3863 load
= (insn
& (1 << 21)) != 0;
3864 if ((insn
& (1 << 23)) == 0) {
3865 /* Load store all elements. */
3866 op
= (insn
>> 8) & 0xf;
3867 size
= (insn
>> 6) & 3;
3870 /* Catch UNDEF cases for bad values of align field */
3873 if (((insn
>> 5) & 1) == 1) {
3878 if (((insn
>> 4) & 3) == 3) {
3885 nregs
= neon_ls_element_type
[op
].nregs
;
3886 interleave
= neon_ls_element_type
[op
].interleave
;
3887 spacing
= neon_ls_element_type
[op
].spacing
;
3888 if (size
== 3 && (interleave
| spacing
) != 1)
3890 addr
= tcg_temp_new_i32();
3891 load_reg_var(s
, addr
, rn
);
3892 stride
= (1 << size
) * interleave
;
3893 for (reg
= 0; reg
< nregs
; reg
++) {
3894 if (interleave
> 2 || (interleave
== 2 && nregs
== 2)) {
3895 load_reg_var(s
, addr
, rn
);
3896 tcg_gen_addi_i32(addr
, addr
, (1 << size
) * reg
);
3897 } else if (interleave
== 2 && nregs
== 4 && reg
== 2) {
3898 load_reg_var(s
, addr
, rn
);
3899 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
3903 tmp64
= gen_ld64(addr
, IS_USER(s
));
3904 neon_store_reg64(tmp64
, rd
);
3905 tcg_temp_free_i64(tmp64
);
3907 tmp64
= tcg_temp_new_i64();
3908 neon_load_reg64(tmp64
, rd
);
3909 gen_st64(tmp64
, addr
, IS_USER(s
));
3911 tcg_gen_addi_i32(addr
, addr
, stride
);
3913 for (pass
= 0; pass
< 2; pass
++) {
3916 tmp
= gen_ld32(addr
, IS_USER(s
));
3917 neon_store_reg(rd
, pass
, tmp
);
3919 tmp
= neon_load_reg(rd
, pass
);
3920 gen_st32(tmp
, addr
, IS_USER(s
));
3922 tcg_gen_addi_i32(addr
, addr
, stride
);
3923 } else if (size
== 1) {
3925 tmp
= gen_ld16u(addr
, IS_USER(s
));
3926 tcg_gen_addi_i32(addr
, addr
, stride
);
3927 tmp2
= gen_ld16u(addr
, IS_USER(s
));
3928 tcg_gen_addi_i32(addr
, addr
, stride
);
3929 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
3930 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3931 tcg_temp_free_i32(tmp2
);
3932 neon_store_reg(rd
, pass
, tmp
);
3934 tmp
= neon_load_reg(rd
, pass
);
3935 tmp2
= tcg_temp_new_i32();
3936 tcg_gen_shri_i32(tmp2
, tmp
, 16);
3937 gen_st16(tmp
, addr
, IS_USER(s
));
3938 tcg_gen_addi_i32(addr
, addr
, stride
);
3939 gen_st16(tmp2
, addr
, IS_USER(s
));
3940 tcg_gen_addi_i32(addr
, addr
, stride
);
3942 } else /* size == 0 */ {
3945 for (n
= 0; n
< 4; n
++) {
3946 tmp
= gen_ld8u(addr
, IS_USER(s
));
3947 tcg_gen_addi_i32(addr
, addr
, stride
);
3951 tcg_gen_shli_i32(tmp
, tmp
, n
* 8);
3952 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
3953 tcg_temp_free_i32(tmp
);
3956 neon_store_reg(rd
, pass
, tmp2
);
3958 tmp2
= neon_load_reg(rd
, pass
);
3959 for (n
= 0; n
< 4; n
++) {
3960 tmp
= tcg_temp_new_i32();
3962 tcg_gen_mov_i32(tmp
, tmp2
);
3964 tcg_gen_shri_i32(tmp
, tmp2
, n
* 8);
3966 gen_st8(tmp
, addr
, IS_USER(s
));
3967 tcg_gen_addi_i32(addr
, addr
, stride
);
3969 tcg_temp_free_i32(tmp2
);
3976 tcg_temp_free_i32(addr
);
3979 size
= (insn
>> 10) & 3;
3981 /* Load single element to all lanes. */
3982 int a
= (insn
>> 4) & 1;
3986 size
= (insn
>> 6) & 3;
3987 nregs
= ((insn
>> 8) & 3) + 1;
3990 if (nregs
!= 4 || a
== 0) {
3993 /* For VLD4 size==3 a == 1 means 32 bits at 16 byte alignment */
3996 if (nregs
== 1 && a
== 1 && size
== 0) {
3999 if (nregs
== 3 && a
== 1) {
4002 addr
= tcg_temp_new_i32();
4003 load_reg_var(s
, addr
, rn
);
4005 /* VLD1 to all lanes: bit 5 indicates how many Dregs to write */
4006 tmp
= gen_load_and_replicate(s
, addr
, size
);
4007 tcg_gen_st_i32(tmp
, cpu_env
, neon_reg_offset(rd
, 0));
4008 tcg_gen_st_i32(tmp
, cpu_env
, neon_reg_offset(rd
, 1));
4009 if (insn
& (1 << 5)) {
4010 tcg_gen_st_i32(tmp
, cpu_env
, neon_reg_offset(rd
+ 1, 0));
4011 tcg_gen_st_i32(tmp
, cpu_env
, neon_reg_offset(rd
+ 1, 1));
4013 tcg_temp_free_i32(tmp
);
4015 /* VLD2/3/4 to all lanes: bit 5 indicates register stride */
4016 stride
= (insn
& (1 << 5)) ? 2 : 1;
4017 for (reg
= 0; reg
< nregs
; reg
++) {
4018 tmp
= gen_load_and_replicate(s
, addr
, size
);
4019 tcg_gen_st_i32(tmp
, cpu_env
, neon_reg_offset(rd
, 0));
4020 tcg_gen_st_i32(tmp
, cpu_env
, neon_reg_offset(rd
, 1));
4021 tcg_temp_free_i32(tmp
);
4022 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
4026 tcg_temp_free_i32(addr
);
4027 stride
= (1 << size
) * nregs
;
4029 /* Single element. */
4030 int idx
= (insn
>> 4) & 0xf;
4031 pass
= (insn
>> 7) & 1;
4034 shift
= ((insn
>> 5) & 3) * 8;
4038 shift
= ((insn
>> 6) & 1) * 16;
4039 stride
= (insn
& (1 << 5)) ? 2 : 1;
4043 stride
= (insn
& (1 << 6)) ? 2 : 1;
4048 nregs
= ((insn
>> 8) & 3) + 1;
4049 /* Catch the UNDEF cases. This is unavoidably a bit messy. */
4052 if (((idx
& (1 << size
)) != 0) ||
4053 (size
== 2 && ((idx
& 3) == 1 || (idx
& 3) == 2))) {
4058 if ((idx
& 1) != 0) {
4063 if (size
== 2 && (idx
& 2) != 0) {
4068 if ((size
== 2) && ((idx
& 3) == 3)) {
4075 if ((rd
+ stride
* (nregs
- 1)) > 31) {
4076 /* Attempts to write off the end of the register file
4077 * are UNPREDICTABLE; we choose to UNDEF because otherwise
4078 * the neon_load_reg() would write off the end of the array.
4082 addr
= tcg_temp_new_i32();
4083 load_reg_var(s
, addr
, rn
);
4084 for (reg
= 0; reg
< nregs
; reg
++) {
4088 tmp
= gen_ld8u(addr
, IS_USER(s
));
4091 tmp
= gen_ld16u(addr
, IS_USER(s
));
4094 tmp
= gen_ld32(addr
, IS_USER(s
));
4096 default: /* Avoid compiler warnings. */
4100 tmp2
= neon_load_reg(rd
, pass
);
4101 gen_bfi(tmp
, tmp2
, tmp
, shift
, size
? 0xffff : 0xff);
4102 tcg_temp_free_i32(tmp2
);
4104 neon_store_reg(rd
, pass
, tmp
);
4105 } else { /* Store */
4106 tmp
= neon_load_reg(rd
, pass
);
4108 tcg_gen_shri_i32(tmp
, tmp
, shift
);
4111 gen_st8(tmp
, addr
, IS_USER(s
));
4114 gen_st16(tmp
, addr
, IS_USER(s
));
4117 gen_st32(tmp
, addr
, IS_USER(s
));
4122 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
4124 tcg_temp_free_i32(addr
);
4125 stride
= nregs
* (1 << size
);
4131 base
= load_reg(s
, rn
);
4133 tcg_gen_addi_i32(base
, base
, stride
);
4136 index
= load_reg(s
, rm
);
4137 tcg_gen_add_i32(base
, base
, index
);
4138 tcg_temp_free_i32(index
);
4140 store_reg(s
, rn
, base
);
4145 /* Bitwise select. dest = c ? t : f. Clobbers T and F. */
4146 static void gen_neon_bsl(TCGv dest
, TCGv t
, TCGv f
, TCGv c
)
4148 tcg_gen_and_i32(t
, t
, c
);
4149 tcg_gen_andc_i32(f
, f
, c
);
4150 tcg_gen_or_i32(dest
, t
, f
);
4153 static inline void gen_neon_narrow(int size
, TCGv dest
, TCGv_i64 src
)
4156 case 0: gen_helper_neon_narrow_u8(dest
, src
); break;
4157 case 1: gen_helper_neon_narrow_u16(dest
, src
); break;
4158 case 2: tcg_gen_trunc_i64_i32(dest
, src
); break;
4163 static inline void gen_neon_narrow_sats(int size
, TCGv dest
, TCGv_i64 src
)
4166 case 0: gen_helper_neon_narrow_sat_s8(dest
, src
); break;
4167 case 1: gen_helper_neon_narrow_sat_s16(dest
, src
); break;
4168 case 2: gen_helper_neon_narrow_sat_s32(dest
, src
); break;
4173 static inline void gen_neon_narrow_satu(int size
, TCGv dest
, TCGv_i64 src
)
4176 case 0: gen_helper_neon_narrow_sat_u8(dest
, src
); break;
4177 case 1: gen_helper_neon_narrow_sat_u16(dest
, src
); break;
4178 case 2: gen_helper_neon_narrow_sat_u32(dest
, src
); break;
4183 static inline void gen_neon_unarrow_sats(int size
, TCGv dest
, TCGv_i64 src
)
4186 case 0: gen_helper_neon_unarrow_sat8(dest
, src
); break;
4187 case 1: gen_helper_neon_unarrow_sat16(dest
, src
); break;
4188 case 2: gen_helper_neon_unarrow_sat32(dest
, src
); break;
4193 static inline void gen_neon_shift_narrow(int size
, TCGv var
, TCGv shift
,
4199 case 1: gen_helper_neon_rshl_u16(var
, var
, shift
); break;
4200 case 2: gen_helper_neon_rshl_u32(var
, var
, shift
); break;
4205 case 1: gen_helper_neon_rshl_s16(var
, var
, shift
); break;
4206 case 2: gen_helper_neon_rshl_s32(var
, var
, shift
); break;
4213 case 1: gen_helper_neon_shl_u16(var
, var
, shift
); break;
4214 case 2: gen_helper_neon_shl_u32(var
, var
, shift
); break;
4219 case 1: gen_helper_neon_shl_s16(var
, var
, shift
); break;
4220 case 2: gen_helper_neon_shl_s32(var
, var
, shift
); break;
4227 static inline void gen_neon_widen(TCGv_i64 dest
, TCGv src
, int size
, int u
)
4231 case 0: gen_helper_neon_widen_u8(dest
, src
); break;
4232 case 1: gen_helper_neon_widen_u16(dest
, src
); break;
4233 case 2: tcg_gen_extu_i32_i64(dest
, src
); break;
4238 case 0: gen_helper_neon_widen_s8(dest
, src
); break;
4239 case 1: gen_helper_neon_widen_s16(dest
, src
); break;
4240 case 2: tcg_gen_ext_i32_i64(dest
, src
); break;
4244 tcg_temp_free_i32(src
);
4247 static inline void gen_neon_addl(int size
)
4250 case 0: gen_helper_neon_addl_u16(CPU_V001
); break;
4251 case 1: gen_helper_neon_addl_u32(CPU_V001
); break;
4252 case 2: tcg_gen_add_i64(CPU_V001
); break;
4257 static inline void gen_neon_subl(int size
)
4260 case 0: gen_helper_neon_subl_u16(CPU_V001
); break;
4261 case 1: gen_helper_neon_subl_u32(CPU_V001
); break;
4262 case 2: tcg_gen_sub_i64(CPU_V001
); break;
4267 static inline void gen_neon_negl(TCGv_i64 var
, int size
)
4270 case 0: gen_helper_neon_negl_u16(var
, var
); break;
4271 case 1: gen_helper_neon_negl_u32(var
, var
); break;
4272 case 2: gen_helper_neon_negl_u64(var
, var
); break;
4277 static inline void gen_neon_addl_saturate(TCGv_i64 op0
, TCGv_i64 op1
, int size
)
4280 case 1: gen_helper_neon_addl_saturate_s32(op0
, op0
, op1
); break;
4281 case 2: gen_helper_neon_addl_saturate_s64(op0
, op0
, op1
); break;
4286 static inline void gen_neon_mull(TCGv_i64 dest
, TCGv a
, TCGv b
, int size
, int u
)
4290 switch ((size
<< 1) | u
) {
4291 case 0: gen_helper_neon_mull_s8(dest
, a
, b
); break;
4292 case 1: gen_helper_neon_mull_u8(dest
, a
, b
); break;
4293 case 2: gen_helper_neon_mull_s16(dest
, a
, b
); break;
4294 case 3: gen_helper_neon_mull_u16(dest
, a
, b
); break;
4296 tmp
= gen_muls_i64_i32(a
, b
);
4297 tcg_gen_mov_i64(dest
, tmp
);
4298 tcg_temp_free_i64(tmp
);
4301 tmp
= gen_mulu_i64_i32(a
, b
);
4302 tcg_gen_mov_i64(dest
, tmp
);
4303 tcg_temp_free_i64(tmp
);
4308 /* gen_helper_neon_mull_[su]{8|16} do not free their parameters.
4309 Don't forget to clean them now. */
4311 tcg_temp_free_i32(a
);
4312 tcg_temp_free_i32(b
);
4316 static void gen_neon_narrow_op(int op
, int u
, int size
, TCGv dest
, TCGv_i64 src
)
4320 gen_neon_unarrow_sats(size
, dest
, src
);
4322 gen_neon_narrow(size
, dest
, src
);
4326 gen_neon_narrow_satu(size
, dest
, src
);
4328 gen_neon_narrow_sats(size
, dest
, src
);
4333 /* Symbolic constants for op fields for Neon 3-register same-length.
4334 * The values correspond to bits [11:8,4]; see the ARM ARM DDI0406B
4337 #define NEON_3R_VHADD 0
4338 #define NEON_3R_VQADD 1
4339 #define NEON_3R_VRHADD 2
4340 #define NEON_3R_LOGIC 3 /* VAND,VBIC,VORR,VMOV,VORN,VEOR,VBIF,VBIT,VBSL */
4341 #define NEON_3R_VHSUB 4
4342 #define NEON_3R_VQSUB 5
4343 #define NEON_3R_VCGT 6
4344 #define NEON_3R_VCGE 7
4345 #define NEON_3R_VSHL 8
4346 #define NEON_3R_VQSHL 9
4347 #define NEON_3R_VRSHL 10
4348 #define NEON_3R_VQRSHL 11
4349 #define NEON_3R_VMAX 12
4350 #define NEON_3R_VMIN 13
4351 #define NEON_3R_VABD 14
4352 #define NEON_3R_VABA 15
4353 #define NEON_3R_VADD_VSUB 16
4354 #define NEON_3R_VTST_VCEQ 17
4355 #define NEON_3R_VML 18 /* VMLA, VMLAL, VMLS, VMLSL */
4356 #define NEON_3R_VMUL 19
4357 #define NEON_3R_VPMAX 20
4358 #define NEON_3R_VPMIN 21
4359 #define NEON_3R_VQDMULH_VQRDMULH 22
4360 #define NEON_3R_VPADD 23
4361 #define NEON_3R_FLOAT_ARITH 26 /* float VADD, VSUB, VPADD, VABD */
4362 #define NEON_3R_FLOAT_MULTIPLY 27 /* float VMLA, VMLS, VMUL */
4363 #define NEON_3R_FLOAT_CMP 28 /* float VCEQ, VCGE, VCGT */
4364 #define NEON_3R_FLOAT_ACMP 29 /* float VACGE, VACGT, VACLE, VACLT */
4365 #define NEON_3R_FLOAT_MINMAX 30 /* float VMIN, VMAX */
4366 #define NEON_3R_VRECPS_VRSQRTS 31 /* float VRECPS, VRSQRTS */
4368 static const uint8_t neon_3r_sizes
[] = {
4369 [NEON_3R_VHADD
] = 0x7,
4370 [NEON_3R_VQADD
] = 0xf,
4371 [NEON_3R_VRHADD
] = 0x7,
4372 [NEON_3R_LOGIC
] = 0xf, /* size field encodes op type */
4373 [NEON_3R_VHSUB
] = 0x7,
4374 [NEON_3R_VQSUB
] = 0xf,
4375 [NEON_3R_VCGT
] = 0x7,
4376 [NEON_3R_VCGE
] = 0x7,
4377 [NEON_3R_VSHL
] = 0xf,
4378 [NEON_3R_VQSHL
] = 0xf,
4379 [NEON_3R_VRSHL
] = 0xf,
4380 [NEON_3R_VQRSHL
] = 0xf,
4381 [NEON_3R_VMAX
] = 0x7,
4382 [NEON_3R_VMIN
] = 0x7,
4383 [NEON_3R_VABD
] = 0x7,
4384 [NEON_3R_VABA
] = 0x7,
4385 [NEON_3R_VADD_VSUB
] = 0xf,
4386 [NEON_3R_VTST_VCEQ
] = 0x7,
4387 [NEON_3R_VML
] = 0x7,
4388 [NEON_3R_VMUL
] = 0x7,
4389 [NEON_3R_VPMAX
] = 0x7,
4390 [NEON_3R_VPMIN
] = 0x7,
4391 [NEON_3R_VQDMULH_VQRDMULH
] = 0x6,
4392 [NEON_3R_VPADD
] = 0x7,
4393 [NEON_3R_FLOAT_ARITH
] = 0x5, /* size bit 1 encodes op */
4394 [NEON_3R_FLOAT_MULTIPLY
] = 0x5, /* size bit 1 encodes op */
4395 [NEON_3R_FLOAT_CMP
] = 0x5, /* size bit 1 encodes op */
4396 [NEON_3R_FLOAT_ACMP
] = 0x5, /* size bit 1 encodes op */
4397 [NEON_3R_FLOAT_MINMAX
] = 0x5, /* size bit 1 encodes op */
4398 [NEON_3R_VRECPS_VRSQRTS
] = 0x5, /* size bit 1 encodes op */
4401 /* Symbolic constants for op fields for Neon 2-register miscellaneous.
4402 * The values correspond to bits [17:16,10:7]; see the ARM ARM DDI0406B
4405 #define NEON_2RM_VREV64 0
4406 #define NEON_2RM_VREV32 1
4407 #define NEON_2RM_VREV16 2
4408 #define NEON_2RM_VPADDL 4
4409 #define NEON_2RM_VPADDL_U 5
4410 #define NEON_2RM_VCLS 8
4411 #define NEON_2RM_VCLZ 9
4412 #define NEON_2RM_VCNT 10
4413 #define NEON_2RM_VMVN 11
4414 #define NEON_2RM_VPADAL 12
4415 #define NEON_2RM_VPADAL_U 13
4416 #define NEON_2RM_VQABS 14
4417 #define NEON_2RM_VQNEG 15
4418 #define NEON_2RM_VCGT0 16
4419 #define NEON_2RM_VCGE0 17
4420 #define NEON_2RM_VCEQ0 18
4421 #define NEON_2RM_VCLE0 19
4422 #define NEON_2RM_VCLT0 20
4423 #define NEON_2RM_VABS 22
4424 #define NEON_2RM_VNEG 23
4425 #define NEON_2RM_VCGT0_F 24
4426 #define NEON_2RM_VCGE0_F 25
4427 #define NEON_2RM_VCEQ0_F 26
4428 #define NEON_2RM_VCLE0_F 27
4429 #define NEON_2RM_VCLT0_F 28
4430 #define NEON_2RM_VABS_F 30
4431 #define NEON_2RM_VNEG_F 31
4432 #define NEON_2RM_VSWP 32
4433 #define NEON_2RM_VTRN 33
4434 #define NEON_2RM_VUZP 34
4435 #define NEON_2RM_VZIP 35
4436 #define NEON_2RM_VMOVN 36 /* Includes VQMOVN, VQMOVUN */
4437 #define NEON_2RM_VQMOVN 37 /* Includes VQMOVUN */
4438 #define NEON_2RM_VSHLL 38
4439 #define NEON_2RM_VCVT_F16_F32 44
4440 #define NEON_2RM_VCVT_F32_F16 46
4441 #define NEON_2RM_VRECPE 56
4442 #define NEON_2RM_VRSQRTE 57
4443 #define NEON_2RM_VRECPE_F 58
4444 #define NEON_2RM_VRSQRTE_F 59
4445 #define NEON_2RM_VCVT_FS 60
4446 #define NEON_2RM_VCVT_FU 61
4447 #define NEON_2RM_VCVT_SF 62
4448 #define NEON_2RM_VCVT_UF 63
4450 static int neon_2rm_is_float_op(int op
)
4452 /* Return true if this neon 2reg-misc op is float-to-float */
4453 return (op
== NEON_2RM_VABS_F
|| op
== NEON_2RM_VNEG_F
||
4454 op
>= NEON_2RM_VRECPE_F
);
4457 /* Each entry in this array has bit n set if the insn allows
4458 * size value n (otherwise it will UNDEF). Since unallocated
4459 * op values will have no bits set they always UNDEF.
4461 static const uint8_t neon_2rm_sizes
[] = {
4462 [NEON_2RM_VREV64
] = 0x7,
4463 [NEON_2RM_VREV32
] = 0x3,
4464 [NEON_2RM_VREV16
] = 0x1,
4465 [NEON_2RM_VPADDL
] = 0x7,
4466 [NEON_2RM_VPADDL_U
] = 0x7,
4467 [NEON_2RM_VCLS
] = 0x7,
4468 [NEON_2RM_VCLZ
] = 0x7,
4469 [NEON_2RM_VCNT
] = 0x1,
4470 [NEON_2RM_VMVN
] = 0x1,
4471 [NEON_2RM_VPADAL
] = 0x7,
4472 [NEON_2RM_VPADAL_U
] = 0x7,
4473 [NEON_2RM_VQABS
] = 0x7,
4474 [NEON_2RM_VQNEG
] = 0x7,
4475 [NEON_2RM_VCGT0
] = 0x7,
4476 [NEON_2RM_VCGE0
] = 0x7,
4477 [NEON_2RM_VCEQ0
] = 0x7,
4478 [NEON_2RM_VCLE0
] = 0x7,
4479 [NEON_2RM_VCLT0
] = 0x7,
4480 [NEON_2RM_VABS
] = 0x7,
4481 [NEON_2RM_VNEG
] = 0x7,
4482 [NEON_2RM_VCGT0_F
] = 0x4,
4483 [NEON_2RM_VCGE0_F
] = 0x4,
4484 [NEON_2RM_VCEQ0_F
] = 0x4,
4485 [NEON_2RM_VCLE0_F
] = 0x4,
4486 [NEON_2RM_VCLT0_F
] = 0x4,
4487 [NEON_2RM_VABS_F
] = 0x4,
4488 [NEON_2RM_VNEG_F
] = 0x4,
4489 [NEON_2RM_VSWP
] = 0x1,
4490 [NEON_2RM_VTRN
] = 0x7,
4491 [NEON_2RM_VUZP
] = 0x7,
4492 [NEON_2RM_VZIP
] = 0x7,
4493 [NEON_2RM_VMOVN
] = 0x7,
4494 [NEON_2RM_VQMOVN
] = 0x7,
4495 [NEON_2RM_VSHLL
] = 0x7,
4496 [NEON_2RM_VCVT_F16_F32
] = 0x2,
4497 [NEON_2RM_VCVT_F32_F16
] = 0x2,
4498 [NEON_2RM_VRECPE
] = 0x4,
4499 [NEON_2RM_VRSQRTE
] = 0x4,
4500 [NEON_2RM_VRECPE_F
] = 0x4,
4501 [NEON_2RM_VRSQRTE_F
] = 0x4,
4502 [NEON_2RM_VCVT_FS
] = 0x4,
4503 [NEON_2RM_VCVT_FU
] = 0x4,
4504 [NEON_2RM_VCVT_SF
] = 0x4,
4505 [NEON_2RM_VCVT_UF
] = 0x4,
4508 /* Translate a NEON data processing instruction. Return nonzero if the
4509 instruction is invalid.
4510 We process data in a mixture of 32-bit and 64-bit chunks.
4511 Mostly we use 32-bit chunks so we can use normal scalar instructions. */
4513 static int disas_neon_data_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
4525 TCGv tmp
, tmp2
, tmp3
, tmp4
, tmp5
;
4528 if (!s
->vfp_enabled
)
4530 q
= (insn
& (1 << 6)) != 0;
4531 u
= (insn
>> 24) & 1;
4532 VFP_DREG_D(rd
, insn
);
4533 VFP_DREG_N(rn
, insn
);
4534 VFP_DREG_M(rm
, insn
);
4535 size
= (insn
>> 20) & 3;
4536 if ((insn
& (1 << 23)) == 0) {
4537 /* Three register same length. */
4538 op
= ((insn
>> 7) & 0x1e) | ((insn
>> 4) & 1);
4539 /* Catch invalid op and bad size combinations: UNDEF */
4540 if ((neon_3r_sizes
[op
] & (1 << size
)) == 0) {
4543 /* All insns of this form UNDEF for either this condition or the
4544 * superset of cases "Q==1"; we catch the latter later.
4546 if (q
&& ((rd
| rn
| rm
) & 1)) {
4549 if (size
== 3 && op
!= NEON_3R_LOGIC
) {
4550 /* 64-bit element instructions. */
4551 for (pass
= 0; pass
< (q
? 2 : 1); pass
++) {
4552 neon_load_reg64(cpu_V0
, rn
+ pass
);
4553 neon_load_reg64(cpu_V1
, rm
+ pass
);
4557 gen_helper_neon_qadd_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4559 gen_helper_neon_qadd_s64(cpu_V0
, cpu_V0
, cpu_V1
);
4564 gen_helper_neon_qsub_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4566 gen_helper_neon_qsub_s64(cpu_V0
, cpu_V0
, cpu_V1
);
4571 gen_helper_neon_shl_u64(cpu_V0
, cpu_V1
, cpu_V0
);
4573 gen_helper_neon_shl_s64(cpu_V0
, cpu_V1
, cpu_V0
);
4578 gen_helper_neon_qshl_u64(cpu_V0
, cpu_V1
, cpu_V0
);
4580 gen_helper_neon_qshl_s64(cpu_V0
, cpu_V1
, cpu_V0
);
4585 gen_helper_neon_rshl_u64(cpu_V0
, cpu_V1
, cpu_V0
);
4587 gen_helper_neon_rshl_s64(cpu_V0
, cpu_V1
, cpu_V0
);
4590 case NEON_3R_VQRSHL
:
4592 gen_helper_neon_qrshl_u64(cpu_V0
, cpu_V1
, cpu_V0
);
4594 gen_helper_neon_qrshl_s64(cpu_V0
, cpu_V1
, cpu_V0
);
4597 case NEON_3R_VADD_VSUB
:
4599 tcg_gen_sub_i64(CPU_V001
);
4601 tcg_gen_add_i64(CPU_V001
);
4607 neon_store_reg64(cpu_V0
, rd
+ pass
);
4616 case NEON_3R_VQRSHL
:
4619 /* Shift instruction operands are reversed. */
4634 case NEON_3R_FLOAT_ARITH
:
4635 pairwise
= (u
&& size
< 2); /* if VPADD (float) */
4637 case NEON_3R_FLOAT_MINMAX
:
4638 pairwise
= u
; /* if VPMIN/VPMAX (float) */
4640 case NEON_3R_FLOAT_CMP
:
4642 /* no encoding for U=0 C=1x */
4646 case NEON_3R_FLOAT_ACMP
:
4651 case NEON_3R_VRECPS_VRSQRTS
:
4657 if (u
&& (size
!= 0)) {
4658 /* UNDEF on invalid size for polynomial subcase */
4666 if (pairwise
&& q
) {
4667 /* All the pairwise insns UNDEF if Q is set */
4671 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
4676 tmp
= neon_load_reg(rn
, 0);
4677 tmp2
= neon_load_reg(rn
, 1);
4679 tmp
= neon_load_reg(rm
, 0);
4680 tmp2
= neon_load_reg(rm
, 1);
4684 tmp
= neon_load_reg(rn
, pass
);
4685 tmp2
= neon_load_reg(rm
, pass
);
4689 GEN_NEON_INTEGER_OP(hadd
);
4692 GEN_NEON_INTEGER_OP(qadd
);
4694 case NEON_3R_VRHADD
:
4695 GEN_NEON_INTEGER_OP(rhadd
);
4697 case NEON_3R_LOGIC
: /* Logic ops. */
4698 switch ((u
<< 2) | size
) {
4700 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
4703 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
4706 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
4709 tcg_gen_orc_i32(tmp
, tmp
, tmp2
);
4712 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
4715 tmp3
= neon_load_reg(rd
, pass
);
4716 gen_neon_bsl(tmp
, tmp
, tmp2
, tmp3
);
4717 tcg_temp_free_i32(tmp3
);
4720 tmp3
= neon_load_reg(rd
, pass
);
4721 gen_neon_bsl(tmp
, tmp
, tmp3
, tmp2
);
4722 tcg_temp_free_i32(tmp3
);
4725 tmp3
= neon_load_reg(rd
, pass
);
4726 gen_neon_bsl(tmp
, tmp3
, tmp
, tmp2
);
4727 tcg_temp_free_i32(tmp3
);
4732 GEN_NEON_INTEGER_OP(hsub
);
4735 GEN_NEON_INTEGER_OP(qsub
);
4738 GEN_NEON_INTEGER_OP(cgt
);
4741 GEN_NEON_INTEGER_OP(cge
);
4744 GEN_NEON_INTEGER_OP(shl
);
4747 GEN_NEON_INTEGER_OP(qshl
);
4750 GEN_NEON_INTEGER_OP(rshl
);
4752 case NEON_3R_VQRSHL
:
4753 GEN_NEON_INTEGER_OP(qrshl
);
4756 GEN_NEON_INTEGER_OP(max
);
4759 GEN_NEON_INTEGER_OP(min
);
4762 GEN_NEON_INTEGER_OP(abd
);
4765 GEN_NEON_INTEGER_OP(abd
);
4766 tcg_temp_free_i32(tmp2
);
4767 tmp2
= neon_load_reg(rd
, pass
);
4768 gen_neon_add(size
, tmp
, tmp2
);
4770 case NEON_3R_VADD_VSUB
:
4771 if (!u
) { /* VADD */
4772 gen_neon_add(size
, tmp
, tmp2
);
4775 case 0: gen_helper_neon_sub_u8(tmp
, tmp
, tmp2
); break;
4776 case 1: gen_helper_neon_sub_u16(tmp
, tmp
, tmp2
); break;
4777 case 2: tcg_gen_sub_i32(tmp
, tmp
, tmp2
); break;
4782 case NEON_3R_VTST_VCEQ
:
4783 if (!u
) { /* VTST */
4785 case 0: gen_helper_neon_tst_u8(tmp
, tmp
, tmp2
); break;
4786 case 1: gen_helper_neon_tst_u16(tmp
, tmp
, tmp2
); break;
4787 case 2: gen_helper_neon_tst_u32(tmp
, tmp
, tmp2
); break;
4792 case 0: gen_helper_neon_ceq_u8(tmp
, tmp
, tmp2
); break;
4793 case 1: gen_helper_neon_ceq_u16(tmp
, tmp
, tmp2
); break;
4794 case 2: gen_helper_neon_ceq_u32(tmp
, tmp
, tmp2
); break;
4799 case NEON_3R_VML
: /* VMLA, VMLAL, VMLS,VMLSL */
4801 case 0: gen_helper_neon_mul_u8(tmp
, tmp
, tmp2
); break;
4802 case 1: gen_helper_neon_mul_u16(tmp
, tmp
, tmp2
); break;
4803 case 2: tcg_gen_mul_i32(tmp
, tmp
, tmp2
); break;
4806 tcg_temp_free_i32(tmp2
);
4807 tmp2
= neon_load_reg(rd
, pass
);
4809 gen_neon_rsb(size
, tmp
, tmp2
);
4811 gen_neon_add(size
, tmp
, tmp2
);
4815 if (u
) { /* polynomial */
4816 gen_helper_neon_mul_p8(tmp
, tmp
, tmp2
);
4817 } else { /* Integer */
4819 case 0: gen_helper_neon_mul_u8(tmp
, tmp
, tmp2
); break;
4820 case 1: gen_helper_neon_mul_u16(tmp
, tmp
, tmp2
); break;
4821 case 2: tcg_gen_mul_i32(tmp
, tmp
, tmp2
); break;
4827 GEN_NEON_INTEGER_OP(pmax
);
4830 GEN_NEON_INTEGER_OP(pmin
);
4832 case NEON_3R_VQDMULH_VQRDMULH
: /* Multiply high. */
4833 if (!u
) { /* VQDMULH */
4835 case 1: gen_helper_neon_qdmulh_s16(tmp
, tmp
, tmp2
); break;
4836 case 2: gen_helper_neon_qdmulh_s32(tmp
, tmp
, tmp2
); break;
4839 } else { /* VQRDMULH */
4841 case 1: gen_helper_neon_qrdmulh_s16(tmp
, tmp
, tmp2
); break;
4842 case 2: gen_helper_neon_qrdmulh_s32(tmp
, tmp
, tmp2
); break;
4849 case 0: gen_helper_neon_padd_u8(tmp
, tmp
, tmp2
); break;
4850 case 1: gen_helper_neon_padd_u16(tmp
, tmp
, tmp2
); break;
4851 case 2: tcg_gen_add_i32(tmp
, tmp
, tmp2
); break;
4855 case NEON_3R_FLOAT_ARITH
: /* Floating point arithmetic. */
4856 switch ((u
<< 2) | size
) {
4858 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
4861 gen_helper_neon_sub_f32(tmp
, tmp
, tmp2
);
4864 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
4867 gen_helper_neon_abd_f32(tmp
, tmp
, tmp2
);
4873 case NEON_3R_FLOAT_MULTIPLY
:
4874 gen_helper_neon_mul_f32(tmp
, tmp
, tmp2
);
4876 tcg_temp_free_i32(tmp2
);
4877 tmp2
= neon_load_reg(rd
, pass
);
4879 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
4881 gen_helper_neon_sub_f32(tmp
, tmp2
, tmp
);
4885 case NEON_3R_FLOAT_CMP
:
4887 gen_helper_neon_ceq_f32(tmp
, tmp
, tmp2
);
4890 gen_helper_neon_cge_f32(tmp
, tmp
, tmp2
);
4892 gen_helper_neon_cgt_f32(tmp
, tmp
, tmp2
);
4895 case NEON_3R_FLOAT_ACMP
:
4897 gen_helper_neon_acge_f32(tmp
, tmp
, tmp2
);
4899 gen_helper_neon_acgt_f32(tmp
, tmp
, tmp2
);
4901 case NEON_3R_FLOAT_MINMAX
:
4903 gen_helper_neon_max_f32(tmp
, tmp
, tmp2
);
4905 gen_helper_neon_min_f32(tmp
, tmp
, tmp2
);
4907 case NEON_3R_VRECPS_VRSQRTS
:
4909 gen_helper_recps_f32(tmp
, tmp
, tmp2
, cpu_env
);
4911 gen_helper_rsqrts_f32(tmp
, tmp
, tmp2
, cpu_env
);
4916 tcg_temp_free_i32(tmp2
);
4918 /* Save the result. For elementwise operations we can put it
4919 straight into the destination register. For pairwise operations
4920 we have to be careful to avoid clobbering the source operands. */
4921 if (pairwise
&& rd
== rm
) {
4922 neon_store_scratch(pass
, tmp
);
4924 neon_store_reg(rd
, pass
, tmp
);
4928 if (pairwise
&& rd
== rm
) {
4929 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
4930 tmp
= neon_load_scratch(pass
);
4931 neon_store_reg(rd
, pass
, tmp
);
4934 /* End of 3 register same size operations. */
4935 } else if (insn
& (1 << 4)) {
4936 if ((insn
& 0x00380080) != 0) {
4937 /* Two registers and shift. */
4938 op
= (insn
>> 8) & 0xf;
4939 if (insn
& (1 << 7)) {
4947 while ((insn
& (1 << (size
+ 19))) == 0)
4950 shift
= (insn
>> 16) & ((1 << (3 + size
)) - 1);
4951 /* To avoid excessive dumplication of ops we implement shift
4952 by immediate using the variable shift operations. */
4954 /* Shift by immediate:
4955 VSHR, VSRA, VRSHR, VRSRA, VSRI, VSHL, VQSHL, VQSHLU. */
4956 if (q
&& ((rd
| rm
) & 1)) {
4959 if (!u
&& (op
== 4 || op
== 6)) {
4962 /* Right shifts are encoded as N - shift, where N is the
4963 element size in bits. */
4965 shift
= shift
- (1 << (size
+ 3));
4973 imm
= (uint8_t) shift
;
4978 imm
= (uint16_t) shift
;
4989 for (pass
= 0; pass
< count
; pass
++) {
4991 neon_load_reg64(cpu_V0
, rm
+ pass
);
4992 tcg_gen_movi_i64(cpu_V1
, imm
);
4997 gen_helper_neon_shl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4999 gen_helper_neon_shl_s64(cpu_V0
, cpu_V0
, cpu_V1
);
5004 gen_helper_neon_rshl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
5006 gen_helper_neon_rshl_s64(cpu_V0
, cpu_V0
, cpu_V1
);
5009 case 5: /* VSHL, VSLI */
5010 gen_helper_neon_shl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
5012 case 6: /* VQSHLU */
5013 gen_helper_neon_qshlu_s64(cpu_V0
, cpu_V0
, cpu_V1
);
5017 gen_helper_neon_qshl_u64(cpu_V0
,
5020 gen_helper_neon_qshl_s64(cpu_V0
,
5025 if (op
== 1 || op
== 3) {
5027 neon_load_reg64(cpu_V1
, rd
+ pass
);
5028 tcg_gen_add_i64(cpu_V0
, cpu_V0
, cpu_V1
);
5029 } else if (op
== 4 || (op
== 5 && u
)) {
5031 neon_load_reg64(cpu_V1
, rd
+ pass
);
5033 if (shift
< -63 || shift
> 63) {
5037 mask
= 0xffffffffffffffffull
>> -shift
;
5039 mask
= 0xffffffffffffffffull
<< shift
;
5042 tcg_gen_andi_i64(cpu_V1
, cpu_V1
, ~mask
);
5043 tcg_gen_or_i64(cpu_V0
, cpu_V0
, cpu_V1
);
5045 neon_store_reg64(cpu_V0
, rd
+ pass
);
5046 } else { /* size < 3 */
5047 /* Operands in T0 and T1. */
5048 tmp
= neon_load_reg(rm
, pass
);
5049 tmp2
= tcg_temp_new_i32();
5050 tcg_gen_movi_i32(tmp2
, imm
);
5054 GEN_NEON_INTEGER_OP(shl
);
5058 GEN_NEON_INTEGER_OP(rshl
);
5061 case 5: /* VSHL, VSLI */
5063 case 0: gen_helper_neon_shl_u8(tmp
, tmp
, tmp2
); break;
5064 case 1: gen_helper_neon_shl_u16(tmp
, tmp
, tmp2
); break;
5065 case 2: gen_helper_neon_shl_u32(tmp
, tmp
, tmp2
); break;
5069 case 6: /* VQSHLU */
5072 gen_helper_neon_qshlu_s8(tmp
, tmp
, tmp2
);
5075 gen_helper_neon_qshlu_s16(tmp
, tmp
, tmp2
);
5078 gen_helper_neon_qshlu_s32(tmp
, tmp
, tmp2
);
5085 GEN_NEON_INTEGER_OP(qshl
);
5088 tcg_temp_free_i32(tmp2
);
5090 if (op
== 1 || op
== 3) {
5092 tmp2
= neon_load_reg(rd
, pass
);
5093 gen_neon_add(size
, tmp
, tmp2
);
5094 tcg_temp_free_i32(tmp2
);
5095 } else if (op
== 4 || (op
== 5 && u
)) {
5100 mask
= 0xff >> -shift
;
5102 mask
= (uint8_t)(0xff << shift
);
5108 mask
= 0xffff >> -shift
;
5110 mask
= (uint16_t)(0xffff << shift
);
5114 if (shift
< -31 || shift
> 31) {
5118 mask
= 0xffffffffu
>> -shift
;
5120 mask
= 0xffffffffu
<< shift
;
5126 tmp2
= neon_load_reg(rd
, pass
);
5127 tcg_gen_andi_i32(tmp
, tmp
, mask
);
5128 tcg_gen_andi_i32(tmp2
, tmp2
, ~mask
);
5129 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
5130 tcg_temp_free_i32(tmp2
);
5132 neon_store_reg(rd
, pass
, tmp
);
5135 } else if (op
< 10) {
5136 /* Shift by immediate and narrow:
5137 VSHRN, VRSHRN, VQSHRN, VQRSHRN. */
5138 int input_unsigned
= (op
== 8) ? !u
: u
;
5142 shift
= shift
- (1 << (size
+ 3));
5145 tmp64
= tcg_const_i64(shift
);
5146 neon_load_reg64(cpu_V0
, rm
);
5147 neon_load_reg64(cpu_V1
, rm
+ 1);
5148 for (pass
= 0; pass
< 2; pass
++) {
5156 if (input_unsigned
) {
5157 gen_helper_neon_rshl_u64(cpu_V0
, in
, tmp64
);
5159 gen_helper_neon_rshl_s64(cpu_V0
, in
, tmp64
);
5162 if (input_unsigned
) {
5163 gen_helper_neon_shl_u64(cpu_V0
, in
, tmp64
);
5165 gen_helper_neon_shl_s64(cpu_V0
, in
, tmp64
);
5168 tmp
= tcg_temp_new_i32();
5169 gen_neon_narrow_op(op
== 8, u
, size
- 1, tmp
, cpu_V0
);
5170 neon_store_reg(rd
, pass
, tmp
);
5172 tcg_temp_free_i64(tmp64
);
5175 imm
= (uint16_t)shift
;
5179 imm
= (uint32_t)shift
;
5181 tmp2
= tcg_const_i32(imm
);
5182 tmp4
= neon_load_reg(rm
+ 1, 0);
5183 tmp5
= neon_load_reg(rm
+ 1, 1);
5184 for (pass
= 0; pass
< 2; pass
++) {
5186 tmp
= neon_load_reg(rm
, 0);
5190 gen_neon_shift_narrow(size
, tmp
, tmp2
, q
,
5193 tmp3
= neon_load_reg(rm
, 1);
5197 gen_neon_shift_narrow(size
, tmp3
, tmp2
, q
,
5199 tcg_gen_concat_i32_i64(cpu_V0
, tmp
, tmp3
);
5200 tcg_temp_free_i32(tmp
);
5201 tcg_temp_free_i32(tmp3
);
5202 tmp
= tcg_temp_new_i32();
5203 gen_neon_narrow_op(op
== 8, u
, size
- 1, tmp
, cpu_V0
);
5204 neon_store_reg(rd
, pass
, tmp
);
5206 tcg_temp_free_i32(tmp2
);
5208 } else if (op
== 10) {
5210 if (q
|| (rd
& 1)) {
5213 tmp
= neon_load_reg(rm
, 0);
5214 tmp2
= neon_load_reg(rm
, 1);
5215 for (pass
= 0; pass
< 2; pass
++) {
5219 gen_neon_widen(cpu_V0
, tmp
, size
, u
);
5222 /* The shift is less than the width of the source
5223 type, so we can just shift the whole register. */
5224 tcg_gen_shli_i64(cpu_V0
, cpu_V0
, shift
);
5225 /* Widen the result of shift: we need to clear
5226 * the potential overflow bits resulting from
5227 * left bits of the narrow input appearing as
5228 * right bits of left the neighbour narrow
5230 if (size
< 2 || !u
) {
5233 imm
= (0xffu
>> (8 - shift
));
5235 } else if (size
== 1) {
5236 imm
= 0xffff >> (16 - shift
);
5239 imm
= 0xffffffff >> (32 - shift
);
5242 imm64
= imm
| (((uint64_t)imm
) << 32);
5246 tcg_gen_andi_i64(cpu_V0
, cpu_V0
, ~imm64
);
5249 neon_store_reg64(cpu_V0
, rd
+ pass
);
5251 } else if (op
>= 14) {
5252 /* VCVT fixed-point. */
5253 if (!(insn
& (1 << 21)) || (q
&& ((rd
| rm
) & 1))) {
5256 /* We have already masked out the must-be-1 top bit of imm6,
5257 * hence this 32-shift where the ARM ARM has 64-imm6.
5260 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
5261 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, pass
));
5264 gen_vfp_ulto(0, shift
, 1);
5266 gen_vfp_slto(0, shift
, 1);
5269 gen_vfp_toul(0, shift
, 1);
5271 gen_vfp_tosl(0, shift
, 1);
5273 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, pass
));
5278 } else { /* (insn & 0x00380080) == 0 */
5280 if (q
&& (rd
& 1)) {
5284 op
= (insn
>> 8) & 0xf;
5285 /* One register and immediate. */
5286 imm
= (u
<< 7) | ((insn
>> 12) & 0x70) | (insn
& 0xf);
5287 invert
= (insn
& (1 << 5)) != 0;
5288 /* Note that op = 2,3,4,5,6,7,10,11,12,13 imm=0 is UNPREDICTABLE.
5289 * We choose to not special-case this and will behave as if a
5290 * valid constant encoding of 0 had been given.
5309 imm
= (imm
<< 8) | (imm
<< 24);
5312 imm
= (imm
<< 8) | 0xff;
5315 imm
= (imm
<< 16) | 0xffff;
5318 imm
|= (imm
<< 8) | (imm
<< 16) | (imm
<< 24);
5326 imm
= ((imm
& 0x80) << 24) | ((imm
& 0x3f) << 19)
5327 | ((imm
& 0x40) ? (0x1f << 25) : (1 << 30));
5333 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
5334 if (op
& 1 && op
< 12) {
5335 tmp
= neon_load_reg(rd
, pass
);
5337 /* The immediate value has already been inverted, so
5339 tcg_gen_andi_i32(tmp
, tmp
, imm
);
5341 tcg_gen_ori_i32(tmp
, tmp
, imm
);
5345 tmp
= tcg_temp_new_i32();
5346 if (op
== 14 && invert
) {
5350 for (n
= 0; n
< 4; n
++) {
5351 if (imm
& (1 << (n
+ (pass
& 1) * 4)))
5352 val
|= 0xff << (n
* 8);
5354 tcg_gen_movi_i32(tmp
, val
);
5356 tcg_gen_movi_i32(tmp
, imm
);
5359 neon_store_reg(rd
, pass
, tmp
);
5362 } else { /* (insn & 0x00800010 == 0x00800000) */
5364 op
= (insn
>> 8) & 0xf;
5365 if ((insn
& (1 << 6)) == 0) {
5366 /* Three registers of different lengths. */
5370 /* undefreq: bit 0 : UNDEF if size != 0
5371 * bit 1 : UNDEF if size == 0
5372 * bit 2 : UNDEF if U == 1
5373 * Note that [1:0] set implies 'always UNDEF'
5376 /* prewiden, src1_wide, src2_wide, undefreq */
5377 static const int neon_3reg_wide
[16][4] = {
5378 {1, 0, 0, 0}, /* VADDL */
5379 {1, 1, 0, 0}, /* VADDW */
5380 {1, 0, 0, 0}, /* VSUBL */
5381 {1, 1, 0, 0}, /* VSUBW */
5382 {0, 1, 1, 0}, /* VADDHN */
5383 {0, 0, 0, 0}, /* VABAL */
5384 {0, 1, 1, 0}, /* VSUBHN */
5385 {0, 0, 0, 0}, /* VABDL */
5386 {0, 0, 0, 0}, /* VMLAL */
5387 {0, 0, 0, 6}, /* VQDMLAL */
5388 {0, 0, 0, 0}, /* VMLSL */
5389 {0, 0, 0, 6}, /* VQDMLSL */
5390 {0, 0, 0, 0}, /* Integer VMULL */
5391 {0, 0, 0, 2}, /* VQDMULL */
5392 {0, 0, 0, 5}, /* Polynomial VMULL */
5393 {0, 0, 0, 3}, /* Reserved: always UNDEF */
5396 prewiden
= neon_3reg_wide
[op
][0];
5397 src1_wide
= neon_3reg_wide
[op
][1];
5398 src2_wide
= neon_3reg_wide
[op
][2];
5399 undefreq
= neon_3reg_wide
[op
][3];
5401 if (((undefreq
& 1) && (size
!= 0)) ||
5402 ((undefreq
& 2) && (size
== 0)) ||
5403 ((undefreq
& 4) && u
)) {
5406 if ((src1_wide
&& (rn
& 1)) ||
5407 (src2_wide
&& (rm
& 1)) ||
5408 (!src2_wide
&& (rd
& 1))) {
5412 /* Avoid overlapping operands. Wide source operands are
5413 always aligned so will never overlap with wide
5414 destinations in problematic ways. */
5415 if (rd
== rm
&& !src2_wide
) {
5416 tmp
= neon_load_reg(rm
, 1);
5417 neon_store_scratch(2, tmp
);
5418 } else if (rd
== rn
&& !src1_wide
) {
5419 tmp
= neon_load_reg(rn
, 1);
5420 neon_store_scratch(2, tmp
);
5423 for (pass
= 0; pass
< 2; pass
++) {
5425 neon_load_reg64(cpu_V0
, rn
+ pass
);
5428 if (pass
== 1 && rd
== rn
) {
5429 tmp
= neon_load_scratch(2);
5431 tmp
= neon_load_reg(rn
, pass
);
5434 gen_neon_widen(cpu_V0
, tmp
, size
, u
);
5438 neon_load_reg64(cpu_V1
, rm
+ pass
);
5441 if (pass
== 1 && rd
== rm
) {
5442 tmp2
= neon_load_scratch(2);
5444 tmp2
= neon_load_reg(rm
, pass
);
5447 gen_neon_widen(cpu_V1
, tmp2
, size
, u
);
5451 case 0: case 1: case 4: /* VADDL, VADDW, VADDHN, VRADDHN */
5452 gen_neon_addl(size
);
5454 case 2: case 3: case 6: /* VSUBL, VSUBW, VSUBHN, VRSUBHN */
5455 gen_neon_subl(size
);
5457 case 5: case 7: /* VABAL, VABDL */
5458 switch ((size
<< 1) | u
) {
5460 gen_helper_neon_abdl_s16(cpu_V0
, tmp
, tmp2
);
5463 gen_helper_neon_abdl_u16(cpu_V0
, tmp
, tmp2
);
5466 gen_helper_neon_abdl_s32(cpu_V0
, tmp
, tmp2
);
5469 gen_helper_neon_abdl_u32(cpu_V0
, tmp
, tmp2
);
5472 gen_helper_neon_abdl_s64(cpu_V0
, tmp
, tmp2
);
5475 gen_helper_neon_abdl_u64(cpu_V0
, tmp
, tmp2
);
5479 tcg_temp_free_i32(tmp2
);
5480 tcg_temp_free_i32(tmp
);
5482 case 8: case 9: case 10: case 11: case 12: case 13:
5483 /* VMLAL, VQDMLAL, VMLSL, VQDMLSL, VMULL, VQDMULL */
5484 gen_neon_mull(cpu_V0
, tmp
, tmp2
, size
, u
);
5486 case 14: /* Polynomial VMULL */
5487 gen_helper_neon_mull_p8(cpu_V0
, tmp
, tmp2
);
5488 tcg_temp_free_i32(tmp2
);
5489 tcg_temp_free_i32(tmp
);
5491 default: /* 15 is RESERVED: caught earlier */
5496 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5497 neon_store_reg64(cpu_V0
, rd
+ pass
);
5498 } else if (op
== 5 || (op
>= 8 && op
<= 11)) {
5500 neon_load_reg64(cpu_V1
, rd
+ pass
);
5502 case 10: /* VMLSL */
5503 gen_neon_negl(cpu_V0
, size
);
5505 case 5: case 8: /* VABAL, VMLAL */
5506 gen_neon_addl(size
);
5508 case 9: case 11: /* VQDMLAL, VQDMLSL */
5509 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5511 gen_neon_negl(cpu_V0
, size
);
5513 gen_neon_addl_saturate(cpu_V0
, cpu_V1
, size
);
5518 neon_store_reg64(cpu_V0
, rd
+ pass
);
5519 } else if (op
== 4 || op
== 6) {
5520 /* Narrowing operation. */
5521 tmp
= tcg_temp_new_i32();
5525 gen_helper_neon_narrow_high_u8(tmp
, cpu_V0
);
5528 gen_helper_neon_narrow_high_u16(tmp
, cpu_V0
);
5531 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
5532 tcg_gen_trunc_i64_i32(tmp
, cpu_V0
);
5539 gen_helper_neon_narrow_round_high_u8(tmp
, cpu_V0
);
5542 gen_helper_neon_narrow_round_high_u16(tmp
, cpu_V0
);
5545 tcg_gen_addi_i64(cpu_V0
, cpu_V0
, 1u << 31);
5546 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
5547 tcg_gen_trunc_i64_i32(tmp
, cpu_V0
);
5555 neon_store_reg(rd
, 0, tmp3
);
5556 neon_store_reg(rd
, 1, tmp
);
5559 /* Write back the result. */
5560 neon_store_reg64(cpu_V0
, rd
+ pass
);
5564 /* Two registers and a scalar. NB that for ops of this form
5565 * the ARM ARM labels bit 24 as Q, but it is in our variable
5572 case 1: /* Float VMLA scalar */
5573 case 5: /* Floating point VMLS scalar */
5574 case 9: /* Floating point VMUL scalar */
5579 case 0: /* Integer VMLA scalar */
5580 case 4: /* Integer VMLS scalar */
5581 case 8: /* Integer VMUL scalar */
5582 case 12: /* VQDMULH scalar */
5583 case 13: /* VQRDMULH scalar */
5584 if (u
&& ((rd
| rn
) & 1)) {
5587 tmp
= neon_get_scalar(size
, rm
);
5588 neon_store_scratch(0, tmp
);
5589 for (pass
= 0; pass
< (u
? 4 : 2); pass
++) {
5590 tmp
= neon_load_scratch(0);
5591 tmp2
= neon_load_reg(rn
, pass
);
5594 gen_helper_neon_qdmulh_s16(tmp
, tmp
, tmp2
);
5596 gen_helper_neon_qdmulh_s32(tmp
, tmp
, tmp2
);
5598 } else if (op
== 13) {
5600 gen_helper_neon_qrdmulh_s16(tmp
, tmp
, tmp2
);
5602 gen_helper_neon_qrdmulh_s32(tmp
, tmp
, tmp2
);
5604 } else if (op
& 1) {
5605 gen_helper_neon_mul_f32(tmp
, tmp
, tmp2
);
5608 case 0: gen_helper_neon_mul_u8(tmp
, tmp
, tmp2
); break;
5609 case 1: gen_helper_neon_mul_u16(tmp
, tmp
, tmp2
); break;
5610 case 2: tcg_gen_mul_i32(tmp
, tmp
, tmp2
); break;
5614 tcg_temp_free_i32(tmp2
);
5617 tmp2
= neon_load_reg(rd
, pass
);
5620 gen_neon_add(size
, tmp
, tmp2
);
5623 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
5626 gen_neon_rsb(size
, tmp
, tmp2
);
5629 gen_helper_neon_sub_f32(tmp
, tmp2
, tmp
);
5634 tcg_temp_free_i32(tmp2
);
5636 neon_store_reg(rd
, pass
, tmp
);
5639 case 3: /* VQDMLAL scalar */
5640 case 7: /* VQDMLSL scalar */
5641 case 11: /* VQDMULL scalar */
5646 case 2: /* VMLAL sclar */
5647 case 6: /* VMLSL scalar */
5648 case 10: /* VMULL scalar */
5652 tmp2
= neon_get_scalar(size
, rm
);
5653 /* We need a copy of tmp2 because gen_neon_mull
5654 * deletes it during pass 0. */
5655 tmp4
= tcg_temp_new_i32();
5656 tcg_gen_mov_i32(tmp4
, tmp2
);
5657 tmp3
= neon_load_reg(rn
, 1);
5659 for (pass
= 0; pass
< 2; pass
++) {
5661 tmp
= neon_load_reg(rn
, 0);
5666 gen_neon_mull(cpu_V0
, tmp
, tmp2
, size
, u
);
5668 neon_load_reg64(cpu_V1
, rd
+ pass
);
5672 gen_neon_negl(cpu_V0
, size
);
5675 gen_neon_addl(size
);
5678 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5680 gen_neon_negl(cpu_V0
, size
);
5682 gen_neon_addl_saturate(cpu_V0
, cpu_V1
, size
);
5688 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5693 neon_store_reg64(cpu_V0
, rd
+ pass
);
5698 default: /* 14 and 15 are RESERVED */
5702 } else { /* size == 3 */
5705 imm
= (insn
>> 8) & 0xf;
5710 if (q
&& ((rd
| rn
| rm
) & 1)) {
5715 neon_load_reg64(cpu_V0
, rn
);
5717 neon_load_reg64(cpu_V1
, rn
+ 1);
5719 } else if (imm
== 8) {
5720 neon_load_reg64(cpu_V0
, rn
+ 1);
5722 neon_load_reg64(cpu_V1
, rm
);
5725 tmp64
= tcg_temp_new_i64();
5727 neon_load_reg64(cpu_V0
, rn
);
5728 neon_load_reg64(tmp64
, rn
+ 1);
5730 neon_load_reg64(cpu_V0
, rn
+ 1);
5731 neon_load_reg64(tmp64
, rm
);
5733 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, (imm
& 7) * 8);
5734 tcg_gen_shli_i64(cpu_V1
, tmp64
, 64 - ((imm
& 7) * 8));
5735 tcg_gen_or_i64(cpu_V0
, cpu_V0
, cpu_V1
);
5737 neon_load_reg64(cpu_V1
, rm
);
5739 neon_load_reg64(cpu_V1
, rm
+ 1);
5742 tcg_gen_shli_i64(cpu_V1
, cpu_V1
, 64 - (imm
* 8));
5743 tcg_gen_shri_i64(tmp64
, tmp64
, imm
* 8);
5744 tcg_gen_or_i64(cpu_V1
, cpu_V1
, tmp64
);
5745 tcg_temp_free_i64(tmp64
);
5748 neon_load_reg64(cpu_V0
, rn
);
5749 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, imm
* 8);
5750 neon_load_reg64(cpu_V1
, rm
);
5751 tcg_gen_shli_i64(cpu_V1
, cpu_V1
, 64 - (imm
* 8));
5752 tcg_gen_or_i64(cpu_V0
, cpu_V0
, cpu_V1
);
5754 neon_store_reg64(cpu_V0
, rd
);
5756 neon_store_reg64(cpu_V1
, rd
+ 1);
5758 } else if ((insn
& (1 << 11)) == 0) {
5759 /* Two register misc. */
5760 op
= ((insn
>> 12) & 0x30) | ((insn
>> 7) & 0xf);
5761 size
= (insn
>> 18) & 3;
5762 /* UNDEF for unknown op values and bad op-size combinations */
5763 if ((neon_2rm_sizes
[op
] & (1 << size
)) == 0) {
5766 if ((op
!= NEON_2RM_VMOVN
&& op
!= NEON_2RM_VQMOVN
) &&
5767 q
&& ((rm
| rd
) & 1)) {
5771 case NEON_2RM_VREV64
:
5772 for (pass
= 0; pass
< (q
? 2 : 1); pass
++) {
5773 tmp
= neon_load_reg(rm
, pass
* 2);
5774 tmp2
= neon_load_reg(rm
, pass
* 2 + 1);
5776 case 0: tcg_gen_bswap32_i32(tmp
, tmp
); break;
5777 case 1: gen_swap_half(tmp
); break;
5778 case 2: /* no-op */ break;
5781 neon_store_reg(rd
, pass
* 2 + 1, tmp
);
5783 neon_store_reg(rd
, pass
* 2, tmp2
);
5786 case 0: tcg_gen_bswap32_i32(tmp2
, tmp2
); break;
5787 case 1: gen_swap_half(tmp2
); break;
5790 neon_store_reg(rd
, pass
* 2, tmp2
);
5794 case NEON_2RM_VPADDL
: case NEON_2RM_VPADDL_U
:
5795 case NEON_2RM_VPADAL
: case NEON_2RM_VPADAL_U
:
5796 for (pass
= 0; pass
< q
+ 1; pass
++) {
5797 tmp
= neon_load_reg(rm
, pass
* 2);
5798 gen_neon_widen(cpu_V0
, tmp
, size
, op
& 1);
5799 tmp
= neon_load_reg(rm
, pass
* 2 + 1);
5800 gen_neon_widen(cpu_V1
, tmp
, size
, op
& 1);
5802 case 0: gen_helper_neon_paddl_u16(CPU_V001
); break;
5803 case 1: gen_helper_neon_paddl_u32(CPU_V001
); break;
5804 case 2: tcg_gen_add_i64(CPU_V001
); break;
5807 if (op
>= NEON_2RM_VPADAL
) {
5809 neon_load_reg64(cpu_V1
, rd
+ pass
);
5810 gen_neon_addl(size
);
5812 neon_store_reg64(cpu_V0
, rd
+ pass
);
5818 for (n
= 0; n
< (q
? 4 : 2); n
+= 2) {
5819 tmp
= neon_load_reg(rm
, n
);
5820 tmp2
= neon_load_reg(rd
, n
+ 1);
5821 neon_store_reg(rm
, n
, tmp2
);
5822 neon_store_reg(rd
, n
+ 1, tmp
);
5829 if (gen_neon_unzip(rd
, rm
, size
, q
)) {
5834 if (gen_neon_zip(rd
, rm
, size
, q
)) {
5838 case NEON_2RM_VMOVN
: case NEON_2RM_VQMOVN
:
5839 /* also VQMOVUN; op field and mnemonics don't line up */
5844 for (pass
= 0; pass
< 2; pass
++) {
5845 neon_load_reg64(cpu_V0
, rm
+ pass
);
5846 tmp
= tcg_temp_new_i32();
5847 gen_neon_narrow_op(op
== NEON_2RM_VMOVN
, q
, size
,
5852 neon_store_reg(rd
, 0, tmp2
);
5853 neon_store_reg(rd
, 1, tmp
);
5857 case NEON_2RM_VSHLL
:
5858 if (q
|| (rd
& 1)) {
5861 tmp
= neon_load_reg(rm
, 0);
5862 tmp2
= neon_load_reg(rm
, 1);
5863 for (pass
= 0; pass
< 2; pass
++) {
5866 gen_neon_widen(cpu_V0
, tmp
, size
, 1);
5867 tcg_gen_shli_i64(cpu_V0
, cpu_V0
, 8 << size
);
5868 neon_store_reg64(cpu_V0
, rd
+ pass
);
5871 case NEON_2RM_VCVT_F16_F32
:
5872 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
) ||
5876 tmp
= tcg_temp_new_i32();
5877 tmp2
= tcg_temp_new_i32();
5878 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 0));
5879 gen_helper_neon_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
5880 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 1));
5881 gen_helper_neon_fcvt_f32_to_f16(tmp2
, cpu_F0s
, cpu_env
);
5882 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
5883 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
5884 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 2));
5885 gen_helper_neon_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
5886 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 3));
5887 neon_store_reg(rd
, 0, tmp2
);
5888 tmp2
= tcg_temp_new_i32();
5889 gen_helper_neon_fcvt_f32_to_f16(tmp2
, cpu_F0s
, cpu_env
);
5890 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
5891 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
5892 neon_store_reg(rd
, 1, tmp2
);
5893 tcg_temp_free_i32(tmp
);
5895 case NEON_2RM_VCVT_F32_F16
:
5896 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
) ||
5900 tmp3
= tcg_temp_new_i32();
5901 tmp
= neon_load_reg(rm
, 0);
5902 tmp2
= neon_load_reg(rm
, 1);
5903 tcg_gen_ext16u_i32(tmp3
, tmp
);
5904 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5905 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 0));
5906 tcg_gen_shri_i32(tmp3
, tmp
, 16);
5907 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5908 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 1));
5909 tcg_temp_free_i32(tmp
);
5910 tcg_gen_ext16u_i32(tmp3
, tmp2
);
5911 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5912 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 2));
5913 tcg_gen_shri_i32(tmp3
, tmp2
, 16);
5914 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5915 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 3));
5916 tcg_temp_free_i32(tmp2
);
5917 tcg_temp_free_i32(tmp3
);
5921 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
5922 if (neon_2rm_is_float_op(op
)) {
5923 tcg_gen_ld_f32(cpu_F0s
, cpu_env
,
5924 neon_reg_offset(rm
, pass
));
5927 tmp
= neon_load_reg(rm
, pass
);
5930 case NEON_2RM_VREV32
:
5932 case 0: tcg_gen_bswap32_i32(tmp
, tmp
); break;
5933 case 1: gen_swap_half(tmp
); break;
5937 case NEON_2RM_VREV16
:
5942 case 0: gen_helper_neon_cls_s8(tmp
, tmp
); break;
5943 case 1: gen_helper_neon_cls_s16(tmp
, tmp
); break;
5944 case 2: gen_helper_neon_cls_s32(tmp
, tmp
); break;
5950 case 0: gen_helper_neon_clz_u8(tmp
, tmp
); break;
5951 case 1: gen_helper_neon_clz_u16(tmp
, tmp
); break;
5952 case 2: gen_helper_clz(tmp
, tmp
); break;
5957 gen_helper_neon_cnt_u8(tmp
, tmp
);
5960 tcg_gen_not_i32(tmp
, tmp
);
5962 case NEON_2RM_VQABS
:
5964 case 0: gen_helper_neon_qabs_s8(tmp
, tmp
); break;
5965 case 1: gen_helper_neon_qabs_s16(tmp
, tmp
); break;
5966 case 2: gen_helper_neon_qabs_s32(tmp
, tmp
); break;
5970 case NEON_2RM_VQNEG
:
5972 case 0: gen_helper_neon_qneg_s8(tmp
, tmp
); break;
5973 case 1: gen_helper_neon_qneg_s16(tmp
, tmp
); break;
5974 case 2: gen_helper_neon_qneg_s32(tmp
, tmp
); break;
5978 case NEON_2RM_VCGT0
: case NEON_2RM_VCLE0
:
5979 tmp2
= tcg_const_i32(0);
5981 case 0: gen_helper_neon_cgt_s8(tmp
, tmp
, tmp2
); break;
5982 case 1: gen_helper_neon_cgt_s16(tmp
, tmp
, tmp2
); break;
5983 case 2: gen_helper_neon_cgt_s32(tmp
, tmp
, tmp2
); break;
5986 tcg_temp_free(tmp2
);
5987 if (op
== NEON_2RM_VCLE0
) {
5988 tcg_gen_not_i32(tmp
, tmp
);
5991 case NEON_2RM_VCGE0
: case NEON_2RM_VCLT0
:
5992 tmp2
= tcg_const_i32(0);
5994 case 0: gen_helper_neon_cge_s8(tmp
, tmp
, tmp2
); break;
5995 case 1: gen_helper_neon_cge_s16(tmp
, tmp
, tmp2
); break;
5996 case 2: gen_helper_neon_cge_s32(tmp
, tmp
, tmp2
); break;
5999 tcg_temp_free(tmp2
);
6000 if (op
== NEON_2RM_VCLT0
) {
6001 tcg_gen_not_i32(tmp
, tmp
);
6004 case NEON_2RM_VCEQ0
:
6005 tmp2
= tcg_const_i32(0);
6007 case 0: gen_helper_neon_ceq_u8(tmp
, tmp
, tmp2
); break;
6008 case 1: gen_helper_neon_ceq_u16(tmp
, tmp
, tmp2
); break;
6009 case 2: gen_helper_neon_ceq_u32(tmp
, tmp
, tmp2
); break;
6012 tcg_temp_free(tmp2
);
6016 case 0: gen_helper_neon_abs_s8(tmp
, tmp
); break;
6017 case 1: gen_helper_neon_abs_s16(tmp
, tmp
); break;
6018 case 2: tcg_gen_abs_i32(tmp
, tmp
); break;
6023 tmp2
= tcg_const_i32(0);
6024 gen_neon_rsb(size
, tmp
, tmp2
);
6025 tcg_temp_free(tmp2
);
6027 case NEON_2RM_VCGT0_F
:
6028 tmp2
= tcg_const_i32(0);
6029 gen_helper_neon_cgt_f32(tmp
, tmp
, tmp2
);
6030 tcg_temp_free(tmp2
);
6032 case NEON_2RM_VCGE0_F
:
6033 tmp2
= tcg_const_i32(0);
6034 gen_helper_neon_cge_f32(tmp
, tmp
, tmp2
);
6035 tcg_temp_free(tmp2
);
6037 case NEON_2RM_VCEQ0_F
:
6038 tmp2
= tcg_const_i32(0);
6039 gen_helper_neon_ceq_f32(tmp
, tmp
, tmp2
);
6040 tcg_temp_free(tmp2
);
6042 case NEON_2RM_VCLE0_F
:
6043 tmp2
= tcg_const_i32(0);
6044 gen_helper_neon_cge_f32(tmp
, tmp2
, tmp
);
6045 tcg_temp_free(tmp2
);
6047 case NEON_2RM_VCLT0_F
:
6048 tmp2
= tcg_const_i32(0);
6049 gen_helper_neon_cgt_f32(tmp
, tmp2
, tmp
);
6050 tcg_temp_free(tmp2
);
6052 case NEON_2RM_VABS_F
:
6055 case NEON_2RM_VNEG_F
:
6059 tmp2
= neon_load_reg(rd
, pass
);
6060 neon_store_reg(rm
, pass
, tmp2
);
6063 tmp2
= neon_load_reg(rd
, pass
);
6065 case 0: gen_neon_trn_u8(tmp
, tmp2
); break;
6066 case 1: gen_neon_trn_u16(tmp
, tmp2
); break;
6069 neon_store_reg(rm
, pass
, tmp2
);
6071 case NEON_2RM_VRECPE
:
6072 gen_helper_recpe_u32(tmp
, tmp
, cpu_env
);
6074 case NEON_2RM_VRSQRTE
:
6075 gen_helper_rsqrte_u32(tmp
, tmp
, cpu_env
);
6077 case NEON_2RM_VRECPE_F
:
6078 gen_helper_recpe_f32(cpu_F0s
, cpu_F0s
, cpu_env
);
6080 case NEON_2RM_VRSQRTE_F
:
6081 gen_helper_rsqrte_f32(cpu_F0s
, cpu_F0s
, cpu_env
);
6083 case NEON_2RM_VCVT_FS
: /* VCVT.F32.S32 */
6086 case NEON_2RM_VCVT_FU
: /* VCVT.F32.U32 */
6089 case NEON_2RM_VCVT_SF
: /* VCVT.S32.F32 */
6090 gen_vfp_tosiz(0, 1);
6092 case NEON_2RM_VCVT_UF
: /* VCVT.U32.F32 */
6093 gen_vfp_touiz(0, 1);
6096 /* Reserved op values were caught by the
6097 * neon_2rm_sizes[] check earlier.
6101 if (neon_2rm_is_float_op(op
)) {
6102 tcg_gen_st_f32(cpu_F0s
, cpu_env
,
6103 neon_reg_offset(rd
, pass
));
6105 neon_store_reg(rd
, pass
, tmp
);
6110 } else if ((insn
& (1 << 10)) == 0) {
6112 int n
= ((insn
>> 8) & 3) + 1;
6113 if ((rn
+ n
) > 32) {
6114 /* This is UNPREDICTABLE; we choose to UNDEF to avoid the
6115 * helper function running off the end of the register file.
6120 if (insn
& (1 << 6)) {
6121 tmp
= neon_load_reg(rd
, 0);
6123 tmp
= tcg_temp_new_i32();
6124 tcg_gen_movi_i32(tmp
, 0);
6126 tmp2
= neon_load_reg(rm
, 0);
6127 tmp4
= tcg_const_i32(rn
);
6128 tmp5
= tcg_const_i32(n
);
6129 gen_helper_neon_tbl(tmp2
, tmp2
, tmp
, tmp4
, tmp5
);
6130 tcg_temp_free_i32(tmp
);
6131 if (insn
& (1 << 6)) {
6132 tmp
= neon_load_reg(rd
, 1);
6134 tmp
= tcg_temp_new_i32();
6135 tcg_gen_movi_i32(tmp
, 0);
6137 tmp3
= neon_load_reg(rm
, 1);
6138 gen_helper_neon_tbl(tmp3
, tmp3
, tmp
, tmp4
, tmp5
);
6139 tcg_temp_free_i32(tmp5
);
6140 tcg_temp_free_i32(tmp4
);
6141 neon_store_reg(rd
, 0, tmp2
);
6142 neon_store_reg(rd
, 1, tmp3
);
6143 tcg_temp_free_i32(tmp
);
6144 } else if ((insn
& 0x380) == 0) {
6146 if ((insn
& (7 << 16)) == 0 || (q
&& (rd
& 1))) {
6149 if (insn
& (1 << 19)) {
6150 tmp
= neon_load_reg(rm
, 1);
6152 tmp
= neon_load_reg(rm
, 0);
6154 if (insn
& (1 << 16)) {
6155 gen_neon_dup_u8(tmp
, ((insn
>> 17) & 3) * 8);
6156 } else if (insn
& (1 << 17)) {
6157 if ((insn
>> 18) & 1)
6158 gen_neon_dup_high16(tmp
);
6160 gen_neon_dup_low16(tmp
);
6162 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
6163 tmp2
= tcg_temp_new_i32();
6164 tcg_gen_mov_i32(tmp2
, tmp
);
6165 neon_store_reg(rd
, pass
, tmp2
);
6167 tcg_temp_free_i32(tmp
);
6176 static int disas_cp14_read(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
6178 int crn
= (insn
>> 16) & 0xf;
6179 int crm
= insn
& 0xf;
6180 int op1
= (insn
>> 21) & 7;
6181 int op2
= (insn
>> 5) & 7;
6182 int rt
= (insn
>> 12) & 0xf;
6185 /* Minimal set of debug registers, since we don't support debug */
6186 if (op1
== 0 && crn
== 0 && op2
== 0) {
6189 /* DBGDIDR: just RAZ. In particular this means the
6190 * "debug architecture version" bits will read as
6191 * a reserved value, which should cause Linux to
6192 * not try to use the debug hardware.
6194 tmp
= tcg_const_i32(0);
6195 store_reg(s
, rt
, tmp
);
6199 /* DBGDRAR and DBGDSAR: v7 only. Always RAZ since we
6200 * don't implement memory mapped debug components
6202 if (ENABLE_ARCH_7
) {
6203 tmp
= tcg_const_i32(0);
6204 store_reg(s
, rt
, tmp
);
6213 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
6214 if (op1
== 6 && crn
== 0 && crm
== 0 && op2
== 0) {
6218 tmp
= load_cpu_field(teecr
);
6219 store_reg(s
, rt
, tmp
);
6222 if (op1
== 6 && crn
== 1 && crm
== 0 && op2
== 0) {
6224 if (IS_USER(s
) && (env
->teecr
& 1))
6226 tmp
= load_cpu_field(teehbr
);
6227 store_reg(s
, rt
, tmp
);
6231 fprintf(stderr
, "Unknown cp14 read op1:%d crn:%d crm:%d op2:%d\n",
6232 op1
, crn
, crm
, op2
);
6236 static int disas_cp14_write(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
6238 int crn
= (insn
>> 16) & 0xf;
6239 int crm
= insn
& 0xf;
6240 int op1
= (insn
>> 21) & 7;
6241 int op2
= (insn
>> 5) & 7;
6242 int rt
= (insn
>> 12) & 0xf;
6245 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
6246 if (op1
== 6 && crn
== 0 && crm
== 0 && op2
== 0) {
6250 tmp
= load_reg(s
, rt
);
6251 gen_helper_set_teecr(cpu_env
, tmp
);
6252 tcg_temp_free_i32(tmp
);
6255 if (op1
== 6 && crn
== 1 && crm
== 0 && op2
== 0) {
6257 if (IS_USER(s
) && (env
->teecr
& 1))
6259 tmp
= load_reg(s
, rt
);
6260 store_cpu_field(tmp
, teehbr
);
6264 fprintf(stderr
, "Unknown cp14 write op1:%d crn:%d crm:%d op2:%d\n",
6265 op1
, crn
, crm
, op2
);
6269 static int disas_coproc_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
6273 cpnum
= (insn
>> 8) & 0xf;
6274 if (arm_feature(env
, ARM_FEATURE_XSCALE
)
6275 && ((env
->cp15
.c15_cpar
^ 0x3fff) & (1 << cpnum
)))
6281 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
6282 return disas_iwmmxt_insn(env
, s
, insn
);
6283 } else if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
6284 return disas_dsp_insn(env
, s
, insn
);
6289 return disas_vfp_insn (env
, s
, insn
);
6291 /* Coprocessors 7-15 are architecturally reserved by ARM.
6292 Unfortunately Intel decided to ignore this. */
6293 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
6295 if (insn
& (1 << 20))
6296 return disas_cp14_read(env
, s
, insn
);
6298 return disas_cp14_write(env
, s
, insn
);
6300 return disas_cp15_insn (env
, s
, insn
);
6303 /* Unknown coprocessor. See if the board has hooked it. */
6304 return disas_cp_insn (env
, s
, insn
);
6309 /* Store a 64-bit value to a register pair. Clobbers val. */
6310 static void gen_storeq_reg(DisasContext
*s
, int rlow
, int rhigh
, TCGv_i64 val
)
6313 tmp
= tcg_temp_new_i32();
6314 tcg_gen_trunc_i64_i32(tmp
, val
);
6315 store_reg(s
, rlow
, tmp
);
6316 tmp
= tcg_temp_new_i32();
6317 tcg_gen_shri_i64(val
, val
, 32);
6318 tcg_gen_trunc_i64_i32(tmp
, val
);
6319 store_reg(s
, rhigh
, tmp
);
6322 /* load a 32-bit value from a register and perform a 64-bit accumulate. */
6323 static void gen_addq_lo(DisasContext
*s
, TCGv_i64 val
, int rlow
)
6328 /* Load value and extend to 64 bits. */
6329 tmp
= tcg_temp_new_i64();
6330 tmp2
= load_reg(s
, rlow
);
6331 tcg_gen_extu_i32_i64(tmp
, tmp2
);
6332 tcg_temp_free_i32(tmp2
);
6333 tcg_gen_add_i64(val
, val
, tmp
);
6334 tcg_temp_free_i64(tmp
);
6337 /* load and add a 64-bit value from a register pair. */
6338 static void gen_addq(DisasContext
*s
, TCGv_i64 val
, int rlow
, int rhigh
)
6344 /* Load 64-bit value rd:rn. */
6345 tmpl
= load_reg(s
, rlow
);
6346 tmph
= load_reg(s
, rhigh
);
6347 tmp
= tcg_temp_new_i64();
6348 tcg_gen_concat_i32_i64(tmp
, tmpl
, tmph
);
6349 tcg_temp_free_i32(tmpl
);
6350 tcg_temp_free_i32(tmph
);
6351 tcg_gen_add_i64(val
, val
, tmp
);
6352 tcg_temp_free_i64(tmp
);
6355 /* Set N and Z flags from a 64-bit value. */
6356 static void gen_logicq_cc(TCGv_i64 val
)
6358 TCGv tmp
= tcg_temp_new_i32();
6359 gen_helper_logicq_cc(tmp
, val
);
6361 tcg_temp_free_i32(tmp
);
6364 /* Load/Store exclusive instructions are implemented by remembering
6365 the value/address loaded, and seeing if these are the same
6366 when the store is performed. This should be is sufficient to implement
6367 the architecturally mandated semantics, and avoids having to monitor
6370 In system emulation mode only one CPU will be running at once, so
6371 this sequence is effectively atomic. In user emulation mode we
6372 throw an exception and handle the atomic operation elsewhere. */
6373 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
6374 TCGv addr
, int size
)
6380 tmp
= gen_ld8u(addr
, IS_USER(s
));
6383 tmp
= gen_ld16u(addr
, IS_USER(s
));
6387 tmp
= gen_ld32(addr
, IS_USER(s
));
6392 tcg_gen_mov_i32(cpu_exclusive_val
, tmp
);
6393 store_reg(s
, rt
, tmp
);
6395 TCGv tmp2
= tcg_temp_new_i32();
6396 tcg_gen_addi_i32(tmp2
, addr
, 4);
6397 tmp
= gen_ld32(tmp2
, IS_USER(s
));
6398 tcg_temp_free_i32(tmp2
);
6399 tcg_gen_mov_i32(cpu_exclusive_high
, tmp
);
6400 store_reg(s
, rt2
, tmp
);
6402 tcg_gen_mov_i32(cpu_exclusive_addr
, addr
);
6405 static void gen_clrex(DisasContext
*s
)
6407 tcg_gen_movi_i32(cpu_exclusive_addr
, -1);
6410 #ifdef CONFIG_USER_ONLY
6411 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
6412 TCGv addr
, int size
)
6414 tcg_gen_mov_i32(cpu_exclusive_test
, addr
);
6415 tcg_gen_movi_i32(cpu_exclusive_info
,
6416 size
| (rd
<< 4) | (rt
<< 8) | (rt2
<< 12));
6417 gen_exception_insn(s
, 4, EXCP_STREX
);
6420 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
6421 TCGv addr
, int size
)
6427 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]) {
6433 fail_label
= gen_new_label();
6434 done_label
= gen_new_label();
6435 tcg_gen_brcond_i32(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
6438 tmp
= gen_ld8u(addr
, IS_USER(s
));
6441 tmp
= gen_ld16u(addr
, IS_USER(s
));
6445 tmp
= gen_ld32(addr
, IS_USER(s
));
6450 tcg_gen_brcond_i32(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
6451 tcg_temp_free_i32(tmp
);
6453 TCGv tmp2
= tcg_temp_new_i32();
6454 tcg_gen_addi_i32(tmp2
, addr
, 4);
6455 tmp
= gen_ld32(tmp2
, IS_USER(s
));
6456 tcg_temp_free_i32(tmp2
);
6457 tcg_gen_brcond_i32(TCG_COND_NE
, tmp
, cpu_exclusive_high
, fail_label
);
6458 tcg_temp_free_i32(tmp
);
6460 tmp
= load_reg(s
, rt
);
6463 gen_st8(tmp
, addr
, IS_USER(s
));
6466 gen_st16(tmp
, addr
, IS_USER(s
));
6470 gen_st32(tmp
, addr
, IS_USER(s
));
6476 tcg_gen_addi_i32(addr
, addr
, 4);
6477 tmp
= load_reg(s
, rt2
);
6478 gen_st32(tmp
, addr
, IS_USER(s
));
6480 tcg_gen_movi_i32(cpu_R
[rd
], 0);
6481 tcg_gen_br(done_label
);
6482 gen_set_label(fail_label
);
6483 tcg_gen_movi_i32(cpu_R
[rd
], 1);
6484 gen_set_label(done_label
);
6485 tcg_gen_movi_i32(cpu_exclusive_addr
, -1);
6489 static void disas_arm_insn(CPUState
* env
, DisasContext
*s
)
6491 unsigned int cond
, insn
, val
, op1
, i
, shift
, rm
, rs
, rn
, rd
, sh
;
6498 insn
= ldl_code(s
->pc
);
6501 /* M variants do not implement ARM mode. */
6506 /* In ARMv3 and v4 the NV condition is UNPREDICTABLE; we
6507 * choose to UNDEF. In ARMv5 and above the space is used
6508 * for miscellaneous unconditional instructions.
6512 /* Unconditional instructions. */
6513 if (((insn
>> 25) & 7) == 1) {
6514 /* NEON Data processing. */
6515 if (!arm_feature(env
, ARM_FEATURE_NEON
))
6518 if (disas_neon_data_insn(env
, s
, insn
))
6522 if ((insn
& 0x0f100000) == 0x04000000) {
6523 /* NEON load/store. */
6524 if (!arm_feature(env
, ARM_FEATURE_NEON
))
6527 if (disas_neon_ls_insn(env
, s
, insn
))
6531 if (((insn
& 0x0f30f000) == 0x0510f000) ||
6532 ((insn
& 0x0f30f010) == 0x0710f000)) {
6533 if ((insn
& (1 << 22)) == 0) {
6535 if (!arm_feature(env
, ARM_FEATURE_V7MP
)) {
6539 /* Otherwise PLD; v5TE+ */
6543 if (((insn
& 0x0f70f000) == 0x0450f000) ||
6544 ((insn
& 0x0f70f010) == 0x0650f000)) {
6546 return; /* PLI; V7 */
6548 if (((insn
& 0x0f700000) == 0x04100000) ||
6549 ((insn
& 0x0f700010) == 0x06100000)) {
6550 if (!arm_feature(env
, ARM_FEATURE_V7MP
)) {
6553 return; /* v7MP: Unallocated memory hint: must NOP */
6556 if ((insn
& 0x0ffffdff) == 0x01010000) {
6559 if (insn
& (1 << 9)) {
6560 /* BE8 mode not implemented. */
6564 } else if ((insn
& 0x0fffff00) == 0x057ff000) {
6565 switch ((insn
>> 4) & 0xf) {
6574 /* We don't emulate caches so these are a no-op. */
6579 } else if ((insn
& 0x0e5fffe0) == 0x084d0500) {
6585 op1
= (insn
& 0x1f);
6586 addr
= tcg_temp_new_i32();
6587 tmp
= tcg_const_i32(op1
);
6588 gen_helper_get_r13_banked(addr
, cpu_env
, tmp
);
6589 tcg_temp_free_i32(tmp
);
6590 i
= (insn
>> 23) & 3;
6592 case 0: offset
= -4; break; /* DA */
6593 case 1: offset
= 0; break; /* IA */
6594 case 2: offset
= -8; break; /* DB */
6595 case 3: offset
= 4; break; /* IB */
6599 tcg_gen_addi_i32(addr
, addr
, offset
);
6600 tmp
= load_reg(s
, 14);
6601 gen_st32(tmp
, addr
, 0);
6602 tmp
= load_cpu_field(spsr
);
6603 tcg_gen_addi_i32(addr
, addr
, 4);
6604 gen_st32(tmp
, addr
, 0);
6605 if (insn
& (1 << 21)) {
6606 /* Base writeback. */
6608 case 0: offset
= -8; break;
6609 case 1: offset
= 4; break;
6610 case 2: offset
= -4; break;
6611 case 3: offset
= 0; break;
6615 tcg_gen_addi_i32(addr
, addr
, offset
);
6616 tmp
= tcg_const_i32(op1
);
6617 gen_helper_set_r13_banked(cpu_env
, tmp
, addr
);
6618 tcg_temp_free_i32(tmp
);
6619 tcg_temp_free_i32(addr
);
6621 tcg_temp_free_i32(addr
);
6624 } else if ((insn
& 0x0e50ffe0) == 0x08100a00) {
6630 rn
= (insn
>> 16) & 0xf;
6631 addr
= load_reg(s
, rn
);
6632 i
= (insn
>> 23) & 3;
6634 case 0: offset
= -4; break; /* DA */
6635 case 1: offset
= 0; break; /* IA */
6636 case 2: offset
= -8; break; /* DB */
6637 case 3: offset
= 4; break; /* IB */
6641 tcg_gen_addi_i32(addr
, addr
, offset
);
6642 /* Load PC into tmp and CPSR into tmp2. */
6643 tmp
= gen_ld32(addr
, 0);
6644 tcg_gen_addi_i32(addr
, addr
, 4);
6645 tmp2
= gen_ld32(addr
, 0);
6646 if (insn
& (1 << 21)) {
6647 /* Base writeback. */
6649 case 0: offset
= -8; break;
6650 case 1: offset
= 4; break;
6651 case 2: offset
= -4; break;
6652 case 3: offset
= 0; break;
6656 tcg_gen_addi_i32(addr
, addr
, offset
);
6657 store_reg(s
, rn
, addr
);
6659 tcg_temp_free_i32(addr
);
6661 gen_rfe(s
, tmp
, tmp2
);
6663 } else if ((insn
& 0x0e000000) == 0x0a000000) {
6664 /* branch link and change to thumb (blx <offset>) */
6667 val
= (uint32_t)s
->pc
;
6668 tmp
= tcg_temp_new_i32();
6669 tcg_gen_movi_i32(tmp
, val
);
6670 store_reg(s
, 14, tmp
);
6671 /* Sign-extend the 24-bit offset */
6672 offset
= (((int32_t)insn
) << 8) >> 8;
6673 /* offset * 4 + bit24 * 2 + (thumb bit) */
6674 val
+= (offset
<< 2) | ((insn
>> 23) & 2) | 1;
6675 /* pipeline offset */
6677 /* protected by ARCH(5); above, near the start of uncond block */
6680 } else if ((insn
& 0x0e000f00) == 0x0c000100) {
6681 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
6682 /* iWMMXt register transfer. */
6683 if (env
->cp15
.c15_cpar
& (1 << 1))
6684 if (!disas_iwmmxt_insn(env
, s
, insn
))
6687 } else if ((insn
& 0x0fe00000) == 0x0c400000) {
6688 /* Coprocessor double register transfer. */
6690 } else if ((insn
& 0x0f000010) == 0x0e000010) {
6691 /* Additional coprocessor register transfer. */
6692 } else if ((insn
& 0x0ff10020) == 0x01000000) {
6695 /* cps (privileged) */
6699 if (insn
& (1 << 19)) {
6700 if (insn
& (1 << 8))
6702 if (insn
& (1 << 7))
6704 if (insn
& (1 << 6))
6706 if (insn
& (1 << 18))
6709 if (insn
& (1 << 17)) {
6711 val
|= (insn
& 0x1f);
6714 gen_set_psr_im(s
, mask
, 0, val
);
6721 /* if not always execute, we generate a conditional jump to
6723 s
->condlabel
= gen_new_label();
6724 gen_test_cc(cond
^ 1, s
->condlabel
);
6727 if ((insn
& 0x0f900000) == 0x03000000) {
6728 if ((insn
& (1 << 21)) == 0) {
6730 rd
= (insn
>> 12) & 0xf;
6731 val
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
6732 if ((insn
& (1 << 22)) == 0) {
6734 tmp
= tcg_temp_new_i32();
6735 tcg_gen_movi_i32(tmp
, val
);
6738 tmp
= load_reg(s
, rd
);
6739 tcg_gen_ext16u_i32(tmp
, tmp
);
6740 tcg_gen_ori_i32(tmp
, tmp
, val
<< 16);
6742 store_reg(s
, rd
, tmp
);
6744 if (((insn
>> 12) & 0xf) != 0xf)
6746 if (((insn
>> 16) & 0xf) == 0) {
6747 gen_nop_hint(s
, insn
& 0xff);
6749 /* CPSR = immediate */
6751 shift
= ((insn
>> 8) & 0xf) * 2;
6753 val
= (val
>> shift
) | (val
<< (32 - shift
));
6754 i
= ((insn
& (1 << 22)) != 0);
6755 if (gen_set_psr_im(s
, msr_mask(env
, s
, (insn
>> 16) & 0xf, i
), i
, val
))
6759 } else if ((insn
& 0x0f900000) == 0x01000000
6760 && (insn
& 0x00000090) != 0x00000090) {
6761 /* miscellaneous instructions */
6762 op1
= (insn
>> 21) & 3;
6763 sh
= (insn
>> 4) & 0xf;
6766 case 0x0: /* move program status register */
6769 tmp
= load_reg(s
, rm
);
6770 i
= ((op1
& 2) != 0);
6771 if (gen_set_psr(s
, msr_mask(env
, s
, (insn
>> 16) & 0xf, i
), i
, tmp
))
6775 rd
= (insn
>> 12) & 0xf;
6779 tmp
= load_cpu_field(spsr
);
6781 tmp
= tcg_temp_new_i32();
6782 gen_helper_cpsr_read(tmp
);
6784 store_reg(s
, rd
, tmp
);
6789 /* branch/exchange thumb (bx). */
6791 tmp
= load_reg(s
, rm
);
6793 } else if (op1
== 3) {
6796 rd
= (insn
>> 12) & 0xf;
6797 tmp
= load_reg(s
, rm
);
6798 gen_helper_clz(tmp
, tmp
);
6799 store_reg(s
, rd
, tmp
);
6807 /* Trivial implementation equivalent to bx. */
6808 tmp
= load_reg(s
, rm
);
6819 /* branch link/exchange thumb (blx) */
6820 tmp
= load_reg(s
, rm
);
6821 tmp2
= tcg_temp_new_i32();
6822 tcg_gen_movi_i32(tmp2
, s
->pc
);
6823 store_reg(s
, 14, tmp2
);
6826 case 0x5: /* saturating add/subtract */
6828 rd
= (insn
>> 12) & 0xf;
6829 rn
= (insn
>> 16) & 0xf;
6830 tmp
= load_reg(s
, rm
);
6831 tmp2
= load_reg(s
, rn
);
6833 gen_helper_double_saturate(tmp2
, tmp2
);
6835 gen_helper_sub_saturate(tmp
, tmp
, tmp2
);
6837 gen_helper_add_saturate(tmp
, tmp
, tmp2
);
6838 tcg_temp_free_i32(tmp2
);
6839 store_reg(s
, rd
, tmp
);
6842 /* SMC instruction (op1 == 3)
6843 and undefined instructions (op1 == 0 || op1 == 2)
6850 gen_exception_insn(s
, 4, EXCP_BKPT
);
6852 case 0x8: /* signed multiply */
6857 rs
= (insn
>> 8) & 0xf;
6858 rn
= (insn
>> 12) & 0xf;
6859 rd
= (insn
>> 16) & 0xf;
6861 /* (32 * 16) >> 16 */
6862 tmp
= load_reg(s
, rm
);
6863 tmp2
= load_reg(s
, rs
);
6865 tcg_gen_sari_i32(tmp2
, tmp2
, 16);
6868 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
6869 tcg_gen_shri_i64(tmp64
, tmp64
, 16);
6870 tmp
= tcg_temp_new_i32();
6871 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
6872 tcg_temp_free_i64(tmp64
);
6873 if ((sh
& 2) == 0) {
6874 tmp2
= load_reg(s
, rn
);
6875 gen_helper_add_setq(tmp
, tmp
, tmp2
);
6876 tcg_temp_free_i32(tmp2
);
6878 store_reg(s
, rd
, tmp
);
6881 tmp
= load_reg(s
, rm
);
6882 tmp2
= load_reg(s
, rs
);
6883 gen_mulxy(tmp
, tmp2
, sh
& 2, sh
& 4);
6884 tcg_temp_free_i32(tmp2
);
6886 tmp64
= tcg_temp_new_i64();
6887 tcg_gen_ext_i32_i64(tmp64
, tmp
);
6888 tcg_temp_free_i32(tmp
);
6889 gen_addq(s
, tmp64
, rn
, rd
);
6890 gen_storeq_reg(s
, rn
, rd
, tmp64
);
6891 tcg_temp_free_i64(tmp64
);
6894 tmp2
= load_reg(s
, rn
);
6895 gen_helper_add_setq(tmp
, tmp
, tmp2
);
6896 tcg_temp_free_i32(tmp2
);
6898 store_reg(s
, rd
, tmp
);
6905 } else if (((insn
& 0x0e000000) == 0 &&
6906 (insn
& 0x00000090) != 0x90) ||
6907 ((insn
& 0x0e000000) == (1 << 25))) {
6908 int set_cc
, logic_cc
, shiftop
;
6910 op1
= (insn
>> 21) & 0xf;
6911 set_cc
= (insn
>> 20) & 1;
6912 logic_cc
= table_logic_cc
[op1
] & set_cc
;
6914 /* data processing instruction */
6915 if (insn
& (1 << 25)) {
6916 /* immediate operand */
6918 shift
= ((insn
>> 8) & 0xf) * 2;
6920 val
= (val
>> shift
) | (val
<< (32 - shift
));
6922 tmp2
= tcg_temp_new_i32();
6923 tcg_gen_movi_i32(tmp2
, val
);
6924 if (logic_cc
&& shift
) {
6925 gen_set_CF_bit31(tmp2
);
6930 tmp2
= load_reg(s
, rm
);
6931 shiftop
= (insn
>> 5) & 3;
6932 if (!(insn
& (1 << 4))) {
6933 shift
= (insn
>> 7) & 0x1f;
6934 gen_arm_shift_im(tmp2
, shiftop
, shift
, logic_cc
);
6936 rs
= (insn
>> 8) & 0xf;
6937 tmp
= load_reg(s
, rs
);
6938 gen_arm_shift_reg(tmp2
, shiftop
, tmp
, logic_cc
);
6941 if (op1
!= 0x0f && op1
!= 0x0d) {
6942 rn
= (insn
>> 16) & 0xf;
6943 tmp
= load_reg(s
, rn
);
6947 rd
= (insn
>> 12) & 0xf;
6950 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
6954 store_reg_bx(env
, s
, rd
, tmp
);
6957 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
6961 store_reg_bx(env
, s
, rd
, tmp
);
6964 if (set_cc
&& rd
== 15) {
6965 /* SUBS r15, ... is used for exception return. */
6969 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
6970 gen_exception_return(s
, tmp
);
6973 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
6975 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
6977 store_reg_bx(env
, s
, rd
, tmp
);
6982 gen_helper_sub_cc(tmp
, tmp2
, tmp
);
6984 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
6986 store_reg_bx(env
, s
, rd
, tmp
);
6990 gen_helper_add_cc(tmp
, tmp
, tmp2
);
6992 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
6994 store_reg_bx(env
, s
, rd
, tmp
);
6998 gen_helper_adc_cc(tmp
, tmp
, tmp2
);
7000 gen_add_carry(tmp
, tmp
, tmp2
);
7002 store_reg_bx(env
, s
, rd
, tmp
);
7006 gen_helper_sbc_cc(tmp
, tmp
, tmp2
);
7008 gen_sub_carry(tmp
, tmp
, tmp2
);
7010 store_reg_bx(env
, s
, rd
, tmp
);
7014 gen_helper_sbc_cc(tmp
, tmp2
, tmp
);
7016 gen_sub_carry(tmp
, tmp2
, tmp
);
7018 store_reg_bx(env
, s
, rd
, tmp
);
7022 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
7025 tcg_temp_free_i32(tmp
);
7029 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
7032 tcg_temp_free_i32(tmp
);
7036 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
7038 tcg_temp_free_i32(tmp
);
7042 gen_helper_add_cc(tmp
, tmp
, tmp2
);
7044 tcg_temp_free_i32(tmp
);
7047 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
7051 store_reg_bx(env
, s
, rd
, tmp
);
7054 if (logic_cc
&& rd
== 15) {
7055 /* MOVS r15, ... is used for exception return. */
7059 gen_exception_return(s
, tmp2
);
7064 store_reg_bx(env
, s
, rd
, tmp2
);
7068 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
7072 store_reg_bx(env
, s
, rd
, tmp
);
7076 tcg_gen_not_i32(tmp2
, tmp2
);
7080 store_reg_bx(env
, s
, rd
, tmp2
);
7083 if (op1
!= 0x0f && op1
!= 0x0d) {
7084 tcg_temp_free_i32(tmp2
);
7087 /* other instructions */
7088 op1
= (insn
>> 24) & 0xf;
7092 /* multiplies, extra load/stores */
7093 sh
= (insn
>> 5) & 3;
7096 rd
= (insn
>> 16) & 0xf;
7097 rn
= (insn
>> 12) & 0xf;
7098 rs
= (insn
>> 8) & 0xf;
7100 op1
= (insn
>> 20) & 0xf;
7102 case 0: case 1: case 2: case 3: case 6:
7104 tmp
= load_reg(s
, rs
);
7105 tmp2
= load_reg(s
, rm
);
7106 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
7107 tcg_temp_free_i32(tmp2
);
7108 if (insn
& (1 << 22)) {
7109 /* Subtract (mls) */
7111 tmp2
= load_reg(s
, rn
);
7112 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
7113 tcg_temp_free_i32(tmp2
);
7114 } else if (insn
& (1 << 21)) {
7116 tmp2
= load_reg(s
, rn
);
7117 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7118 tcg_temp_free_i32(tmp2
);
7120 if (insn
& (1 << 20))
7122 store_reg(s
, rd
, tmp
);
7125 /* 64 bit mul double accumulate (UMAAL) */
7127 tmp
= load_reg(s
, rs
);
7128 tmp2
= load_reg(s
, rm
);
7129 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
7130 gen_addq_lo(s
, tmp64
, rn
);
7131 gen_addq_lo(s
, tmp64
, rd
);
7132 gen_storeq_reg(s
, rn
, rd
, tmp64
);
7133 tcg_temp_free_i64(tmp64
);
7135 case 8: case 9: case 10: case 11:
7136 case 12: case 13: case 14: case 15:
7137 /* 64 bit mul: UMULL, UMLAL, SMULL, SMLAL. */
7138 tmp
= load_reg(s
, rs
);
7139 tmp2
= load_reg(s
, rm
);
7140 if (insn
& (1 << 22)) {
7141 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
7143 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
7145 if (insn
& (1 << 21)) { /* mult accumulate */
7146 gen_addq(s
, tmp64
, rn
, rd
);
7148 if (insn
& (1 << 20)) {
7149 gen_logicq_cc(tmp64
);
7151 gen_storeq_reg(s
, rn
, rd
, tmp64
);
7152 tcg_temp_free_i64(tmp64
);
7158 rn
= (insn
>> 16) & 0xf;
7159 rd
= (insn
>> 12) & 0xf;
7160 if (insn
& (1 << 23)) {
7161 /* load/store exclusive */
7162 op1
= (insn
>> 21) & 0x3;
7167 addr
= tcg_temp_local_new_i32();
7168 load_reg_var(s
, addr
, rn
);
7169 if (insn
& (1 << 20)) {
7172 gen_load_exclusive(s
, rd
, 15, addr
, 2);
7174 case 1: /* ldrexd */
7175 gen_load_exclusive(s
, rd
, rd
+ 1, addr
, 3);
7177 case 2: /* ldrexb */
7178 gen_load_exclusive(s
, rd
, 15, addr
, 0);
7180 case 3: /* ldrexh */
7181 gen_load_exclusive(s
, rd
, 15, addr
, 1);
7190 gen_store_exclusive(s
, rd
, rm
, 15, addr
, 2);
7192 case 1: /* strexd */
7193 gen_store_exclusive(s
, rd
, rm
, rm
+ 1, addr
, 3);
7195 case 2: /* strexb */
7196 gen_store_exclusive(s
, rd
, rm
, 15, addr
, 0);
7198 case 3: /* strexh */
7199 gen_store_exclusive(s
, rd
, rm
, 15, addr
, 1);
7205 tcg_temp_free(addr
);
7207 /* SWP instruction */
7210 /* ??? This is not really atomic. However we know
7211 we never have multiple CPUs running in parallel,
7212 so it is good enough. */
7213 addr
= load_reg(s
, rn
);
7214 tmp
= load_reg(s
, rm
);
7215 if (insn
& (1 << 22)) {
7216 tmp2
= gen_ld8u(addr
, IS_USER(s
));
7217 gen_st8(tmp
, addr
, IS_USER(s
));
7219 tmp2
= gen_ld32(addr
, IS_USER(s
));
7220 gen_st32(tmp
, addr
, IS_USER(s
));
7222 tcg_temp_free_i32(addr
);
7223 store_reg(s
, rd
, tmp2
);
7229 /* Misc load/store */
7230 rn
= (insn
>> 16) & 0xf;
7231 rd
= (insn
>> 12) & 0xf;
7232 addr
= load_reg(s
, rn
);
7233 if (insn
& (1 << 24))
7234 gen_add_datah_offset(s
, insn
, 0, addr
);
7236 if (insn
& (1 << 20)) {
7240 tmp
= gen_ld16u(addr
, IS_USER(s
));
7243 tmp
= gen_ld8s(addr
, IS_USER(s
));
7247 tmp
= gen_ld16s(addr
, IS_USER(s
));
7251 } else if (sh
& 2) {
7256 tmp
= load_reg(s
, rd
);
7257 gen_st32(tmp
, addr
, IS_USER(s
));
7258 tcg_gen_addi_i32(addr
, addr
, 4);
7259 tmp
= load_reg(s
, rd
+ 1);
7260 gen_st32(tmp
, addr
, IS_USER(s
));
7264 tmp
= gen_ld32(addr
, IS_USER(s
));
7265 store_reg(s
, rd
, tmp
);
7266 tcg_gen_addi_i32(addr
, addr
, 4);
7267 tmp
= gen_ld32(addr
, IS_USER(s
));
7271 address_offset
= -4;
7274 tmp
= load_reg(s
, rd
);
7275 gen_st16(tmp
, addr
, IS_USER(s
));
7278 /* Perform base writeback before the loaded value to
7279 ensure correct behavior with overlapping index registers.
7280 ldrd with base writeback is is undefined if the
7281 destination and index registers overlap. */
7282 if (!(insn
& (1 << 24))) {
7283 gen_add_datah_offset(s
, insn
, address_offset
, addr
);
7284 store_reg(s
, rn
, addr
);
7285 } else if (insn
& (1 << 21)) {
7287 tcg_gen_addi_i32(addr
, addr
, address_offset
);
7288 store_reg(s
, rn
, addr
);
7290 tcg_temp_free_i32(addr
);
7293 /* Complete the load. */
7294 store_reg(s
, rd
, tmp
);
7303 if (insn
& (1 << 4)) {
7305 /* Armv6 Media instructions. */
7307 rn
= (insn
>> 16) & 0xf;
7308 rd
= (insn
>> 12) & 0xf;
7309 rs
= (insn
>> 8) & 0xf;
7310 switch ((insn
>> 23) & 3) {
7311 case 0: /* Parallel add/subtract. */
7312 op1
= (insn
>> 20) & 7;
7313 tmp
= load_reg(s
, rn
);
7314 tmp2
= load_reg(s
, rm
);
7315 sh
= (insn
>> 5) & 7;
7316 if ((op1
& 3) == 0 || sh
== 5 || sh
== 6)
7318 gen_arm_parallel_addsub(op1
, sh
, tmp
, tmp2
);
7319 tcg_temp_free_i32(tmp2
);
7320 store_reg(s
, rd
, tmp
);
7323 if ((insn
& 0x00700020) == 0) {
7324 /* Halfword pack. */
7325 tmp
= load_reg(s
, rn
);
7326 tmp2
= load_reg(s
, rm
);
7327 shift
= (insn
>> 7) & 0x1f;
7328 if (insn
& (1 << 6)) {
7332 tcg_gen_sari_i32(tmp2
, tmp2
, shift
);
7333 tcg_gen_andi_i32(tmp
, tmp
, 0xffff0000);
7334 tcg_gen_ext16u_i32(tmp2
, tmp2
);
7338 tcg_gen_shli_i32(tmp2
, tmp2
, shift
);
7339 tcg_gen_ext16u_i32(tmp
, tmp
);
7340 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffff0000);
7342 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
7343 tcg_temp_free_i32(tmp2
);
7344 store_reg(s
, rd
, tmp
);
7345 } else if ((insn
& 0x00200020) == 0x00200000) {
7347 tmp
= load_reg(s
, rm
);
7348 shift
= (insn
>> 7) & 0x1f;
7349 if (insn
& (1 << 6)) {
7352 tcg_gen_sari_i32(tmp
, tmp
, shift
);
7354 tcg_gen_shli_i32(tmp
, tmp
, shift
);
7356 sh
= (insn
>> 16) & 0x1f;
7357 tmp2
= tcg_const_i32(sh
);
7358 if (insn
& (1 << 22))
7359 gen_helper_usat(tmp
, tmp
, tmp2
);
7361 gen_helper_ssat(tmp
, tmp
, tmp2
);
7362 tcg_temp_free_i32(tmp2
);
7363 store_reg(s
, rd
, tmp
);
7364 } else if ((insn
& 0x00300fe0) == 0x00200f20) {
7366 tmp
= load_reg(s
, rm
);
7367 sh
= (insn
>> 16) & 0x1f;
7368 tmp2
= tcg_const_i32(sh
);
7369 if (insn
& (1 << 22))
7370 gen_helper_usat16(tmp
, tmp
, tmp2
);
7372 gen_helper_ssat16(tmp
, tmp
, tmp2
);
7373 tcg_temp_free_i32(tmp2
);
7374 store_reg(s
, rd
, tmp
);
7375 } else if ((insn
& 0x00700fe0) == 0x00000fa0) {
7377 tmp
= load_reg(s
, rn
);
7378 tmp2
= load_reg(s
, rm
);
7379 tmp3
= tcg_temp_new_i32();
7380 tcg_gen_ld_i32(tmp3
, cpu_env
, offsetof(CPUState
, GE
));
7381 gen_helper_sel_flags(tmp
, tmp3
, tmp
, tmp2
);
7382 tcg_temp_free_i32(tmp3
);
7383 tcg_temp_free_i32(tmp2
);
7384 store_reg(s
, rd
, tmp
);
7385 } else if ((insn
& 0x000003e0) == 0x00000060) {
7386 tmp
= load_reg(s
, rm
);
7387 shift
= (insn
>> 10) & 3;
7388 /* ??? In many cases it's not necessary to do a
7389 rotate, a shift is sufficient. */
7391 tcg_gen_rotri_i32(tmp
, tmp
, shift
* 8);
7392 op1
= (insn
>> 20) & 7;
7394 case 0: gen_sxtb16(tmp
); break;
7395 case 2: gen_sxtb(tmp
); break;
7396 case 3: gen_sxth(tmp
); break;
7397 case 4: gen_uxtb16(tmp
); break;
7398 case 6: gen_uxtb(tmp
); break;
7399 case 7: gen_uxth(tmp
); break;
7400 default: goto illegal_op
;
7403 tmp2
= load_reg(s
, rn
);
7404 if ((op1
& 3) == 0) {
7405 gen_add16(tmp
, tmp2
);
7407 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7408 tcg_temp_free_i32(tmp2
);
7411 store_reg(s
, rd
, tmp
);
7412 } else if ((insn
& 0x003f0f60) == 0x003f0f20) {
7414 tmp
= load_reg(s
, rm
);
7415 if (insn
& (1 << 22)) {
7416 if (insn
& (1 << 7)) {
7420 gen_helper_rbit(tmp
, tmp
);
7423 if (insn
& (1 << 7))
7426 tcg_gen_bswap32_i32(tmp
, tmp
);
7428 store_reg(s
, rd
, tmp
);
7433 case 2: /* Multiplies (Type 3). */
7434 tmp
= load_reg(s
, rm
);
7435 tmp2
= load_reg(s
, rs
);
7436 if (insn
& (1 << 20)) {
7437 /* Signed multiply most significant [accumulate].
7438 (SMMUL, SMMLA, SMMLS) */
7439 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
7442 tmp
= load_reg(s
, rd
);
7443 if (insn
& (1 << 6)) {
7444 tmp64
= gen_subq_msw(tmp64
, tmp
);
7446 tmp64
= gen_addq_msw(tmp64
, tmp
);
7449 if (insn
& (1 << 5)) {
7450 tcg_gen_addi_i64(tmp64
, tmp64
, 0x80000000u
);
7452 tcg_gen_shri_i64(tmp64
, tmp64
, 32);
7453 tmp
= tcg_temp_new_i32();
7454 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
7455 tcg_temp_free_i64(tmp64
);
7456 store_reg(s
, rn
, tmp
);
7458 if (insn
& (1 << 5))
7459 gen_swap_half(tmp2
);
7460 gen_smul_dual(tmp
, tmp2
);
7461 if (insn
& (1 << 6)) {
7462 /* This subtraction cannot overflow. */
7463 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
7465 /* This addition cannot overflow 32 bits;
7466 * however it may overflow considered as a signed
7467 * operation, in which case we must set the Q flag.
7469 gen_helper_add_setq(tmp
, tmp
, tmp2
);
7471 tcg_temp_free_i32(tmp2
);
7472 if (insn
& (1 << 22)) {
7473 /* smlald, smlsld */
7474 tmp64
= tcg_temp_new_i64();
7475 tcg_gen_ext_i32_i64(tmp64
, tmp
);
7476 tcg_temp_free_i32(tmp
);
7477 gen_addq(s
, tmp64
, rd
, rn
);
7478 gen_storeq_reg(s
, rd
, rn
, tmp64
);
7479 tcg_temp_free_i64(tmp64
);
7481 /* smuad, smusd, smlad, smlsd */
7484 tmp2
= load_reg(s
, rd
);
7485 gen_helper_add_setq(tmp
, tmp
, tmp2
);
7486 tcg_temp_free_i32(tmp2
);
7488 store_reg(s
, rn
, tmp
);
7493 op1
= ((insn
>> 17) & 0x38) | ((insn
>> 5) & 7);
7495 case 0: /* Unsigned sum of absolute differences. */
7497 tmp
= load_reg(s
, rm
);
7498 tmp2
= load_reg(s
, rs
);
7499 gen_helper_usad8(tmp
, tmp
, tmp2
);
7500 tcg_temp_free_i32(tmp2
);
7502 tmp2
= load_reg(s
, rd
);
7503 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7504 tcg_temp_free_i32(tmp2
);
7506 store_reg(s
, rn
, tmp
);
7508 case 0x20: case 0x24: case 0x28: case 0x2c:
7509 /* Bitfield insert/clear. */
7511 shift
= (insn
>> 7) & 0x1f;
7512 i
= (insn
>> 16) & 0x1f;
7515 tmp
= tcg_temp_new_i32();
7516 tcg_gen_movi_i32(tmp
, 0);
7518 tmp
= load_reg(s
, rm
);
7521 tmp2
= load_reg(s
, rd
);
7522 gen_bfi(tmp
, tmp2
, tmp
, shift
, (1u << i
) - 1);
7523 tcg_temp_free_i32(tmp2
);
7525 store_reg(s
, rd
, tmp
);
7527 case 0x12: case 0x16: case 0x1a: case 0x1e: /* sbfx */
7528 case 0x32: case 0x36: case 0x3a: case 0x3e: /* ubfx */
7530 tmp
= load_reg(s
, rm
);
7531 shift
= (insn
>> 7) & 0x1f;
7532 i
= ((insn
>> 16) & 0x1f) + 1;
7537 gen_ubfx(tmp
, shift
, (1u << i
) - 1);
7539 gen_sbfx(tmp
, shift
, i
);
7542 store_reg(s
, rd
, tmp
);
7552 /* Check for undefined extension instructions
7553 * per the ARM Bible IE:
7554 * xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
7556 sh
= (0xf << 20) | (0xf << 4);
7557 if (op1
== 0x7 && ((insn
& sh
) == sh
))
7561 /* load/store byte/word */
7562 rn
= (insn
>> 16) & 0xf;
7563 rd
= (insn
>> 12) & 0xf;
7564 tmp2
= load_reg(s
, rn
);
7565 i
= (IS_USER(s
) || (insn
& 0x01200000) == 0x00200000);
7566 if (insn
& (1 << 24))
7567 gen_add_data_offset(s
, insn
, tmp2
);
7568 if (insn
& (1 << 20)) {
7570 if (insn
& (1 << 22)) {
7571 tmp
= gen_ld8u(tmp2
, i
);
7573 tmp
= gen_ld32(tmp2
, i
);
7577 tmp
= load_reg(s
, rd
);
7578 if (insn
& (1 << 22))
7579 gen_st8(tmp
, tmp2
, i
);
7581 gen_st32(tmp
, tmp2
, i
);
7583 if (!(insn
& (1 << 24))) {
7584 gen_add_data_offset(s
, insn
, tmp2
);
7585 store_reg(s
, rn
, tmp2
);
7586 } else if (insn
& (1 << 21)) {
7587 store_reg(s
, rn
, tmp2
);
7589 tcg_temp_free_i32(tmp2
);
7591 if (insn
& (1 << 20)) {
7592 /* Complete the load. */
7593 store_reg_from_load(env
, s
, rd
, tmp
);
7599 int j
, n
, user
, loaded_base
;
7601 /* load/store multiple words */
7602 /* XXX: store correct base if write back */
7604 if (insn
& (1 << 22)) {
7606 goto illegal_op
; /* only usable in supervisor mode */
7608 if ((insn
& (1 << 15)) == 0)
7611 rn
= (insn
>> 16) & 0xf;
7612 addr
= load_reg(s
, rn
);
7614 /* compute total size */
7616 TCGV_UNUSED(loaded_var
);
7619 if (insn
& (1 << i
))
7622 /* XXX: test invalid n == 0 case ? */
7623 if (insn
& (1 << 23)) {
7624 if (insn
& (1 << 24)) {
7626 tcg_gen_addi_i32(addr
, addr
, 4);
7628 /* post increment */
7631 if (insn
& (1 << 24)) {
7633 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
7635 /* post decrement */
7637 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
7642 if (insn
& (1 << i
)) {
7643 if (insn
& (1 << 20)) {
7645 tmp
= gen_ld32(addr
, IS_USER(s
));
7647 tmp2
= tcg_const_i32(i
);
7648 gen_helper_set_user_reg(tmp2
, tmp
);
7649 tcg_temp_free_i32(tmp2
);
7650 tcg_temp_free_i32(tmp
);
7651 } else if (i
== rn
) {
7655 store_reg_from_load(env
, s
, i
, tmp
);
7660 /* special case: r15 = PC + 8 */
7661 val
= (long)s
->pc
+ 4;
7662 tmp
= tcg_temp_new_i32();
7663 tcg_gen_movi_i32(tmp
, val
);
7665 tmp
= tcg_temp_new_i32();
7666 tmp2
= tcg_const_i32(i
);
7667 gen_helper_get_user_reg(tmp
, tmp2
);
7668 tcg_temp_free_i32(tmp2
);
7670 tmp
= load_reg(s
, i
);
7672 gen_st32(tmp
, addr
, IS_USER(s
));
7675 /* no need to add after the last transfer */
7677 tcg_gen_addi_i32(addr
, addr
, 4);
7680 if (insn
& (1 << 21)) {
7682 if (insn
& (1 << 23)) {
7683 if (insn
& (1 << 24)) {
7686 /* post increment */
7687 tcg_gen_addi_i32(addr
, addr
, 4);
7690 if (insn
& (1 << 24)) {
7693 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
7695 /* post decrement */
7696 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
7699 store_reg(s
, rn
, addr
);
7701 tcg_temp_free_i32(addr
);
7704 store_reg(s
, rn
, loaded_var
);
7706 if ((insn
& (1 << 22)) && !user
) {
7707 /* Restore CPSR from SPSR. */
7708 tmp
= load_cpu_field(spsr
);
7709 gen_set_cpsr(tmp
, 0xffffffff);
7710 tcg_temp_free_i32(tmp
);
7711 s
->is_jmp
= DISAS_UPDATE
;
7720 /* branch (and link) */
7721 val
= (int32_t)s
->pc
;
7722 if (insn
& (1 << 24)) {
7723 tmp
= tcg_temp_new_i32();
7724 tcg_gen_movi_i32(tmp
, val
);
7725 store_reg(s
, 14, tmp
);
7727 offset
= (((int32_t)insn
<< 8) >> 8);
7728 val
+= (offset
<< 2) + 4;
7736 if (disas_coproc_insn(env
, s
, insn
))
7741 gen_set_pc_im(s
->pc
);
7742 s
->is_jmp
= DISAS_SWI
;
7746 gen_exception_insn(s
, 4, EXCP_UDEF
);
7752 /* Return true if this is a Thumb-2 logical op. */
7754 thumb2_logic_op(int op
)
7759 /* Generate code for a Thumb-2 data processing operation. If CONDS is nonzero
7760 then set condition code flags based on the result of the operation.
7761 If SHIFTER_OUT is nonzero then set the carry flag for logical operations
7762 to the high bit of T1.
7763 Returns zero if the opcode is valid. */
7766 gen_thumb2_data_op(DisasContext
*s
, int op
, int conds
, uint32_t shifter_out
, TCGv t0
, TCGv t1
)
7773 tcg_gen_and_i32(t0
, t0
, t1
);
7777 tcg_gen_andc_i32(t0
, t0
, t1
);
7781 tcg_gen_or_i32(t0
, t0
, t1
);
7785 tcg_gen_orc_i32(t0
, t0
, t1
);
7789 tcg_gen_xor_i32(t0
, t0
, t1
);
7794 gen_helper_add_cc(t0
, t0
, t1
);
7796 tcg_gen_add_i32(t0
, t0
, t1
);
7800 gen_helper_adc_cc(t0
, t0
, t1
);
7806 gen_helper_sbc_cc(t0
, t0
, t1
);
7808 gen_sub_carry(t0
, t0
, t1
);
7812 gen_helper_sub_cc(t0
, t0
, t1
);
7814 tcg_gen_sub_i32(t0
, t0
, t1
);
7818 gen_helper_sub_cc(t0
, t1
, t0
);
7820 tcg_gen_sub_i32(t0
, t1
, t0
);
7822 default: /* 5, 6, 7, 9, 12, 15. */
7828 gen_set_CF_bit31(t1
);
7833 /* Translate a 32-bit thumb instruction. Returns nonzero if the instruction
7835 static int disas_thumb2_insn(CPUState
*env
, DisasContext
*s
, uint16_t insn_hw1
)
7837 uint32_t insn
, imm
, shift
, offset
;
7838 uint32_t rd
, rn
, rm
, rs
;
7849 if (!(arm_feature(env
, ARM_FEATURE_THUMB2
)
7850 || arm_feature (env
, ARM_FEATURE_M
))) {
7851 /* Thumb-1 cores may need to treat bl and blx as a pair of
7852 16-bit instructions to get correct prefetch abort behavior. */
7854 if ((insn
& (1 << 12)) == 0) {
7856 /* Second half of blx. */
7857 offset
= ((insn
& 0x7ff) << 1);
7858 tmp
= load_reg(s
, 14);
7859 tcg_gen_addi_i32(tmp
, tmp
, offset
);
7860 tcg_gen_andi_i32(tmp
, tmp
, 0xfffffffc);
7862 tmp2
= tcg_temp_new_i32();
7863 tcg_gen_movi_i32(tmp2
, s
->pc
| 1);
7864 store_reg(s
, 14, tmp2
);
7868 if (insn
& (1 << 11)) {
7869 /* Second half of bl. */
7870 offset
= ((insn
& 0x7ff) << 1) | 1;
7871 tmp
= load_reg(s
, 14);
7872 tcg_gen_addi_i32(tmp
, tmp
, offset
);
7874 tmp2
= tcg_temp_new_i32();
7875 tcg_gen_movi_i32(tmp2
, s
->pc
| 1);
7876 store_reg(s
, 14, tmp2
);
7880 if ((s
->pc
& ~TARGET_PAGE_MASK
) == 0) {
7881 /* Instruction spans a page boundary. Implement it as two
7882 16-bit instructions in case the second half causes an
7884 offset
= ((int32_t)insn
<< 21) >> 9;
7885 tcg_gen_movi_i32(cpu_R
[14], s
->pc
+ 2 + offset
);
7888 /* Fall through to 32-bit decode. */
7891 insn
= lduw_code(s
->pc
);
7893 insn
|= (uint32_t)insn_hw1
<< 16;
7895 if ((insn
& 0xf800e800) != 0xf000e800) {
7899 rn
= (insn
>> 16) & 0xf;
7900 rs
= (insn
>> 12) & 0xf;
7901 rd
= (insn
>> 8) & 0xf;
7903 switch ((insn
>> 25) & 0xf) {
7904 case 0: case 1: case 2: case 3:
7905 /* 16-bit instructions. Should never happen. */
7908 if (insn
& (1 << 22)) {
7909 /* Other load/store, table branch. */
7910 if (insn
& 0x01200000) {
7911 /* Load/store doubleword. */
7913 addr
= tcg_temp_new_i32();
7914 tcg_gen_movi_i32(addr
, s
->pc
& ~3);
7916 addr
= load_reg(s
, rn
);
7918 offset
= (insn
& 0xff) * 4;
7919 if ((insn
& (1 << 23)) == 0)
7921 if (insn
& (1 << 24)) {
7922 tcg_gen_addi_i32(addr
, addr
, offset
);
7925 if (insn
& (1 << 20)) {
7927 tmp
= gen_ld32(addr
, IS_USER(s
));
7928 store_reg(s
, rs
, tmp
);
7929 tcg_gen_addi_i32(addr
, addr
, 4);
7930 tmp
= gen_ld32(addr
, IS_USER(s
));
7931 store_reg(s
, rd
, tmp
);
7934 tmp
= load_reg(s
, rs
);
7935 gen_st32(tmp
, addr
, IS_USER(s
));
7936 tcg_gen_addi_i32(addr
, addr
, 4);
7937 tmp
= load_reg(s
, rd
);
7938 gen_st32(tmp
, addr
, IS_USER(s
));
7940 if (insn
& (1 << 21)) {
7941 /* Base writeback. */
7944 tcg_gen_addi_i32(addr
, addr
, offset
- 4);
7945 store_reg(s
, rn
, addr
);
7947 tcg_temp_free_i32(addr
);
7949 } else if ((insn
& (1 << 23)) == 0) {
7950 /* Load/store exclusive word. */
7951 addr
= tcg_temp_local_new();
7952 load_reg_var(s
, addr
, rn
);
7953 tcg_gen_addi_i32(addr
, addr
, (insn
& 0xff) << 2);
7954 if (insn
& (1 << 20)) {
7955 gen_load_exclusive(s
, rs
, 15, addr
, 2);
7957 gen_store_exclusive(s
, rd
, rs
, 15, addr
, 2);
7959 tcg_temp_free(addr
);
7960 } else if ((insn
& (1 << 6)) == 0) {
7963 addr
= tcg_temp_new_i32();
7964 tcg_gen_movi_i32(addr
, s
->pc
);
7966 addr
= load_reg(s
, rn
);
7968 tmp
= load_reg(s
, rm
);
7969 tcg_gen_add_i32(addr
, addr
, tmp
);
7970 if (insn
& (1 << 4)) {
7972 tcg_gen_add_i32(addr
, addr
, tmp
);
7973 tcg_temp_free_i32(tmp
);
7974 tmp
= gen_ld16u(addr
, IS_USER(s
));
7976 tcg_temp_free_i32(tmp
);
7977 tmp
= gen_ld8u(addr
, IS_USER(s
));
7979 tcg_temp_free_i32(addr
);
7980 tcg_gen_shli_i32(tmp
, tmp
, 1);
7981 tcg_gen_addi_i32(tmp
, tmp
, s
->pc
);
7982 store_reg(s
, 15, tmp
);
7984 /* Load/store exclusive byte/halfword/doubleword. */
7986 op
= (insn
>> 4) & 0x3;
7990 addr
= tcg_temp_local_new();
7991 load_reg_var(s
, addr
, rn
);
7992 if (insn
& (1 << 20)) {
7993 gen_load_exclusive(s
, rs
, rd
, addr
, op
);
7995 gen_store_exclusive(s
, rm
, rs
, rd
, addr
, op
);
7997 tcg_temp_free(addr
);
8000 /* Load/store multiple, RFE, SRS. */
8001 if (((insn
>> 23) & 1) == ((insn
>> 24) & 1)) {
8002 /* Not available in user mode. */
8005 if (insn
& (1 << 20)) {
8007 addr
= load_reg(s
, rn
);
8008 if ((insn
& (1 << 24)) == 0)
8009 tcg_gen_addi_i32(addr
, addr
, -8);
8010 /* Load PC into tmp and CPSR into tmp2. */
8011 tmp
= gen_ld32(addr
, 0);
8012 tcg_gen_addi_i32(addr
, addr
, 4);
8013 tmp2
= gen_ld32(addr
, 0);
8014 if (insn
& (1 << 21)) {
8015 /* Base writeback. */
8016 if (insn
& (1 << 24)) {
8017 tcg_gen_addi_i32(addr
, addr
, 4);
8019 tcg_gen_addi_i32(addr
, addr
, -4);
8021 store_reg(s
, rn
, addr
);
8023 tcg_temp_free_i32(addr
);
8025 gen_rfe(s
, tmp
, tmp2
);
8029 addr
= tcg_temp_new_i32();
8030 tmp
= tcg_const_i32(op
);
8031 gen_helper_get_r13_banked(addr
, cpu_env
, tmp
);
8032 tcg_temp_free_i32(tmp
);
8033 if ((insn
& (1 << 24)) == 0) {
8034 tcg_gen_addi_i32(addr
, addr
, -8);
8036 tmp
= load_reg(s
, 14);
8037 gen_st32(tmp
, addr
, 0);
8038 tcg_gen_addi_i32(addr
, addr
, 4);
8039 tmp
= tcg_temp_new_i32();
8040 gen_helper_cpsr_read(tmp
);
8041 gen_st32(tmp
, addr
, 0);
8042 if (insn
& (1 << 21)) {
8043 if ((insn
& (1 << 24)) == 0) {
8044 tcg_gen_addi_i32(addr
, addr
, -4);
8046 tcg_gen_addi_i32(addr
, addr
, 4);
8048 tmp
= tcg_const_i32(op
);
8049 gen_helper_set_r13_banked(cpu_env
, tmp
, addr
);
8050 tcg_temp_free_i32(tmp
);
8052 tcg_temp_free_i32(addr
);
8056 int i
, loaded_base
= 0;
8058 /* Load/store multiple. */
8059 addr
= load_reg(s
, rn
);
8061 for (i
= 0; i
< 16; i
++) {
8062 if (insn
& (1 << i
))
8065 if (insn
& (1 << 24)) {
8066 tcg_gen_addi_i32(addr
, addr
, -offset
);
8069 TCGV_UNUSED(loaded_var
);
8070 for (i
= 0; i
< 16; i
++) {
8071 if ((insn
& (1 << i
)) == 0)
8073 if (insn
& (1 << 20)) {
8075 tmp
= gen_ld32(addr
, IS_USER(s
));
8078 } else if (i
== rn
) {
8082 store_reg(s
, i
, tmp
);
8086 tmp
= load_reg(s
, i
);
8087 gen_st32(tmp
, addr
, IS_USER(s
));
8089 tcg_gen_addi_i32(addr
, addr
, 4);
8092 store_reg(s
, rn
, loaded_var
);
8094 if (insn
& (1 << 21)) {
8095 /* Base register writeback. */
8096 if (insn
& (1 << 24)) {
8097 tcg_gen_addi_i32(addr
, addr
, -offset
);
8099 /* Fault if writeback register is in register list. */
8100 if (insn
& (1 << rn
))
8102 store_reg(s
, rn
, addr
);
8104 tcg_temp_free_i32(addr
);
8111 op
= (insn
>> 21) & 0xf;
8113 /* Halfword pack. */
8114 tmp
= load_reg(s
, rn
);
8115 tmp2
= load_reg(s
, rm
);
8116 shift
= ((insn
>> 10) & 0x1c) | ((insn
>> 6) & 0x3);
8117 if (insn
& (1 << 5)) {
8121 tcg_gen_sari_i32(tmp2
, tmp2
, shift
);
8122 tcg_gen_andi_i32(tmp
, tmp
, 0xffff0000);
8123 tcg_gen_ext16u_i32(tmp2
, tmp2
);
8127 tcg_gen_shli_i32(tmp2
, tmp2
, shift
);
8128 tcg_gen_ext16u_i32(tmp
, tmp
);
8129 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffff0000);
8131 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
8132 tcg_temp_free_i32(tmp2
);
8133 store_reg(s
, rd
, tmp
);
8135 /* Data processing register constant shift. */
8137 tmp
= tcg_temp_new_i32();
8138 tcg_gen_movi_i32(tmp
, 0);
8140 tmp
= load_reg(s
, rn
);
8142 tmp2
= load_reg(s
, rm
);
8144 shiftop
= (insn
>> 4) & 3;
8145 shift
= ((insn
>> 6) & 3) | ((insn
>> 10) & 0x1c);
8146 conds
= (insn
& (1 << 20)) != 0;
8147 logic_cc
= (conds
&& thumb2_logic_op(op
));
8148 gen_arm_shift_im(tmp2
, shiftop
, shift
, logic_cc
);
8149 if (gen_thumb2_data_op(s
, op
, conds
, 0, tmp
, tmp2
))
8151 tcg_temp_free_i32(tmp2
);
8153 store_reg(s
, rd
, tmp
);
8155 tcg_temp_free_i32(tmp
);
8159 case 13: /* Misc data processing. */
8160 op
= ((insn
>> 22) & 6) | ((insn
>> 7) & 1);
8161 if (op
< 4 && (insn
& 0xf000) != 0xf000)
8164 case 0: /* Register controlled shift. */
8165 tmp
= load_reg(s
, rn
);
8166 tmp2
= load_reg(s
, rm
);
8167 if ((insn
& 0x70) != 0)
8169 op
= (insn
>> 21) & 3;
8170 logic_cc
= (insn
& (1 << 20)) != 0;
8171 gen_arm_shift_reg(tmp
, op
, tmp2
, logic_cc
);
8174 store_reg_bx(env
, s
, rd
, tmp
);
8176 case 1: /* Sign/zero extend. */
8177 tmp
= load_reg(s
, rm
);
8178 shift
= (insn
>> 4) & 3;
8179 /* ??? In many cases it's not necessary to do a
8180 rotate, a shift is sufficient. */
8182 tcg_gen_rotri_i32(tmp
, tmp
, shift
* 8);
8183 op
= (insn
>> 20) & 7;
8185 case 0: gen_sxth(tmp
); break;
8186 case 1: gen_uxth(tmp
); break;
8187 case 2: gen_sxtb16(tmp
); break;
8188 case 3: gen_uxtb16(tmp
); break;
8189 case 4: gen_sxtb(tmp
); break;
8190 case 5: gen_uxtb(tmp
); break;
8191 default: goto illegal_op
;
8194 tmp2
= load_reg(s
, rn
);
8195 if ((op
>> 1) == 1) {
8196 gen_add16(tmp
, tmp2
);
8198 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8199 tcg_temp_free_i32(tmp2
);
8202 store_reg(s
, rd
, tmp
);
8204 case 2: /* SIMD add/subtract. */
8205 op
= (insn
>> 20) & 7;
8206 shift
= (insn
>> 4) & 7;
8207 if ((op
& 3) == 3 || (shift
& 3) == 3)
8209 tmp
= load_reg(s
, rn
);
8210 tmp2
= load_reg(s
, rm
);
8211 gen_thumb2_parallel_addsub(op
, shift
, tmp
, tmp2
);
8212 tcg_temp_free_i32(tmp2
);
8213 store_reg(s
, rd
, tmp
);
8215 case 3: /* Other data processing. */
8216 op
= ((insn
>> 17) & 0x38) | ((insn
>> 4) & 7);
8218 /* Saturating add/subtract. */
8219 tmp
= load_reg(s
, rn
);
8220 tmp2
= load_reg(s
, rm
);
8222 gen_helper_double_saturate(tmp
, tmp
);
8224 gen_helper_sub_saturate(tmp
, tmp2
, tmp
);
8226 gen_helper_add_saturate(tmp
, tmp
, tmp2
);
8227 tcg_temp_free_i32(tmp2
);
8229 tmp
= load_reg(s
, rn
);
8231 case 0x0a: /* rbit */
8232 gen_helper_rbit(tmp
, tmp
);
8234 case 0x08: /* rev */
8235 tcg_gen_bswap32_i32(tmp
, tmp
);
8237 case 0x09: /* rev16 */
8240 case 0x0b: /* revsh */
8243 case 0x10: /* sel */
8244 tmp2
= load_reg(s
, rm
);
8245 tmp3
= tcg_temp_new_i32();
8246 tcg_gen_ld_i32(tmp3
, cpu_env
, offsetof(CPUState
, GE
));
8247 gen_helper_sel_flags(tmp
, tmp3
, tmp
, tmp2
);
8248 tcg_temp_free_i32(tmp3
);
8249 tcg_temp_free_i32(tmp2
);
8251 case 0x18: /* clz */
8252 gen_helper_clz(tmp
, tmp
);
8258 store_reg(s
, rd
, tmp
);
8260 case 4: case 5: /* 32-bit multiply. Sum of absolute differences. */
8261 op
= (insn
>> 4) & 0xf;
8262 tmp
= load_reg(s
, rn
);
8263 tmp2
= load_reg(s
, rm
);
8264 switch ((insn
>> 20) & 7) {
8265 case 0: /* 32 x 32 -> 32 */
8266 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
8267 tcg_temp_free_i32(tmp2
);
8269 tmp2
= load_reg(s
, rs
);
8271 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
8273 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8274 tcg_temp_free_i32(tmp2
);
8277 case 1: /* 16 x 16 -> 32 */
8278 gen_mulxy(tmp
, tmp2
, op
& 2, op
& 1);
8279 tcg_temp_free_i32(tmp2
);
8281 tmp2
= load_reg(s
, rs
);
8282 gen_helper_add_setq(tmp
, tmp
, tmp2
);
8283 tcg_temp_free_i32(tmp2
);
8286 case 2: /* Dual multiply add. */
8287 case 4: /* Dual multiply subtract. */
8289 gen_swap_half(tmp2
);
8290 gen_smul_dual(tmp
, tmp2
);
8291 if (insn
& (1 << 22)) {
8292 /* This subtraction cannot overflow. */
8293 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
8295 /* This addition cannot overflow 32 bits;
8296 * however it may overflow considered as a signed
8297 * operation, in which case we must set the Q flag.
8299 gen_helper_add_setq(tmp
, tmp
, tmp2
);
8301 tcg_temp_free_i32(tmp2
);
8304 tmp2
= load_reg(s
, rs
);
8305 gen_helper_add_setq(tmp
, tmp
, tmp2
);
8306 tcg_temp_free_i32(tmp2
);
8309 case 3: /* 32 * 16 -> 32msb */
8311 tcg_gen_sari_i32(tmp2
, tmp2
, 16);
8314 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
8315 tcg_gen_shri_i64(tmp64
, tmp64
, 16);
8316 tmp
= tcg_temp_new_i32();
8317 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
8318 tcg_temp_free_i64(tmp64
);
8321 tmp2
= load_reg(s
, rs
);
8322 gen_helper_add_setq(tmp
, tmp
, tmp2
);
8323 tcg_temp_free_i32(tmp2
);
8326 case 5: case 6: /* 32 * 32 -> 32msb (SMMUL, SMMLA, SMMLS) */
8327 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
8329 tmp
= load_reg(s
, rs
);
8330 if (insn
& (1 << 20)) {
8331 tmp64
= gen_addq_msw(tmp64
, tmp
);
8333 tmp64
= gen_subq_msw(tmp64
, tmp
);
8336 if (insn
& (1 << 4)) {
8337 tcg_gen_addi_i64(tmp64
, tmp64
, 0x80000000u
);
8339 tcg_gen_shri_i64(tmp64
, tmp64
, 32);
8340 tmp
= tcg_temp_new_i32();
8341 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
8342 tcg_temp_free_i64(tmp64
);
8344 case 7: /* Unsigned sum of absolute differences. */
8345 gen_helper_usad8(tmp
, tmp
, tmp2
);
8346 tcg_temp_free_i32(tmp2
);
8348 tmp2
= load_reg(s
, rs
);
8349 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8350 tcg_temp_free_i32(tmp2
);
8354 store_reg(s
, rd
, tmp
);
8356 case 6: case 7: /* 64-bit multiply, Divide. */
8357 op
= ((insn
>> 4) & 0xf) | ((insn
>> 16) & 0x70);
8358 tmp
= load_reg(s
, rn
);
8359 tmp2
= load_reg(s
, rm
);
8360 if ((op
& 0x50) == 0x10) {
8362 if (!arm_feature(env
, ARM_FEATURE_DIV
))
8365 gen_helper_udiv(tmp
, tmp
, tmp2
);
8367 gen_helper_sdiv(tmp
, tmp
, tmp2
);
8368 tcg_temp_free_i32(tmp2
);
8369 store_reg(s
, rd
, tmp
);
8370 } else if ((op
& 0xe) == 0xc) {
8371 /* Dual multiply accumulate long. */
8373 gen_swap_half(tmp2
);
8374 gen_smul_dual(tmp
, tmp2
);
8376 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
8378 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8380 tcg_temp_free_i32(tmp2
);
8382 tmp64
= tcg_temp_new_i64();
8383 tcg_gen_ext_i32_i64(tmp64
, tmp
);
8384 tcg_temp_free_i32(tmp
);
8385 gen_addq(s
, tmp64
, rs
, rd
);
8386 gen_storeq_reg(s
, rs
, rd
, tmp64
);
8387 tcg_temp_free_i64(tmp64
);
8390 /* Unsigned 64-bit multiply */
8391 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
8395 gen_mulxy(tmp
, tmp2
, op
& 2, op
& 1);
8396 tcg_temp_free_i32(tmp2
);
8397 tmp64
= tcg_temp_new_i64();
8398 tcg_gen_ext_i32_i64(tmp64
, tmp
);
8399 tcg_temp_free_i32(tmp
);
8401 /* Signed 64-bit multiply */
8402 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
8407 gen_addq_lo(s
, tmp64
, rs
);
8408 gen_addq_lo(s
, tmp64
, rd
);
8409 } else if (op
& 0x40) {
8410 /* 64-bit accumulate. */
8411 gen_addq(s
, tmp64
, rs
, rd
);
8413 gen_storeq_reg(s
, rs
, rd
, tmp64
);
8414 tcg_temp_free_i64(tmp64
);
8419 case 6: case 7: case 14: case 15:
8421 if (((insn
>> 24) & 3) == 3) {
8422 /* Translate into the equivalent ARM encoding. */
8423 insn
= (insn
& 0xe2ffffff) | ((insn
& (1 << 28)) >> 4) | (1 << 28);
8424 if (disas_neon_data_insn(env
, s
, insn
))
8427 if (insn
& (1 << 28))
8429 if (disas_coproc_insn (env
, s
, insn
))
8433 case 8: case 9: case 10: case 11:
8434 if (insn
& (1 << 15)) {
8435 /* Branches, misc control. */
8436 if (insn
& 0x5000) {
8437 /* Unconditional branch. */
8438 /* signextend(hw1[10:0]) -> offset[:12]. */
8439 offset
= ((int32_t)insn
<< 5) >> 9 & ~(int32_t)0xfff;
8440 /* hw1[10:0] -> offset[11:1]. */
8441 offset
|= (insn
& 0x7ff) << 1;
8442 /* (~hw2[13, 11] ^ offset[24]) -> offset[23,22]
8443 offset[24:22] already have the same value because of the
8444 sign extension above. */
8445 offset
^= ((~insn
) & (1 << 13)) << 10;
8446 offset
^= ((~insn
) & (1 << 11)) << 11;
8448 if (insn
& (1 << 14)) {
8449 /* Branch and link. */
8450 tcg_gen_movi_i32(cpu_R
[14], s
->pc
| 1);
8454 if (insn
& (1 << 12)) {
8459 offset
&= ~(uint32_t)2;
8460 /* thumb2 bx, no need to check */
8461 gen_bx_im(s
, offset
);
8463 } else if (((insn
>> 23) & 7) == 7) {
8465 if (insn
& (1 << 13))
8468 if (insn
& (1 << 26)) {
8469 /* Secure monitor call (v6Z) */
8470 goto illegal_op
; /* not implemented. */
8472 op
= (insn
>> 20) & 7;
8474 case 0: /* msr cpsr. */
8476 tmp
= load_reg(s
, rn
);
8477 addr
= tcg_const_i32(insn
& 0xff);
8478 gen_helper_v7m_msr(cpu_env
, addr
, tmp
);
8479 tcg_temp_free_i32(addr
);
8480 tcg_temp_free_i32(tmp
);
8485 case 1: /* msr spsr. */
8488 tmp
= load_reg(s
, rn
);
8490 msr_mask(env
, s
, (insn
>> 8) & 0xf, op
== 1),
8494 case 2: /* cps, nop-hint. */
8495 if (((insn
>> 8) & 7) == 0) {
8496 gen_nop_hint(s
, insn
& 0xff);
8498 /* Implemented as NOP in user mode. */
8503 if (insn
& (1 << 10)) {
8504 if (insn
& (1 << 7))
8506 if (insn
& (1 << 6))
8508 if (insn
& (1 << 5))
8510 if (insn
& (1 << 9))
8511 imm
= CPSR_A
| CPSR_I
| CPSR_F
;
8513 if (insn
& (1 << 8)) {
8515 imm
|= (insn
& 0x1f);
8518 gen_set_psr_im(s
, offset
, 0, imm
);
8521 case 3: /* Special control operations. */
8523 op
= (insn
>> 4) & 0xf;
8531 /* These execute as NOPs. */
8538 /* Trivial implementation equivalent to bx. */
8539 tmp
= load_reg(s
, rn
);
8542 case 5: /* Exception return. */
8546 if (rn
!= 14 || rd
!= 15) {
8549 tmp
= load_reg(s
, rn
);
8550 tcg_gen_subi_i32(tmp
, tmp
, insn
& 0xff);
8551 gen_exception_return(s
, tmp
);
8553 case 6: /* mrs cpsr. */
8554 tmp
= tcg_temp_new_i32();
8556 addr
= tcg_const_i32(insn
& 0xff);
8557 gen_helper_v7m_mrs(tmp
, cpu_env
, addr
);
8558 tcg_temp_free_i32(addr
);
8560 gen_helper_cpsr_read(tmp
);
8562 store_reg(s
, rd
, tmp
);
8564 case 7: /* mrs spsr. */
8565 /* Not accessible in user mode. */
8566 if (IS_USER(s
) || IS_M(env
))
8568 tmp
= load_cpu_field(spsr
);
8569 store_reg(s
, rd
, tmp
);
8574 /* Conditional branch. */
8575 op
= (insn
>> 22) & 0xf;
8576 /* Generate a conditional jump to next instruction. */
8577 s
->condlabel
= gen_new_label();
8578 gen_test_cc(op
^ 1, s
->condlabel
);
8581 /* offset[11:1] = insn[10:0] */
8582 offset
= (insn
& 0x7ff) << 1;
8583 /* offset[17:12] = insn[21:16]. */
8584 offset
|= (insn
& 0x003f0000) >> 4;
8585 /* offset[31:20] = insn[26]. */
8586 offset
|= ((int32_t)((insn
<< 5) & 0x80000000)) >> 11;
8587 /* offset[18] = insn[13]. */
8588 offset
|= (insn
& (1 << 13)) << 5;
8589 /* offset[19] = insn[11]. */
8590 offset
|= (insn
& (1 << 11)) << 8;
8592 /* jump to the offset */
8593 gen_jmp(s
, s
->pc
+ offset
);
8596 /* Data processing immediate. */
8597 if (insn
& (1 << 25)) {
8598 if (insn
& (1 << 24)) {
8599 if (insn
& (1 << 20))
8601 /* Bitfield/Saturate. */
8602 op
= (insn
>> 21) & 7;
8604 shift
= ((insn
>> 6) & 3) | ((insn
>> 10) & 0x1c);
8606 tmp
= tcg_temp_new_i32();
8607 tcg_gen_movi_i32(tmp
, 0);
8609 tmp
= load_reg(s
, rn
);
8612 case 2: /* Signed bitfield extract. */
8614 if (shift
+ imm
> 32)
8617 gen_sbfx(tmp
, shift
, imm
);
8619 case 6: /* Unsigned bitfield extract. */
8621 if (shift
+ imm
> 32)
8624 gen_ubfx(tmp
, shift
, (1u << imm
) - 1);
8626 case 3: /* Bitfield insert/clear. */
8629 imm
= imm
+ 1 - shift
;
8631 tmp2
= load_reg(s
, rd
);
8632 gen_bfi(tmp
, tmp2
, tmp
, shift
, (1u << imm
) - 1);
8633 tcg_temp_free_i32(tmp2
);
8638 default: /* Saturate. */
8641 tcg_gen_sari_i32(tmp
, tmp
, shift
);
8643 tcg_gen_shli_i32(tmp
, tmp
, shift
);
8645 tmp2
= tcg_const_i32(imm
);
8648 if ((op
& 1) && shift
== 0)
8649 gen_helper_usat16(tmp
, tmp
, tmp2
);
8651 gen_helper_usat(tmp
, tmp
, tmp2
);
8654 if ((op
& 1) && shift
== 0)
8655 gen_helper_ssat16(tmp
, tmp
, tmp2
);
8657 gen_helper_ssat(tmp
, tmp
, tmp2
);
8659 tcg_temp_free_i32(tmp2
);
8662 store_reg(s
, rd
, tmp
);
8664 imm
= ((insn
& 0x04000000) >> 15)
8665 | ((insn
& 0x7000) >> 4) | (insn
& 0xff);
8666 if (insn
& (1 << 22)) {
8667 /* 16-bit immediate. */
8668 imm
|= (insn
>> 4) & 0xf000;
8669 if (insn
& (1 << 23)) {
8671 tmp
= load_reg(s
, rd
);
8672 tcg_gen_ext16u_i32(tmp
, tmp
);
8673 tcg_gen_ori_i32(tmp
, tmp
, imm
<< 16);
8676 tmp
= tcg_temp_new_i32();
8677 tcg_gen_movi_i32(tmp
, imm
);
8680 /* Add/sub 12-bit immediate. */
8682 offset
= s
->pc
& ~(uint32_t)3;
8683 if (insn
& (1 << 23))
8687 tmp
= tcg_temp_new_i32();
8688 tcg_gen_movi_i32(tmp
, offset
);
8690 tmp
= load_reg(s
, rn
);
8691 if (insn
& (1 << 23))
8692 tcg_gen_subi_i32(tmp
, tmp
, imm
);
8694 tcg_gen_addi_i32(tmp
, tmp
, imm
);
8697 store_reg(s
, rd
, tmp
);
8700 int shifter_out
= 0;
8701 /* modified 12-bit immediate. */
8702 shift
= ((insn
& 0x04000000) >> 23) | ((insn
& 0x7000) >> 12);
8703 imm
= (insn
& 0xff);
8706 /* Nothing to do. */
8708 case 1: /* 00XY00XY */
8711 case 2: /* XY00XY00 */
8715 case 3: /* XYXYXYXY */
8719 default: /* Rotated constant. */
8720 shift
= (shift
<< 1) | (imm
>> 7);
8722 imm
= imm
<< (32 - shift
);
8726 tmp2
= tcg_temp_new_i32();
8727 tcg_gen_movi_i32(tmp2
, imm
);
8728 rn
= (insn
>> 16) & 0xf;
8730 tmp
= tcg_temp_new_i32();
8731 tcg_gen_movi_i32(tmp
, 0);
8733 tmp
= load_reg(s
, rn
);
8735 op
= (insn
>> 21) & 0xf;
8736 if (gen_thumb2_data_op(s
, op
, (insn
& (1 << 20)) != 0,
8737 shifter_out
, tmp
, tmp2
))
8739 tcg_temp_free_i32(tmp2
);
8740 rd
= (insn
>> 8) & 0xf;
8742 store_reg(s
, rd
, tmp
);
8744 tcg_temp_free_i32(tmp
);
8749 case 12: /* Load/store single data item. */
8754 if ((insn
& 0x01100000) == 0x01000000) {
8755 if (disas_neon_ls_insn(env
, s
, insn
))
8759 op
= ((insn
>> 21) & 3) | ((insn
>> 22) & 4);
8761 if (!(insn
& (1 << 20))) {
8765 /* Byte or halfword load space with dest == r15 : memory hints.
8766 * Catch them early so we don't emit pointless addressing code.
8767 * This space is a mix of:
8768 * PLD/PLDW/PLI, which we implement as NOPs (note that unlike
8769 * the ARM encodings, PLDW space doesn't UNDEF for non-v7MP
8771 * unallocated hints, which must be treated as NOPs
8772 * UNPREDICTABLE space, which we NOP or UNDEF depending on
8773 * which is easiest for the decoding logic
8774 * Some space which must UNDEF
8776 int op1
= (insn
>> 23) & 3;
8777 int op2
= (insn
>> 6) & 0x3f;
8782 /* UNPREDICTABLE or unallocated hint */
8786 return 0; /* PLD* or unallocated hint */
8788 if ((op2
== 0) || ((op2
& 0x3c) == 0x30)) {
8789 return 0; /* PLD* or unallocated hint */
8791 /* UNDEF space, or an UNPREDICTABLE */
8797 addr
= tcg_temp_new_i32();
8799 /* s->pc has already been incremented by 4. */
8800 imm
= s
->pc
& 0xfffffffc;
8801 if (insn
& (1 << 23))
8802 imm
+= insn
& 0xfff;
8804 imm
-= insn
& 0xfff;
8805 tcg_gen_movi_i32(addr
, imm
);
8807 addr
= load_reg(s
, rn
);
8808 if (insn
& (1 << 23)) {
8809 /* Positive offset. */
8811 tcg_gen_addi_i32(addr
, addr
, imm
);
8814 switch ((insn
>> 8) & 0xf) {
8815 case 0x0: /* Shifted Register. */
8816 shift
= (insn
>> 4) & 0xf;
8818 tcg_temp_free_i32(addr
);
8821 tmp
= load_reg(s
, rm
);
8823 tcg_gen_shli_i32(tmp
, tmp
, shift
);
8824 tcg_gen_add_i32(addr
, addr
, tmp
);
8825 tcg_temp_free_i32(tmp
);
8827 case 0xc: /* Negative offset. */
8828 tcg_gen_addi_i32(addr
, addr
, -imm
);
8830 case 0xe: /* User privilege. */
8831 tcg_gen_addi_i32(addr
, addr
, imm
);
8834 case 0x9: /* Post-decrement. */
8837 case 0xb: /* Post-increment. */
8841 case 0xd: /* Pre-decrement. */
8844 case 0xf: /* Pre-increment. */
8845 tcg_gen_addi_i32(addr
, addr
, imm
);
8849 tcg_temp_free_i32(addr
);
8854 if (insn
& (1 << 20)) {
8857 case 0: tmp
= gen_ld8u(addr
, user
); break;
8858 case 4: tmp
= gen_ld8s(addr
, user
); break;
8859 case 1: tmp
= gen_ld16u(addr
, user
); break;
8860 case 5: tmp
= gen_ld16s(addr
, user
); break;
8861 case 2: tmp
= gen_ld32(addr
, user
); break;
8863 tcg_temp_free_i32(addr
);
8869 store_reg(s
, rs
, tmp
);
8873 tmp
= load_reg(s
, rs
);
8875 case 0: gen_st8(tmp
, addr
, user
); break;
8876 case 1: gen_st16(tmp
, addr
, user
); break;
8877 case 2: gen_st32(tmp
, addr
, user
); break;
8879 tcg_temp_free_i32(addr
);
8884 tcg_gen_addi_i32(addr
, addr
, imm
);
8886 store_reg(s
, rn
, addr
);
8888 tcg_temp_free_i32(addr
);
8900 static void disas_thumb_insn(CPUState
*env
, DisasContext
*s
)
8902 uint32_t val
, insn
, op
, rm
, rn
, rd
, shift
, cond
;
8909 if (s
->condexec_mask
) {
8910 cond
= s
->condexec_cond
;
8911 if (cond
!= 0x0e) { /* Skip conditional when condition is AL. */
8912 s
->condlabel
= gen_new_label();
8913 gen_test_cc(cond
^ 1, s
->condlabel
);
8918 insn
= lduw_code(s
->pc
);
8921 switch (insn
>> 12) {
8925 op
= (insn
>> 11) & 3;
8928 rn
= (insn
>> 3) & 7;
8929 tmp
= load_reg(s
, rn
);
8930 if (insn
& (1 << 10)) {
8932 tmp2
= tcg_temp_new_i32();
8933 tcg_gen_movi_i32(tmp2
, (insn
>> 6) & 7);
8936 rm
= (insn
>> 6) & 7;
8937 tmp2
= load_reg(s
, rm
);
8939 if (insn
& (1 << 9)) {
8940 if (s
->condexec_mask
)
8941 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
8943 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8945 if (s
->condexec_mask
)
8946 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8948 gen_helper_add_cc(tmp
, tmp
, tmp2
);
8950 tcg_temp_free_i32(tmp2
);
8951 store_reg(s
, rd
, tmp
);
8953 /* shift immediate */
8954 rm
= (insn
>> 3) & 7;
8955 shift
= (insn
>> 6) & 0x1f;
8956 tmp
= load_reg(s
, rm
);
8957 gen_arm_shift_im(tmp
, op
, shift
, s
->condexec_mask
== 0);
8958 if (!s
->condexec_mask
)
8960 store_reg(s
, rd
, tmp
);
8964 /* arithmetic large immediate */
8965 op
= (insn
>> 11) & 3;
8966 rd
= (insn
>> 8) & 0x7;
8967 if (op
== 0) { /* mov */
8968 tmp
= tcg_temp_new_i32();
8969 tcg_gen_movi_i32(tmp
, insn
& 0xff);
8970 if (!s
->condexec_mask
)
8972 store_reg(s
, rd
, tmp
);
8974 tmp
= load_reg(s
, rd
);
8975 tmp2
= tcg_temp_new_i32();
8976 tcg_gen_movi_i32(tmp2
, insn
& 0xff);
8979 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8980 tcg_temp_free_i32(tmp
);
8981 tcg_temp_free_i32(tmp2
);
8984 if (s
->condexec_mask
)
8985 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8987 gen_helper_add_cc(tmp
, tmp
, tmp2
);
8988 tcg_temp_free_i32(tmp2
);
8989 store_reg(s
, rd
, tmp
);
8992 if (s
->condexec_mask
)
8993 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
8995 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8996 tcg_temp_free_i32(tmp2
);
8997 store_reg(s
, rd
, tmp
);
9003 if (insn
& (1 << 11)) {
9004 rd
= (insn
>> 8) & 7;
9005 /* load pc-relative. Bit 1 of PC is ignored. */
9006 val
= s
->pc
+ 2 + ((insn
& 0xff) * 4);
9007 val
&= ~(uint32_t)2;
9008 addr
= tcg_temp_new_i32();
9009 tcg_gen_movi_i32(addr
, val
);
9010 tmp
= gen_ld32(addr
, IS_USER(s
));
9011 tcg_temp_free_i32(addr
);
9012 store_reg(s
, rd
, tmp
);
9015 if (insn
& (1 << 10)) {
9016 /* data processing extended or blx */
9017 rd
= (insn
& 7) | ((insn
>> 4) & 8);
9018 rm
= (insn
>> 3) & 0xf;
9019 op
= (insn
>> 8) & 3;
9022 tmp
= load_reg(s
, rd
);
9023 tmp2
= load_reg(s
, rm
);
9024 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
9025 tcg_temp_free_i32(tmp2
);
9026 store_reg(s
, rd
, tmp
);
9029 tmp
= load_reg(s
, rd
);
9030 tmp2
= load_reg(s
, rm
);
9031 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
9032 tcg_temp_free_i32(tmp2
);
9033 tcg_temp_free_i32(tmp
);
9035 case 2: /* mov/cpy */
9036 tmp
= load_reg(s
, rm
);
9037 store_reg(s
, rd
, tmp
);
9039 case 3:/* branch [and link] exchange thumb register */
9040 tmp
= load_reg(s
, rm
);
9041 if (insn
& (1 << 7)) {
9043 val
= (uint32_t)s
->pc
| 1;
9044 tmp2
= tcg_temp_new_i32();
9045 tcg_gen_movi_i32(tmp2
, val
);
9046 store_reg(s
, 14, tmp2
);
9048 /* already thumb, no need to check */
9055 /* data processing register */
9057 rm
= (insn
>> 3) & 7;
9058 op
= (insn
>> 6) & 0xf;
9059 if (op
== 2 || op
== 3 || op
== 4 || op
== 7) {
9060 /* the shift/rotate ops want the operands backwards */
9069 if (op
== 9) { /* neg */
9070 tmp
= tcg_temp_new_i32();
9071 tcg_gen_movi_i32(tmp
, 0);
9072 } else if (op
!= 0xf) { /* mvn doesn't read its first operand */
9073 tmp
= load_reg(s
, rd
);
9078 tmp2
= load_reg(s
, rm
);
9081 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
9082 if (!s
->condexec_mask
)
9086 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
9087 if (!s
->condexec_mask
)
9091 if (s
->condexec_mask
) {
9092 gen_helper_shl(tmp2
, tmp2
, tmp
);
9094 gen_helper_shl_cc(tmp2
, tmp2
, tmp
);
9099 if (s
->condexec_mask
) {
9100 gen_helper_shr(tmp2
, tmp2
, tmp
);
9102 gen_helper_shr_cc(tmp2
, tmp2
, tmp
);
9107 if (s
->condexec_mask
) {
9108 gen_helper_sar(tmp2
, tmp2
, tmp
);
9110 gen_helper_sar_cc(tmp2
, tmp2
, tmp
);
9115 if (s
->condexec_mask
)
9118 gen_helper_adc_cc(tmp
, tmp
, tmp2
);
9121 if (s
->condexec_mask
)
9122 gen_sub_carry(tmp
, tmp
, tmp2
);
9124 gen_helper_sbc_cc(tmp
, tmp
, tmp2
);
9127 if (s
->condexec_mask
) {
9128 tcg_gen_andi_i32(tmp
, tmp
, 0x1f);
9129 tcg_gen_rotr_i32(tmp2
, tmp2
, tmp
);
9131 gen_helper_ror_cc(tmp2
, tmp2
, tmp
);
9136 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
9141 if (s
->condexec_mask
)
9142 tcg_gen_neg_i32(tmp
, tmp2
);
9144 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
9147 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
9151 gen_helper_add_cc(tmp
, tmp
, tmp2
);
9155 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
9156 if (!s
->condexec_mask
)
9160 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
9161 if (!s
->condexec_mask
)
9165 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
9166 if (!s
->condexec_mask
)
9170 tcg_gen_not_i32(tmp2
, tmp2
);
9171 if (!s
->condexec_mask
)
9179 store_reg(s
, rm
, tmp2
);
9181 tcg_temp_free_i32(tmp
);
9183 store_reg(s
, rd
, tmp
);
9184 tcg_temp_free_i32(tmp2
);
9187 tcg_temp_free_i32(tmp
);
9188 tcg_temp_free_i32(tmp2
);
9193 /* load/store register offset. */
9195 rn
= (insn
>> 3) & 7;
9196 rm
= (insn
>> 6) & 7;
9197 op
= (insn
>> 9) & 7;
9198 addr
= load_reg(s
, rn
);
9199 tmp
= load_reg(s
, rm
);
9200 tcg_gen_add_i32(addr
, addr
, tmp
);
9201 tcg_temp_free_i32(tmp
);
9203 if (op
< 3) /* store */
9204 tmp
= load_reg(s
, rd
);
9208 gen_st32(tmp
, addr
, IS_USER(s
));
9211 gen_st16(tmp
, addr
, IS_USER(s
));
9214 gen_st8(tmp
, addr
, IS_USER(s
));
9217 tmp
= gen_ld8s(addr
, IS_USER(s
));
9220 tmp
= gen_ld32(addr
, IS_USER(s
));
9223 tmp
= gen_ld16u(addr
, IS_USER(s
));
9226 tmp
= gen_ld8u(addr
, IS_USER(s
));
9229 tmp
= gen_ld16s(addr
, IS_USER(s
));
9232 if (op
>= 3) /* load */
9233 store_reg(s
, rd
, tmp
);
9234 tcg_temp_free_i32(addr
);
9238 /* load/store word immediate offset */
9240 rn
= (insn
>> 3) & 7;
9241 addr
= load_reg(s
, rn
);
9242 val
= (insn
>> 4) & 0x7c;
9243 tcg_gen_addi_i32(addr
, addr
, val
);
9245 if (insn
& (1 << 11)) {
9247 tmp
= gen_ld32(addr
, IS_USER(s
));
9248 store_reg(s
, rd
, tmp
);
9251 tmp
= load_reg(s
, rd
);
9252 gen_st32(tmp
, addr
, IS_USER(s
));
9254 tcg_temp_free_i32(addr
);
9258 /* load/store byte immediate offset */
9260 rn
= (insn
>> 3) & 7;
9261 addr
= load_reg(s
, rn
);
9262 val
= (insn
>> 6) & 0x1f;
9263 tcg_gen_addi_i32(addr
, addr
, val
);
9265 if (insn
& (1 << 11)) {
9267 tmp
= gen_ld8u(addr
, IS_USER(s
));
9268 store_reg(s
, rd
, tmp
);
9271 tmp
= load_reg(s
, rd
);
9272 gen_st8(tmp
, addr
, IS_USER(s
));
9274 tcg_temp_free_i32(addr
);
9278 /* load/store halfword immediate offset */
9280 rn
= (insn
>> 3) & 7;
9281 addr
= load_reg(s
, rn
);
9282 val
= (insn
>> 5) & 0x3e;
9283 tcg_gen_addi_i32(addr
, addr
, val
);
9285 if (insn
& (1 << 11)) {
9287 tmp
= gen_ld16u(addr
, IS_USER(s
));
9288 store_reg(s
, rd
, tmp
);
9291 tmp
= load_reg(s
, rd
);
9292 gen_st16(tmp
, addr
, IS_USER(s
));
9294 tcg_temp_free_i32(addr
);
9298 /* load/store from stack */
9299 rd
= (insn
>> 8) & 7;
9300 addr
= load_reg(s
, 13);
9301 val
= (insn
& 0xff) * 4;
9302 tcg_gen_addi_i32(addr
, addr
, val
);
9304 if (insn
& (1 << 11)) {
9306 tmp
= gen_ld32(addr
, IS_USER(s
));
9307 store_reg(s
, rd
, tmp
);
9310 tmp
= load_reg(s
, rd
);
9311 gen_st32(tmp
, addr
, IS_USER(s
));
9313 tcg_temp_free_i32(addr
);
9317 /* add to high reg */
9318 rd
= (insn
>> 8) & 7;
9319 if (insn
& (1 << 11)) {
9321 tmp
= load_reg(s
, 13);
9323 /* PC. bit 1 is ignored. */
9324 tmp
= tcg_temp_new_i32();
9325 tcg_gen_movi_i32(tmp
, (s
->pc
+ 2) & ~(uint32_t)2);
9327 val
= (insn
& 0xff) * 4;
9328 tcg_gen_addi_i32(tmp
, tmp
, val
);
9329 store_reg(s
, rd
, tmp
);
9334 op
= (insn
>> 8) & 0xf;
9337 /* adjust stack pointer */
9338 tmp
= load_reg(s
, 13);
9339 val
= (insn
& 0x7f) * 4;
9340 if (insn
& (1 << 7))
9341 val
= -(int32_t)val
;
9342 tcg_gen_addi_i32(tmp
, tmp
, val
);
9343 store_reg(s
, 13, tmp
);
9346 case 2: /* sign/zero extend. */
9349 rm
= (insn
>> 3) & 7;
9350 tmp
= load_reg(s
, rm
);
9351 switch ((insn
>> 6) & 3) {
9352 case 0: gen_sxth(tmp
); break;
9353 case 1: gen_sxtb(tmp
); break;
9354 case 2: gen_uxth(tmp
); break;
9355 case 3: gen_uxtb(tmp
); break;
9357 store_reg(s
, rd
, tmp
);
9359 case 4: case 5: case 0xc: case 0xd:
9361 addr
= load_reg(s
, 13);
9362 if (insn
& (1 << 8))
9366 for (i
= 0; i
< 8; i
++) {
9367 if (insn
& (1 << i
))
9370 if ((insn
& (1 << 11)) == 0) {
9371 tcg_gen_addi_i32(addr
, addr
, -offset
);
9373 for (i
= 0; i
< 8; i
++) {
9374 if (insn
& (1 << i
)) {
9375 if (insn
& (1 << 11)) {
9377 tmp
= gen_ld32(addr
, IS_USER(s
));
9378 store_reg(s
, i
, tmp
);
9381 tmp
= load_reg(s
, i
);
9382 gen_st32(tmp
, addr
, IS_USER(s
));
9384 /* advance to the next address. */
9385 tcg_gen_addi_i32(addr
, addr
, 4);
9389 if (insn
& (1 << 8)) {
9390 if (insn
& (1 << 11)) {
9392 tmp
= gen_ld32(addr
, IS_USER(s
));
9393 /* don't set the pc until the rest of the instruction
9397 tmp
= load_reg(s
, 14);
9398 gen_st32(tmp
, addr
, IS_USER(s
));
9400 tcg_gen_addi_i32(addr
, addr
, 4);
9402 if ((insn
& (1 << 11)) == 0) {
9403 tcg_gen_addi_i32(addr
, addr
, -offset
);
9405 /* write back the new stack pointer */
9406 store_reg(s
, 13, addr
);
9407 /* set the new PC value */
9408 if ((insn
& 0x0900) == 0x0900) {
9409 store_reg_from_load(env
, s
, 15, tmp
);
9413 case 1: case 3: case 9: case 11: /* czb */
9415 tmp
= load_reg(s
, rm
);
9416 s
->condlabel
= gen_new_label();
9418 if (insn
& (1 << 11))
9419 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, s
->condlabel
);
9421 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, s
->condlabel
);
9422 tcg_temp_free_i32(tmp
);
9423 offset
= ((insn
& 0xf8) >> 2) | (insn
& 0x200) >> 3;
9424 val
= (uint32_t)s
->pc
+ 2;
9429 case 15: /* IT, nop-hint. */
9430 if ((insn
& 0xf) == 0) {
9431 gen_nop_hint(s
, (insn
>> 4) & 0xf);
9435 s
->condexec_cond
= (insn
>> 4) & 0xe;
9436 s
->condexec_mask
= insn
& 0x1f;
9437 /* No actual code generated for this insn, just setup state. */
9440 case 0xe: /* bkpt */
9442 gen_exception_insn(s
, 2, EXCP_BKPT
);
9447 rn
= (insn
>> 3) & 0x7;
9449 tmp
= load_reg(s
, rn
);
9450 switch ((insn
>> 6) & 3) {
9451 case 0: tcg_gen_bswap32_i32(tmp
, tmp
); break;
9452 case 1: gen_rev16(tmp
); break;
9453 case 3: gen_revsh(tmp
); break;
9454 default: goto illegal_op
;
9456 store_reg(s
, rd
, tmp
);
9464 tmp
= tcg_const_i32((insn
& (1 << 4)) != 0);
9467 addr
= tcg_const_i32(16);
9468 gen_helper_v7m_msr(cpu_env
, addr
, tmp
);
9469 tcg_temp_free_i32(addr
);
9473 addr
= tcg_const_i32(17);
9474 gen_helper_v7m_msr(cpu_env
, addr
, tmp
);
9475 tcg_temp_free_i32(addr
);
9477 tcg_temp_free_i32(tmp
);
9480 if (insn
& (1 << 4))
9481 shift
= CPSR_A
| CPSR_I
| CPSR_F
;
9484 gen_set_psr_im(s
, ((insn
& 7) << 6), 0, shift
);
9495 /* load/store multiple */
9497 TCGV_UNUSED(loaded_var
);
9498 rn
= (insn
>> 8) & 0x7;
9499 addr
= load_reg(s
, rn
);
9500 for (i
= 0; i
< 8; i
++) {
9501 if (insn
& (1 << i
)) {
9502 if (insn
& (1 << 11)) {
9504 tmp
= gen_ld32(addr
, IS_USER(s
));
9508 store_reg(s
, i
, tmp
);
9512 tmp
= load_reg(s
, i
);
9513 gen_st32(tmp
, addr
, IS_USER(s
));
9515 /* advance to the next address */
9516 tcg_gen_addi_i32(addr
, addr
, 4);
9519 if ((insn
& (1 << rn
)) == 0) {
9520 /* base reg not in list: base register writeback */
9521 store_reg(s
, rn
, addr
);
9523 /* base reg in list: if load, complete it now */
9524 if (insn
& (1 << 11)) {
9525 store_reg(s
, rn
, loaded_var
);
9527 tcg_temp_free_i32(addr
);
9532 /* conditional branch or swi */
9533 cond
= (insn
>> 8) & 0xf;
9539 gen_set_pc_im(s
->pc
);
9540 s
->is_jmp
= DISAS_SWI
;
9543 /* generate a conditional jump to next instruction */
9544 s
->condlabel
= gen_new_label();
9545 gen_test_cc(cond
^ 1, s
->condlabel
);
9548 /* jump to the offset */
9549 val
= (uint32_t)s
->pc
+ 2;
9550 offset
= ((int32_t)insn
<< 24) >> 24;
9556 if (insn
& (1 << 11)) {
9557 if (disas_thumb2_insn(env
, s
, insn
))
9561 /* unconditional branch */
9562 val
= (uint32_t)s
->pc
;
9563 offset
= ((int32_t)insn
<< 21) >> 21;
9564 val
+= (offset
<< 1) + 2;
9569 if (disas_thumb2_insn(env
, s
, insn
))
9575 gen_exception_insn(s
, 4, EXCP_UDEF
);
9579 gen_exception_insn(s
, 2, EXCP_UDEF
);
9582 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
9583 basic block 'tb'. If search_pc is TRUE, also generate PC
9584 information for each intermediate instruction. */
9585 static inline void gen_intermediate_code_internal(CPUState
*env
,
9586 TranslationBlock
*tb
,
9589 DisasContext dc1
, *dc
= &dc1
;
9591 uint16_t *gen_opc_end
;
9593 target_ulong pc_start
;
9594 uint32_t next_page_start
;
9598 /* generate intermediate code */
9603 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9605 dc
->is_jmp
= DISAS_NEXT
;
9607 dc
->singlestep_enabled
= env
->singlestep_enabled
;
9609 dc
->thumb
= ARM_TBFLAG_THUMB(tb
->flags
);
9610 dc
->condexec_mask
= (ARM_TBFLAG_CONDEXEC(tb
->flags
) & 0xf) << 1;
9611 dc
->condexec_cond
= ARM_TBFLAG_CONDEXEC(tb
->flags
) >> 4;
9612 #if !defined(CONFIG_USER_ONLY)
9613 dc
->user
= (ARM_TBFLAG_PRIV(tb
->flags
) == 0);
9615 dc
->vfp_enabled
= ARM_TBFLAG_VFPEN(tb
->flags
);
9616 dc
->vec_len
= ARM_TBFLAG_VECLEN(tb
->flags
);
9617 dc
->vec_stride
= ARM_TBFLAG_VECSTRIDE(tb
->flags
);
9618 cpu_F0s
= tcg_temp_new_i32();
9619 cpu_F1s
= tcg_temp_new_i32();
9620 cpu_F0d
= tcg_temp_new_i64();
9621 cpu_F1d
= tcg_temp_new_i64();
9624 /* FIXME: cpu_M0 can probably be the same as cpu_V0. */
9625 cpu_M0
= tcg_temp_new_i64();
9626 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
9629 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9631 max_insns
= CF_COUNT_MASK
;
9635 tcg_clear_temp_count();
9637 /* A note on handling of the condexec (IT) bits:
9639 * We want to avoid the overhead of having to write the updated condexec
9640 * bits back to the CPUState for every instruction in an IT block. So:
9641 * (1) if the condexec bits are not already zero then we write
9642 * zero back into the CPUState now. This avoids complications trying
9643 * to do it at the end of the block. (For example if we don't do this
9644 * it's hard to identify whether we can safely skip writing condexec
9645 * at the end of the TB, which we definitely want to do for the case
9646 * where a TB doesn't do anything with the IT state at all.)
9647 * (2) if we are going to leave the TB then we call gen_set_condexec()
9648 * which will write the correct value into CPUState if zero is wrong.
9649 * This is done both for leaving the TB at the end, and for leaving
9650 * it because of an exception we know will happen, which is done in
9651 * gen_exception_insn(). The latter is necessary because we need to
9652 * leave the TB with the PC/IT state just prior to execution of the
9653 * instruction which caused the exception.
9654 * (3) if we leave the TB unexpectedly (eg a data abort on a load)
9655 * then the CPUState will be wrong and we need to reset it.
9656 * This is handled in the same way as restoration of the
9657 * PC in these situations: we will be called again with search_pc=1
9658 * and generate a mapping of the condexec bits for each PC in
9659 * gen_opc_condexec_bits[]. restore_state_to_opc() then uses
9660 * this to restore the condexec bits.
9662 * Note that there are no instructions which can read the condexec
9663 * bits, and none which can write non-static values to them, so
9664 * we don't need to care about whether CPUState is correct in the
9668 /* Reset the conditional execution bits immediately. This avoids
9669 complications trying to do it at the end of the block. */
9670 if (dc
->condexec_mask
|| dc
->condexec_cond
)
9672 TCGv tmp
= tcg_temp_new_i32();
9673 tcg_gen_movi_i32(tmp
, 0);
9674 store_cpu_field(tmp
, condexec_bits
);
9677 #ifdef CONFIG_USER_ONLY
9678 /* Intercept jump to the magic kernel page. */
9679 if (dc
->pc
>= 0xffff0000) {
9680 /* We always get here via a jump, so know we are not in a
9681 conditional execution block. */
9682 gen_exception(EXCP_KERNEL_TRAP
);
9683 dc
->is_jmp
= DISAS_UPDATE
;
9687 if (dc
->pc
>= 0xfffffff0 && IS_M(env
)) {
9688 /* We always get here via a jump, so know we are not in a
9689 conditional execution block. */
9690 gen_exception(EXCP_EXCEPTION_EXIT
);
9691 dc
->is_jmp
= DISAS_UPDATE
;
9696 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9697 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9698 if (bp
->pc
== dc
->pc
) {
9699 gen_exception_insn(dc
, 0, EXCP_DEBUG
);
9700 /* Advance PC so that clearing the breakpoint will
9701 invalidate this TB. */
9703 goto done_generating
;
9709 j
= gen_opc_ptr
- gen_opc_buf
;
9713 gen_opc_instr_start
[lj
++] = 0;
9715 gen_opc_pc
[lj
] = dc
->pc
;
9716 gen_opc_condexec_bits
[lj
] = (dc
->condexec_cond
<< 4) | (dc
->condexec_mask
>> 1);
9717 gen_opc_instr_start
[lj
] = 1;
9718 gen_opc_icount
[lj
] = num_insns
;
9721 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9724 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
))) {
9725 tcg_gen_debug_insn_start(dc
->pc
);
9729 disas_thumb_insn(env
, dc
);
9730 if (dc
->condexec_mask
) {
9731 dc
->condexec_cond
= (dc
->condexec_cond
& 0xe)
9732 | ((dc
->condexec_mask
>> 4) & 1);
9733 dc
->condexec_mask
= (dc
->condexec_mask
<< 1) & 0x1f;
9734 if (dc
->condexec_mask
== 0) {
9735 dc
->condexec_cond
= 0;
9739 disas_arm_insn(env
, dc
);
9742 if (dc
->condjmp
&& !dc
->is_jmp
) {
9743 gen_set_label(dc
->condlabel
);
9747 if (tcg_check_temp_count()) {
9748 fprintf(stderr
, "TCG temporary leak before %08x\n", dc
->pc
);
9751 /* Translation stops when a conditional branch is encountered.
9752 * Otherwise the subsequent code could get translated several times.
9753 * Also stop translation when a page boundary is reached. This
9754 * ensures prefetch aborts occur at the right place. */
9756 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
&&
9757 !env
->singlestep_enabled
&&
9759 dc
->pc
< next_page_start
&&
9760 num_insns
< max_insns
);
9762 if (tb
->cflags
& CF_LAST_IO
) {
9764 /* FIXME: This can theoretically happen with self-modifying
9766 cpu_abort(env
, "IO on conditional branch instruction");
9771 /* At this stage dc->condjmp will only be set when the skipped
9772 instruction was a conditional branch or trap, and the PC has
9773 already been written. */
9774 if (unlikely(env
->singlestep_enabled
)) {
9775 /* Make sure the pc is updated, and raise a debug exception. */
9777 gen_set_condexec(dc
);
9778 if (dc
->is_jmp
== DISAS_SWI
) {
9779 gen_exception(EXCP_SWI
);
9781 gen_exception(EXCP_DEBUG
);
9783 gen_set_label(dc
->condlabel
);
9785 if (dc
->condjmp
|| !dc
->is_jmp
) {
9786 gen_set_pc_im(dc
->pc
);
9789 gen_set_condexec(dc
);
9790 if (dc
->is_jmp
== DISAS_SWI
&& !dc
->condjmp
) {
9791 gen_exception(EXCP_SWI
);
9793 /* FIXME: Single stepping a WFI insn will not halt
9795 gen_exception(EXCP_DEBUG
);
9798 /* While branches must always occur at the end of an IT block,
9799 there are a few other things that can cause us to terminate
9800 the TB in the middel of an IT block:
9801 - Exception generating instructions (bkpt, swi, undefined).
9803 - Hardware watchpoints.
9804 Hardware breakpoints have already been handled and skip this code.
9806 gen_set_condexec(dc
);
9807 switch(dc
->is_jmp
) {
9809 gen_goto_tb(dc
, 1, dc
->pc
);
9814 /* indicate that the hash table must be used to find the next TB */
9818 /* nothing more to generate */
9824 gen_exception(EXCP_SWI
);
9828 gen_set_label(dc
->condlabel
);
9829 gen_set_condexec(dc
);
9830 gen_goto_tb(dc
, 1, dc
->pc
);
9836 gen_icount_end(tb
, num_insns
);
9837 *gen_opc_ptr
= INDEX_op_end
;
9840 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9841 qemu_log("----------------\n");
9842 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9843 log_target_disas(pc_start
, dc
->pc
- pc_start
, dc
->thumb
);
9848 j
= gen_opc_ptr
- gen_opc_buf
;
9851 gen_opc_instr_start
[lj
++] = 0;
9853 tb
->size
= dc
->pc
- pc_start
;
9854 tb
->icount
= num_insns
;
9858 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
9860 gen_intermediate_code_internal(env
, tb
, 0);
9863 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
9865 gen_intermediate_code_internal(env
, tb
, 1);
9868 static const char *cpu_mode_names
[16] = {
9869 "usr", "fiq", "irq", "svc", "???", "???", "???", "abt",
9870 "???", "???", "???", "und", "???", "???", "???", "sys"
9873 void cpu_dump_state(CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9883 /* ??? This assumes float64 and double have the same layout.
9884 Oh well, it's only debug dumps. */
9893 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
9895 cpu_fprintf(f
, "\n");
9897 cpu_fprintf(f
, " ");
9899 psr
= cpsr_read(env
);
9900 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %c %s%d\n",
9902 psr
& (1 << 31) ? 'N' : '-',
9903 psr
& (1 << 30) ? 'Z' : '-',
9904 psr
& (1 << 29) ? 'C' : '-',
9905 psr
& (1 << 28) ? 'V' : '-',
9906 psr
& CPSR_T
? 'T' : 'A',
9907 cpu_mode_names
[psr
& 0xf], (psr
& 0x10) ? 32 : 26);
9910 for (i
= 0; i
< 16; i
++) {
9911 d
.d
= env
->vfp
.regs
[i
];
9915 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g) d%02d=%08x%08x(%8g)\n",
9916 i
* 2, (int)s0
.i
, s0
.s
,
9917 i
* 2 + 1, (int)s1
.i
, s1
.s
,
9918 i
, (int)(uint32_t)d
.l
.upper
, (int)(uint32_t)d
.l
.lower
,
9921 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->vfp
.xregs
[ARM_VFP_FPSCR
]);
9925 void restore_state_to_opc(CPUState
*env
, TranslationBlock
*tb
, int pc_pos
)
9927 env
->regs
[15] = gen_opc_pc
[pc_pos
];
9928 env
->condexec_bits
= gen_opc_condexec_bits
[pc_pos
];