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 static TCGv_ptr get_fpstatus_ptr(int neon)
898 TCGv_ptr statusptr = tcg_temp_new_ptr();
901 offset = offsetof(CPUState, vfp.standard_fp_status);
903 offset = offsetof(CPUState, vfp.fp_status);
905 tcg_gen_addi_ptr(statusptr, cpu_env, offset);
909 #define VFP_OP2(name) \
910 static inline void gen_vfp_##name(int dp) \
912 TCGv_ptr fpst = get_fpstatus_ptr(0); \
914 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, cpu_F1d, fpst); \
916 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, cpu_F1s, fpst); \
918 tcg_temp_free_ptr(fpst); \
928 static inline void gen_vfp_F1_mul(int dp)
930 /* Like gen_vfp_mul() but put result in F1 */
931 TCGv_ptr fpst = get_fpstatus_ptr(0);
933 gen_helper_vfp_muld(cpu_F1d, cpu_F0d, cpu_F1d, fpst);
935 gen_helper_vfp_muls(cpu_F1s, cpu_F0s, cpu_F1s, fpst);
937 tcg_temp_free_ptr(fpst);
940 static inline void gen_vfp_F1_neg(int dp)
942 /* Like gen_vfp_neg() but put result in F1 */
944 gen_helper_vfp_negd(cpu_F1d, cpu_F0d);
946 gen_helper_vfp_negs(cpu_F1s, cpu_F0s);
950 static inline void gen_vfp_abs(int dp)
953 gen_helper_vfp_absd(cpu_F0d, cpu_F0d);
955 gen_helper_vfp_abss(cpu_F0s, cpu_F0s);
958 static inline void gen_vfp_neg(int dp)
961 gen_helper_vfp_negd(cpu_F0d, cpu_F0d);
963 gen_helper_vfp_negs(cpu_F0s, cpu_F0s);
966 static inline void gen_vfp_sqrt(int dp)
969 gen_helper_vfp_sqrtd(cpu_F0d, cpu_F0d, cpu_env);
971 gen_helper_vfp_sqrts(cpu_F0s, cpu_F0s, cpu_env);
974 static inline void gen_vfp_cmp(int dp)
977 gen_helper_vfp_cmpd(cpu_F0d, cpu_F1d, cpu_env);
979 gen_helper_vfp_cmps(cpu_F0s, cpu_F1s, cpu_env);
982 static inline void gen_vfp_cmpe(int dp)
985 gen_helper_vfp_cmped(cpu_F0d, cpu_F1d, cpu_env);
987 gen_helper_vfp_cmpes(cpu_F0s, cpu_F1s, cpu_env);
990 static inline void gen_vfp_F1_ld0(int dp)
993 tcg_gen_movi_i64(cpu_F1d, 0);
995 tcg_gen_movi_i32(cpu_F1s, 0);
998 #define VFP_GEN_ITOF(name) \
999 static inline void gen_vfp_##name(int dp, int neon) \
1001 TCGv_ptr statusptr = get_fpstatus_ptr(neon); \
1003 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0s, statusptr); \
1005 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, statusptr); \
1007 tcg_temp_free_ptr(statusptr); \
1014 #define VFP_GEN_FTOI(name) \
1015 static inline void gen_vfp_##name(int dp, int neon) \
1017 TCGv_ptr statusptr = get_fpstatus_ptr(neon); \
1019 gen_helper_vfp_##name##d(cpu_F0s, cpu_F0d, statusptr); \
1021 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, statusptr); \
1023 tcg_temp_free_ptr(statusptr); \
1032 #define VFP_GEN_FIX(name) \
1033 static inline void gen_vfp_##name(int dp, int shift, int neon) \
1035 TCGv tmp_shift = tcg_const_i32(shift); \
1036 TCGv_ptr statusptr = get_fpstatus_ptr(neon); \
1038 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, tmp_shift, statusptr); \
1040 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, tmp_shift, statusptr); \
1042 tcg_temp_free_i32(tmp_shift); \
1043 tcg_temp_free_ptr(statusptr); \
1055 static inline void gen_vfp_ld(DisasContext *s, int dp, TCGv addr)
1058 tcg_gen_qemu_ld64(cpu_F0d, addr, IS_USER(s));
1060 tcg_gen_qemu_ld32u(cpu_F0s, addr, IS_USER(s));
1063 static inline void gen_vfp_st(DisasContext *s, int dp, TCGv addr)
1066 tcg_gen_qemu_st64(cpu_F0d, addr, IS_USER(s));
1068 tcg_gen_qemu_st32(cpu_F0s, addr, IS_USER(s));
1072 vfp_reg_offset (int dp, int reg)
1075 return offsetof(CPUARMState, vfp.regs[reg]);
1077 return offsetof(CPUARMState, vfp.regs[reg >> 1])
1078 + offsetof(CPU_DoubleU, l.upper);
1080 return offsetof(CPUARMState, vfp.regs[reg >> 1])
1081 + offsetof(CPU_DoubleU, l.lower);
1085 /* Return the offset of a 32-bit piece of a NEON register.
1086 zero is the least significant end of the register. */
1088 neon_reg_offset (int reg, int n)
1092 return vfp_reg_offset(0, sreg);
1095 static TCGv neon_load_reg(int reg, int pass)
1097 TCGv tmp = tcg_temp_new_i32();
1098 tcg_gen_ld_i32(tmp, cpu_env, neon_reg_offset(reg, pass));
1102 static void neon_store_reg(int reg, int pass, TCGv var)
1104 tcg_gen_st_i32(var, cpu_env, neon_reg_offset(reg, pass));
1105 tcg_temp_free_i32(var);
1108 static inline void neon_load_reg64(TCGv_i64 var, int reg)
1110 tcg_gen_ld_i64(var, cpu_env, vfp_reg_offset(1, reg));
1113 static inline void neon_store_reg64(TCGv_i64 var, int reg)
1115 tcg_gen_st_i64(var, cpu_env, vfp_reg_offset(1, reg));
1118 #define tcg_gen_ld_f32 tcg_gen_ld_i32
1119 #define tcg_gen_ld_f64 tcg_gen_ld_i64
1120 #define tcg_gen_st_f32 tcg_gen_st_i32
1121 #define tcg_gen_st_f64 tcg_gen_st_i64
1123 static inline void gen_mov_F0_vreg(int dp, int reg)
1126 tcg_gen_ld_f64(cpu_F0d, cpu_env, vfp_reg_offset(dp, reg));
1128 tcg_gen_ld_f32(cpu_F0s, cpu_env, vfp_reg_offset(dp, reg));
1131 static inline void gen_mov_F1_vreg(int dp, int reg)
1134 tcg_gen_ld_f64(cpu_F1d, cpu_env, vfp_reg_offset(dp, reg));
1136 tcg_gen_ld_f32(cpu_F1s, cpu_env, vfp_reg_offset(dp, reg));
1139 static inline void gen_mov_vreg_F0(int dp, int reg)
1142 tcg_gen_st_f64(cpu_F0d, cpu_env, vfp_reg_offset(dp, reg));
1144 tcg_gen_st_f32(cpu_F0s, cpu_env, vfp_reg_offset(dp, reg));
1147 #define ARM_CP_RW_BIT (1 << 20)
1149 static inline void iwmmxt_load_reg(TCGv_i64 var, int reg)
1151 tcg_gen_ld_i64(var, cpu_env, offsetof(CPUState, iwmmxt.regs[reg]));
1154 static inline void iwmmxt_store_reg(TCGv_i64 var, int reg)
1156 tcg_gen_st_i64(var, cpu_env, offsetof(CPUState, iwmmxt.regs[reg]));
1159 static inline TCGv iwmmxt_load_creg(int reg)
1161 TCGv var = tcg_temp_new_i32();
1162 tcg_gen_ld_i32(var, cpu_env, offsetof(CPUState, iwmmxt.cregs[reg]));
1166 static inline void iwmmxt_store_creg(int reg, TCGv var)
1168 tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, iwmmxt.cregs[reg]));
1169 tcg_temp_free_i32(var);
1172 static inline void gen_op_iwmmxt_movq_wRn_M0(int rn)
1174 iwmmxt_store_reg(cpu_M0, rn);
1177 static inline void gen_op_iwmmxt_movq_M0_wRn(int rn)
1179 iwmmxt_load_reg(cpu_M0, rn);
1182 static inline void gen_op_iwmmxt_orq_M0_wRn(int rn)
1184 iwmmxt_load_reg(cpu_V1, rn);
1185 tcg_gen_or_i64(cpu_M0, cpu_M0, cpu_V1);
1188 static inline void gen_op_iwmmxt_andq_M0_wRn(int rn)
1190 iwmmxt_load_reg(cpu_V1, rn);
1191 tcg_gen_and_i64(cpu_M0, cpu_M0, cpu_V1);
1194 static inline void gen_op_iwmmxt_xorq_M0_wRn(int rn)
1196 iwmmxt_load_reg(cpu_V1, rn);
1197 tcg_gen_xor_i64(cpu_M0, cpu_M0, cpu_V1);
1200 #define IWMMXT_OP(name) \
1201 static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
1203 iwmmxt_load_reg(cpu_V1, rn); \
1204 gen_helper_iwmmxt_##name(cpu_M0, cpu_M0, cpu_V1); \
1207 #define IWMMXT_OP_ENV(name) \
1208 static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
1210 iwmmxt_load_reg(cpu_V1, rn); \
1211 gen_helper_iwmmxt_##name(cpu_M0, cpu_env, cpu_M0, cpu_V1); \
1214 #define IWMMXT_OP_ENV_SIZE(name) \
1215 IWMMXT_OP_ENV(name##b) \
1216 IWMMXT_OP_ENV(name##w) \
1217 IWMMXT_OP_ENV(name##l)
1219 #define IWMMXT_OP_ENV1(name) \
1220 static inline void gen_op_iwmmxt_##name##_M0(void) \
1222 gen_helper_iwmmxt_##name(cpu_M0, cpu_env, cpu_M0); \
1236 IWMMXT_OP_ENV_SIZE(unpackl)
1237 IWMMXT_OP_ENV_SIZE(unpackh)
1239 IWMMXT_OP_ENV1(unpacklub)
1240 IWMMXT_OP_ENV1(unpackluw)
1241 IWMMXT_OP_ENV1(unpacklul)
1242 IWMMXT_OP_ENV1(unpackhub)
1243 IWMMXT_OP_ENV1(unpackhuw)
1244 IWMMXT_OP_ENV1(unpackhul)
1245 IWMMXT_OP_ENV1(unpacklsb)
1246 IWMMXT_OP_ENV1(unpacklsw)
1247 IWMMXT_OP_ENV1(unpacklsl)
1248 IWMMXT_OP_ENV1(unpackhsb)
1249 IWMMXT_OP_ENV1(unpackhsw)
1250 IWMMXT_OP_ENV1(unpackhsl)
1252 IWMMXT_OP_ENV_SIZE(cmpeq)
1253 IWMMXT_OP_ENV_SIZE(cmpgtu)
1254 IWMMXT_OP_ENV_SIZE(cmpgts)
1256 IWMMXT_OP_ENV_SIZE(mins)
1257 IWMMXT_OP_ENV_SIZE(minu)
1258 IWMMXT_OP_ENV_SIZE(maxs)
1259 IWMMXT_OP_ENV_SIZE(maxu)
1261 IWMMXT_OP_ENV_SIZE(subn)
1262 IWMMXT_OP_ENV_SIZE(addn)
1263 IWMMXT_OP_ENV_SIZE(subu)
1264 IWMMXT_OP_ENV_SIZE(addu)
1265 IWMMXT_OP_ENV_SIZE(subs)
1266 IWMMXT_OP_ENV_SIZE(adds)
1268 IWMMXT_OP_ENV(avgb0)
1269 IWMMXT_OP_ENV(avgb1)
1270 IWMMXT_OP_ENV(avgw0)
1271 IWMMXT_OP_ENV(avgw1)
1275 IWMMXT_OP_ENV(packuw)
1276 IWMMXT_OP_ENV(packul)
1277 IWMMXT_OP_ENV(packuq)
1278 IWMMXT_OP_ENV(packsw)
1279 IWMMXT_OP_ENV(packsl)
1280 IWMMXT_OP_ENV(packsq)
1282 static void gen_op_iwmmxt_set_mup(void)
1285 tmp = load_cpu_field(iwmmxt.cregs[ARM_IWMMXT_wCon]);
1286 tcg_gen_ori_i32(tmp, tmp, 2);
1287 store_cpu_field(tmp, iwmmxt.cregs[ARM_IWMMXT_wCon]);
1290 static void gen_op_iwmmxt_set_cup(void)
1293 tmp = load_cpu_field(iwmmxt.cregs[ARM_IWMMXT_wCon]);
1294 tcg_gen_ori_i32(tmp, tmp, 1);
1295 store_cpu_field(tmp, iwmmxt.cregs[ARM_IWMMXT_wCon]);
1298 static void gen_op_iwmmxt_setpsr_nz(void)
1300 TCGv tmp = tcg_temp_new_i32();
1301 gen_helper_iwmmxt_setpsr_nz(tmp, cpu_M0);
1302 store_cpu_field(tmp, iwmmxt.cregs[ARM_IWMMXT_wCASF]);
1305 static inline void gen_op_iwmmxt_addl_M0_wRn(int rn)
1307 iwmmxt_load_reg(cpu_V1, rn);
1308 tcg_gen_ext32u_i64(cpu_V1, cpu_V1);
1309 tcg_gen_add_i64(cpu_M0, cpu_M0, cpu_V1);
1312 static inline int gen_iwmmxt_address(DisasContext *s, uint32_t insn, TCGv dest)
1318 rd = (insn >> 16) & 0xf;
1319 tmp = load_reg(s, rd);
1321 offset = (insn & 0xff) << ((insn >> 7) & 2);
1322 if (insn & (1 << 24)) {
1324 if (insn & (1 << 23))
1325 tcg_gen_addi_i32(tmp, tmp, offset);
1327 tcg_gen_addi_i32(tmp, tmp, -offset);
1328 tcg_gen_mov_i32(dest, tmp);
1329 if (insn & (1 << 21))
1330 store_reg(s, rd, tmp);
1332 tcg_temp_free_i32(tmp);
1333 } else if (insn & (1 << 21)) {
1335 tcg_gen_mov_i32(dest, tmp);
1336 if (insn & (1 << 23))
1337 tcg_gen_addi_i32(tmp, tmp, offset);
1339 tcg_gen_addi_i32(tmp, tmp, -offset);
1340 store_reg(s, rd, tmp);
1341 } else if (!(insn & (1 << 23)))
1346 static inline int gen_iwmmxt_shift(uint32_t insn, uint32_t mask, TCGv dest)
1348 int rd = (insn >> 0) & 0xf;
1351 if (insn & (1 << 8)) {
1352 if (rd < ARM_IWMMXT_wCGR0 || rd > ARM_IWMMXT_wCGR3) {
1355 tmp = iwmmxt_load_creg(rd);
1358 tmp = tcg_temp_new_i32();
1359 iwmmxt_load_reg(cpu_V0, rd);
1360 tcg_gen_trunc_i64_i32(tmp, cpu_V0);
1362 tcg_gen_andi_i32(tmp, tmp, mask);
1363 tcg_gen_mov_i32(dest, tmp);
1364 tcg_temp_free_i32(tmp);
1368 /* Disassemble an iwMMXt instruction. Returns nonzero if an error occurred
1369 (ie. an undefined instruction). */
1370 static int disas_iwmmxt_insn(CPUState *env, DisasContext *s, uint32_t insn)
1373 int rdhi, rdlo, rd0, rd1, i;
1375 TCGv tmp, tmp2, tmp3;
1377 if ((insn & 0x0e000e00) == 0x0c000000) {
1378 if ((insn & 0x0fe00ff0) == 0x0c400000) {
1380 rdlo = (insn >> 12) & 0xf;
1381 rdhi = (insn >> 16) & 0xf;
1382 if (insn & ARM_CP_RW_BIT) { /* TMRRC */
1383 iwmmxt_load_reg(cpu_V0, wrd);
1384 tcg_gen_trunc_i64_i32(cpu_R[rdlo], cpu_V0);
1385 tcg_gen_shri_i64(cpu_V0, cpu_V0, 32);
1386 tcg_gen_trunc_i64_i32(cpu_R[rdhi], cpu_V0);
1387 } else { /* TMCRR */
1388 tcg_gen_concat_i32_i64(cpu_V0, cpu_R[rdlo], cpu_R[rdhi]);
1389 iwmmxt_store_reg(cpu_V0, wrd);
1390 gen_op_iwmmxt_set_mup();
1395 wrd = (insn >> 12) & 0xf;
1396 addr = tcg_temp_new_i32();
1397 if (gen_iwmmxt_address(s, insn, addr)) {
1398 tcg_temp_free_i32(addr);
1401 if (insn & ARM_CP_RW_BIT) {
1402 if ((insn >> 28) == 0xf) { /* WLDRW wCx */
1403 tmp = tcg_temp_new_i32();
1404 tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
1405 iwmmxt_store_creg(wrd, tmp);
1408 if (insn & (1 << 8)) {
1409 if (insn & (1 << 22)) { /* WLDRD */
1410 tcg_gen_qemu_ld64(cpu_M0, addr, IS_USER(s));
1412 } else { /* WLDRW wRd */
1413 tmp = gen_ld32(addr, IS_USER(s));
1416 if (insn & (1 << 22)) { /* WLDRH */
1417 tmp = gen_ld16u(addr, IS_USER(s));
1418 } else { /* WLDRB */
1419 tmp = gen_ld8u(addr, IS_USER(s));
1423 tcg_gen_extu_i32_i64(cpu_M0, tmp);
1424 tcg_temp_free_i32(tmp);
1426 gen_op_iwmmxt_movq_wRn_M0(wrd);
1429 if ((insn >> 28) == 0xf) { /* WSTRW wCx */
1430 tmp = iwmmxt_load_creg(wrd);
1431 gen_st32(tmp, addr, IS_USER(s));
1433 gen_op_iwmmxt_movq_M0_wRn(wrd);
1434 tmp = tcg_temp_new_i32();
1435 if (insn & (1 << 8)) {
1436 if (insn & (1 << 22)) { /* WSTRD */
1437 tcg_temp_free_i32(tmp);
1438 tcg_gen_qemu_st64(cpu_M0, addr, IS_USER(s));
1439 } else { /* WSTRW wRd */
1440 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1441 gen_st32(tmp, addr, IS_USER(s));
1444 if (insn & (1 << 22)) { /* WSTRH */
1445 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1446 gen_st16(tmp, addr, IS_USER(s));
1447 } else { /* WSTRB */
1448 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1449 gen_st8(tmp, addr, IS_USER(s));
1454 tcg_temp_free_i32(addr);
1458 if ((insn & 0x0f000000) != 0x0e000000)
1461 switch (((insn >> 12) & 0xf00) | ((insn >> 4) & 0xff)) {
1462 case 0x000: /* WOR */
1463 wrd = (insn >> 12) & 0xf;
1464 rd0 = (insn >> 0) & 0xf;
1465 rd1 = (insn >> 16) & 0xf;
1466 gen_op_iwmmxt_movq_M0_wRn(rd0);
1467 gen_op_iwmmxt_orq_M0_wRn(rd1);
1468 gen_op_iwmmxt_setpsr_nz();
1469 gen_op_iwmmxt_movq_wRn_M0(wrd);
1470 gen_op_iwmmxt_set_mup();
1471 gen_op_iwmmxt_set_cup();
1473 case 0x011: /* TMCR */
1476 rd = (insn >> 12) & 0xf;
1477 wrd = (insn >> 16) & 0xf;
1479 case ARM_IWMMXT_wCID:
1480 case ARM_IWMMXT_wCASF:
1482 case ARM_IWMMXT_wCon:
1483 gen_op_iwmmxt_set_cup();
1485 case ARM_IWMMXT_wCSSF:
1486 tmp = iwmmxt_load_creg(wrd);
1487 tmp2 = load_reg(s, rd);
1488 tcg_gen_andc_i32(tmp, tmp, tmp2);
1489 tcg_temp_free_i32(tmp2);
1490 iwmmxt_store_creg(wrd, tmp);
1492 case ARM_IWMMXT_wCGR0:
1493 case ARM_IWMMXT_wCGR1:
1494 case ARM_IWMMXT_wCGR2:
1495 case ARM_IWMMXT_wCGR3:
1496 gen_op_iwmmxt_set_cup();
1497 tmp = load_reg(s, rd);
1498 iwmmxt_store_creg(wrd, tmp);
1504 case 0x100: /* WXOR */
1505 wrd = (insn >> 12) & 0xf;
1506 rd0 = (insn >> 0) & 0xf;
1507 rd1 = (insn >> 16) & 0xf;
1508 gen_op_iwmmxt_movq_M0_wRn(rd0);
1509 gen_op_iwmmxt_xorq_M0_wRn(rd1);
1510 gen_op_iwmmxt_setpsr_nz();
1511 gen_op_iwmmxt_movq_wRn_M0(wrd);
1512 gen_op_iwmmxt_set_mup();
1513 gen_op_iwmmxt_set_cup();
1515 case 0x111: /* TMRC */
1518 rd = (insn >> 12) & 0xf;
1519 wrd = (insn >> 16) & 0xf;
1520 tmp = iwmmxt_load_creg(wrd);
1521 store_reg(s, rd, tmp);
1523 case 0x300: /* WANDN */
1524 wrd = (insn >> 12) & 0xf;
1525 rd0 = (insn >> 0) & 0xf;
1526 rd1 = (insn >> 16) & 0xf;
1527 gen_op_iwmmxt_movq_M0_wRn(rd0);
1528 tcg_gen_neg_i64(cpu_M0, cpu_M0);
1529 gen_op_iwmmxt_andq_M0_wRn(rd1);
1530 gen_op_iwmmxt_setpsr_nz();
1531 gen_op_iwmmxt_movq_wRn_M0(wrd);
1532 gen_op_iwmmxt_set_mup();
1533 gen_op_iwmmxt_set_cup();
1535 case 0x200: /* WAND */
1536 wrd = (insn >> 12) & 0xf;
1537 rd0 = (insn >> 0) & 0xf;
1538 rd1 = (insn >> 16) & 0xf;
1539 gen_op_iwmmxt_movq_M0_wRn(rd0);
1540 gen_op_iwmmxt_andq_M0_wRn(rd1);
1541 gen_op_iwmmxt_setpsr_nz();
1542 gen_op_iwmmxt_movq_wRn_M0(wrd);
1543 gen_op_iwmmxt_set_mup();
1544 gen_op_iwmmxt_set_cup();
1546 case 0x810: case 0xa10: /* WMADD */
1547 wrd = (insn >> 12) & 0xf;
1548 rd0 = (insn >> 0) & 0xf;
1549 rd1 = (insn >> 16) & 0xf;
1550 gen_op_iwmmxt_movq_M0_wRn(rd0);
1551 if (insn & (1 << 21))
1552 gen_op_iwmmxt_maddsq_M0_wRn(rd1);
1554 gen_op_iwmmxt_madduq_M0_wRn(rd1);
1555 gen_op_iwmmxt_movq_wRn_M0(wrd);
1556 gen_op_iwmmxt_set_mup();
1558 case 0x10e: case 0x50e: case 0x90e: case 0xd0e: /* WUNPCKIL */
1559 wrd = (insn >> 12) & 0xf;
1560 rd0 = (insn >> 16) & 0xf;
1561 rd1 = (insn >> 0) & 0xf;
1562 gen_op_iwmmxt_movq_M0_wRn(rd0);
1563 switch ((insn >> 22) & 3) {
1565 gen_op_iwmmxt_unpacklb_M0_wRn(rd1);
1568 gen_op_iwmmxt_unpacklw_M0_wRn(rd1);
1571 gen_op_iwmmxt_unpackll_M0_wRn(rd1);
1576 gen_op_iwmmxt_movq_wRn_M0(wrd);
1577 gen_op_iwmmxt_set_mup();
1578 gen_op_iwmmxt_set_cup();
1580 case 0x10c: case 0x50c: case 0x90c: case 0xd0c: /* WUNPCKIH */
1581 wrd = (insn >> 12) & 0xf;
1582 rd0 = (insn >> 16) & 0xf;
1583 rd1 = (insn >> 0) & 0xf;
1584 gen_op_iwmmxt_movq_M0_wRn(rd0);
1585 switch ((insn >> 22) & 3) {
1587 gen_op_iwmmxt_unpackhb_M0_wRn(rd1);
1590 gen_op_iwmmxt_unpackhw_M0_wRn(rd1);
1593 gen_op_iwmmxt_unpackhl_M0_wRn(rd1);
1598 gen_op_iwmmxt_movq_wRn_M0(wrd);
1599 gen_op_iwmmxt_set_mup();
1600 gen_op_iwmmxt_set_cup();
1602 case 0x012: case 0x112: case 0x412: case 0x512: /* WSAD */
1603 wrd = (insn >> 12) & 0xf;
1604 rd0 = (insn >> 16) & 0xf;
1605 rd1 = (insn >> 0) & 0xf;
1606 gen_op_iwmmxt_movq_M0_wRn(rd0);
1607 if (insn & (1 << 22))
1608 gen_op_iwmmxt_sadw_M0_wRn(rd1);
1610 gen_op_iwmmxt_sadb_M0_wRn(rd1);
1611 if (!(insn & (1 << 20)))
1612 gen_op_iwmmxt_addl_M0_wRn(wrd);
1613 gen_op_iwmmxt_movq_wRn_M0(wrd);
1614 gen_op_iwmmxt_set_mup();
1616 case 0x010: case 0x110: case 0x210: case 0x310: /* WMUL */
1617 wrd = (insn >> 12) & 0xf;
1618 rd0 = (insn >> 16) & 0xf;
1619 rd1 = (insn >> 0) & 0xf;
1620 gen_op_iwmmxt_movq_M0_wRn(rd0);
1621 if (insn & (1 << 21)) {
1622 if (insn & (1 << 20))
1623 gen_op_iwmmxt_mulshw_M0_wRn(rd1);
1625 gen_op_iwmmxt_mulslw_M0_wRn(rd1);
1627 if (insn & (1 << 20))
1628 gen_op_iwmmxt_muluhw_M0_wRn(rd1);
1630 gen_op_iwmmxt_mululw_M0_wRn(rd1);
1632 gen_op_iwmmxt_movq_wRn_M0(wrd);
1633 gen_op_iwmmxt_set_mup();
1635 case 0x410: case 0x510: case 0x610: case 0x710: /* WMAC */
1636 wrd = (insn >> 12) & 0xf;
1637 rd0 = (insn >> 16) & 0xf;
1638 rd1 = (insn >> 0) & 0xf;
1639 gen_op_iwmmxt_movq_M0_wRn(rd0);
1640 if (insn & (1 << 21))
1641 gen_op_iwmmxt_macsw_M0_wRn(rd1);
1643 gen_op_iwmmxt_macuw_M0_wRn(rd1);
1644 if (!(insn & (1 << 20))) {
1645 iwmmxt_load_reg(cpu_V1, wrd);
1646 tcg_gen_add_i64(cpu_M0, cpu_M0, cpu_V1);
1648 gen_op_iwmmxt_movq_wRn_M0(wrd);
1649 gen_op_iwmmxt_set_mup();
1651 case 0x006: case 0x406: case 0x806: case 0xc06: /* WCMPEQ */
1652 wrd = (insn >> 12) & 0xf;
1653 rd0 = (insn >> 16) & 0xf;
1654 rd1 = (insn >> 0) & 0xf;
1655 gen_op_iwmmxt_movq_M0_wRn(rd0);
1656 switch ((insn >> 22) & 3) {
1658 gen_op_iwmmxt_cmpeqb_M0_wRn(rd1);
1661 gen_op_iwmmxt_cmpeqw_M0_wRn(rd1);
1664 gen_op_iwmmxt_cmpeql_M0_wRn(rd1);
1669 gen_op_iwmmxt_movq_wRn_M0(wrd);
1670 gen_op_iwmmxt_set_mup();
1671 gen_op_iwmmxt_set_cup();
1673 case 0x800: case 0x900: case 0xc00: case 0xd00: /* WAVG2 */
1674 wrd = (insn >> 12) & 0xf;
1675 rd0 = (insn >> 16) & 0xf;
1676 rd1 = (insn >> 0) & 0xf;
1677 gen_op_iwmmxt_movq_M0_wRn(rd0);
1678 if (insn & (1 << 22)) {
1679 if (insn & (1 << 20))
1680 gen_op_iwmmxt_avgw1_M0_wRn(rd1);
1682 gen_op_iwmmxt_avgw0_M0_wRn(rd1);
1684 if (insn & (1 << 20))
1685 gen_op_iwmmxt_avgb1_M0_wRn(rd1);
1687 gen_op_iwmmxt_avgb0_M0_wRn(rd1);
1689 gen_op_iwmmxt_movq_wRn_M0(wrd);
1690 gen_op_iwmmxt_set_mup();
1691 gen_op_iwmmxt_set_cup();
1693 case 0x802: case 0x902: case 0xa02: case 0xb02: /* WALIGNR */
1694 wrd = (insn >> 12) & 0xf;
1695 rd0 = (insn >> 16) & 0xf;
1696 rd1 = (insn >> 0) & 0xf;
1697 gen_op_iwmmxt_movq_M0_wRn(rd0);
1698 tmp = iwmmxt_load_creg(ARM_IWMMXT_wCGR0 + ((insn >> 20) & 3));
1699 tcg_gen_andi_i32(tmp, tmp, 7);
1700 iwmmxt_load_reg(cpu_V1, rd1);
1701 gen_helper_iwmmxt_align(cpu_M0, cpu_M0, cpu_V1, tmp);
1702 tcg_temp_free_i32(tmp);
1703 gen_op_iwmmxt_movq_wRn_M0(wrd);
1704 gen_op_iwmmxt_set_mup();
1706 case 0x601: case 0x605: case 0x609: case 0x60d: /* TINSR */
1707 if (((insn >> 6) & 3) == 3)
1709 rd = (insn >> 12) & 0xf;
1710 wrd = (insn >> 16) & 0xf;
1711 tmp = load_reg(s, rd);
1712 gen_op_iwmmxt_movq_M0_wRn(wrd);
1713 switch ((insn >> 6) & 3) {
1715 tmp2 = tcg_const_i32(0xff);
1716 tmp3 = tcg_const_i32((insn & 7) << 3);
1719 tmp2 = tcg_const_i32(0xffff);
1720 tmp3 = tcg_const_i32((insn & 3) << 4);
1723 tmp2 = tcg_const_i32(0xffffffff);
1724 tmp3 = tcg_const_i32((insn & 1) << 5);
1730 gen_helper_iwmmxt_insr(cpu_M0, cpu_M0, tmp, tmp2, tmp3);
1731 tcg_temp_free(tmp3);
1732 tcg_temp_free(tmp2);
1733 tcg_temp_free_i32(tmp);
1734 gen_op_iwmmxt_movq_wRn_M0(wrd);
1735 gen_op_iwmmxt_set_mup();
1737 case 0x107: case 0x507: case 0x907: case 0xd07: /* TEXTRM */
1738 rd = (insn >> 12) & 0xf;
1739 wrd = (insn >> 16) & 0xf;
1740 if (rd == 15 || ((insn >> 22) & 3) == 3)
1742 gen_op_iwmmxt_movq_M0_wRn(wrd);
1743 tmp = tcg_temp_new_i32();
1744 switch ((insn >> 22) & 3) {
1746 tcg_gen_shri_i64(cpu_M0, cpu_M0, (insn & 7) << 3);
1747 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1749 tcg_gen_ext8s_i32(tmp, tmp);
1751 tcg_gen_andi_i32(tmp, tmp, 0xff);
1755 tcg_gen_shri_i64(cpu_M0, cpu_M0, (insn & 3) << 4);
1756 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1758 tcg_gen_ext16s_i32(tmp, tmp);
1760 tcg_gen_andi_i32(tmp, tmp, 0xffff);
1764 tcg_gen_shri_i64(cpu_M0, cpu_M0, (insn & 1) << 5);
1765 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1768 store_reg(s, rd, tmp);
1770 case 0x117: case 0x517: case 0x917: case 0xd17: /* TEXTRC */
1771 if ((insn & 0x000ff008) != 0x0003f000 || ((insn >> 22) & 3) == 3)
1773 tmp = iwmmxt_load_creg(ARM_IWMMXT_wCASF);
1774 switch ((insn >> 22) & 3) {
1776 tcg_gen_shri_i32(tmp, tmp, ((insn & 7) << 2) + 0);
1779 tcg_gen_shri_i32(tmp, tmp, ((insn & 3) << 3) + 4);
1782 tcg_gen_shri_i32(tmp, tmp, ((insn & 1) << 4) + 12);
1785 tcg_gen_shli_i32(tmp, tmp, 28);
1787 tcg_temp_free_i32(tmp);
1789 case 0x401: case 0x405: case 0x409: case 0x40d: /* TBCST */
1790 if (((insn >> 6) & 3) == 3)
1792 rd = (insn >> 12) & 0xf;
1793 wrd = (insn >> 16) & 0xf;
1794 tmp = load_reg(s, rd);
1795 switch ((insn >> 6) & 3) {
1797 gen_helper_iwmmxt_bcstb(cpu_M0, tmp);
1800 gen_helper_iwmmxt_bcstw(cpu_M0, tmp);
1803 gen_helper_iwmmxt_bcstl(cpu_M0, tmp);
1806 tcg_temp_free_i32(tmp);
1807 gen_op_iwmmxt_movq_wRn_M0(wrd);
1808 gen_op_iwmmxt_set_mup();
1810 case 0x113: case 0x513: case 0x913: case 0xd13: /* TANDC */
1811 if ((insn & 0x000ff00f) != 0x0003f000 || ((insn >> 22) & 3) == 3)
1813 tmp = iwmmxt_load_creg(ARM_IWMMXT_wCASF);
1814 tmp2 = tcg_temp_new_i32();
1815 tcg_gen_mov_i32(tmp2, tmp);
1816 switch ((insn >> 22) & 3) {
1818 for (i = 0; i < 7; i ++) {
1819 tcg_gen_shli_i32(tmp2, tmp2, 4);
1820 tcg_gen_and_i32(tmp, tmp, tmp2);
1824 for (i = 0; i < 3; i ++) {
1825 tcg_gen_shli_i32(tmp2, tmp2, 8);
1826 tcg_gen_and_i32(tmp, tmp, tmp2);
1830 tcg_gen_shli_i32(tmp2, tmp2, 16);
1831 tcg_gen_and_i32(tmp, tmp, tmp2);
1835 tcg_temp_free_i32(tmp2);
1836 tcg_temp_free_i32(tmp);
1838 case 0x01c: case 0x41c: case 0x81c: case 0xc1c: /* WACC */
1839 wrd = (insn >> 12) & 0xf;
1840 rd0 = (insn >> 16) & 0xf;
1841 gen_op_iwmmxt_movq_M0_wRn(rd0);
1842 switch ((insn >> 22) & 3) {
1844 gen_helper_iwmmxt_addcb(cpu_M0, cpu_M0);
1847 gen_helper_iwmmxt_addcw(cpu_M0, cpu_M0);
1850 gen_helper_iwmmxt_addcl(cpu_M0, cpu_M0);
1855 gen_op_iwmmxt_movq_wRn_M0(wrd);
1856 gen_op_iwmmxt_set_mup();
1858 case 0x115: case 0x515: case 0x915: case 0xd15: /* TORC */
1859 if ((insn & 0x000ff00f) != 0x0003f000 || ((insn >> 22) & 3) == 3)
1861 tmp = iwmmxt_load_creg(ARM_IWMMXT_wCASF);
1862 tmp2 = tcg_temp_new_i32();
1863 tcg_gen_mov_i32(tmp2, tmp);
1864 switch ((insn >> 22) & 3) {
1866 for (i = 0; i < 7; i ++) {
1867 tcg_gen_shli_i32(tmp2, tmp2, 4);
1868 tcg_gen_or_i32(tmp, tmp, tmp2);
1872 for (i = 0; i < 3; i ++) {
1873 tcg_gen_shli_i32(tmp2, tmp2, 8);
1874 tcg_gen_or_i32(tmp, tmp, tmp2);
1878 tcg_gen_shli_i32(tmp2, tmp2, 16);
1879 tcg_gen_or_i32(tmp, tmp, tmp2);
1883 tcg_temp_free_i32(tmp2);
1884 tcg_temp_free_i32(tmp);
1886 case 0x103: case 0x503: case 0x903: case 0xd03: /* TMOVMSK */
1887 rd = (insn >> 12) & 0xf;
1888 rd0 = (insn >> 16) & 0xf;
1889 if ((insn & 0xf) != 0 || ((insn >> 22) & 3) == 3)
1891 gen_op_iwmmxt_movq_M0_wRn(rd0);
1892 tmp = tcg_temp_new_i32();
1893 switch ((insn >> 22) & 3) {
1895 gen_helper_iwmmxt_msbb(tmp, cpu_M0);
1898 gen_helper_iwmmxt_msbw(tmp, cpu_M0);
1901 gen_helper_iwmmxt_msbl(tmp, cpu_M0);
1904 store_reg(s, rd, tmp);
1906 case 0x106: case 0x306: case 0x506: case 0x706: /* WCMPGT */
1907 case 0x906: case 0xb06: case 0xd06: case 0xf06:
1908 wrd = (insn >> 12) & 0xf;
1909 rd0 = (insn >> 16) & 0xf;
1910 rd1 = (insn >> 0) & 0xf;
1911 gen_op_iwmmxt_movq_M0_wRn(rd0);
1912 switch ((insn >> 22) & 3) {
1914 if (insn & (1 << 21))
1915 gen_op_iwmmxt_cmpgtsb_M0_wRn(rd1);
1917 gen_op_iwmmxt_cmpgtub_M0_wRn(rd1);
1920 if (insn & (1 << 21))
1921 gen_op_iwmmxt_cmpgtsw_M0_wRn(rd1);
1923 gen_op_iwmmxt_cmpgtuw_M0_wRn(rd1);
1926 if (insn & (1 << 21))
1927 gen_op_iwmmxt_cmpgtsl_M0_wRn(rd1);
1929 gen_op_iwmmxt_cmpgtul_M0_wRn(rd1);
1934 gen_op_iwmmxt_movq_wRn_M0(wrd);
1935 gen_op_iwmmxt_set_mup();
1936 gen_op_iwmmxt_set_cup();
1938 case 0x00e: case 0x20e: case 0x40e: case 0x60e: /* WUNPCKEL */
1939 case 0x80e: case 0xa0e: case 0xc0e: case 0xe0e:
1940 wrd = (insn >> 12) & 0xf;
1941 rd0 = (insn >> 16) & 0xf;
1942 gen_op_iwmmxt_movq_M0_wRn(rd0);
1943 switch ((insn >> 22) & 3) {
1945 if (insn & (1 << 21))
1946 gen_op_iwmmxt_unpacklsb_M0();
1948 gen_op_iwmmxt_unpacklub_M0();
1951 if (insn & (1 << 21))
1952 gen_op_iwmmxt_unpacklsw_M0();
1954 gen_op_iwmmxt_unpackluw_M0();
1957 if (insn & (1 << 21))
1958 gen_op_iwmmxt_unpacklsl_M0();
1960 gen_op_iwmmxt_unpacklul_M0();
1965 gen_op_iwmmxt_movq_wRn_M0(wrd);
1966 gen_op_iwmmxt_set_mup();
1967 gen_op_iwmmxt_set_cup();
1969 case 0x00c: case 0x20c: case 0x40c: case 0x60c: /* WUNPCKEH */
1970 case 0x80c: case 0xa0c: case 0xc0c: case 0xe0c:
1971 wrd = (insn >> 12) & 0xf;
1972 rd0 = (insn >> 16) & 0xf;
1973 gen_op_iwmmxt_movq_M0_wRn(rd0);
1974 switch ((insn >> 22) & 3) {
1976 if (insn & (1 << 21))
1977 gen_op_iwmmxt_unpackhsb_M0();
1979 gen_op_iwmmxt_unpackhub_M0();
1982 if (insn & (1 << 21))
1983 gen_op_iwmmxt_unpackhsw_M0();
1985 gen_op_iwmmxt_unpackhuw_M0();
1988 if (insn & (1 << 21))
1989 gen_op_iwmmxt_unpackhsl_M0();
1991 gen_op_iwmmxt_unpackhul_M0();
1996 gen_op_iwmmxt_movq_wRn_M0(wrd);
1997 gen_op_iwmmxt_set_mup();
1998 gen_op_iwmmxt_set_cup();
2000 case 0x204: case 0x604: case 0xa04: case 0xe04: /* WSRL */
2001 case 0x214: case 0x614: case 0xa14: case 0xe14:
2002 if (((insn >> 22) & 3) == 0)
2004 wrd = (insn >> 12) & 0xf;
2005 rd0 = (insn >> 16) & 0xf;
2006 gen_op_iwmmxt_movq_M0_wRn(rd0);
2007 tmp = tcg_temp_new_i32();
2008 if (gen_iwmmxt_shift(insn, 0xff, tmp)) {
2009 tcg_temp_free_i32(tmp);
2012 switch ((insn >> 22) & 3) {
2014 gen_helper_iwmmxt_srlw(cpu_M0, cpu_env, cpu_M0, tmp);
2017 gen_helper_iwmmxt_srll(cpu_M0, cpu_env, cpu_M0, tmp);
2020 gen_helper_iwmmxt_srlq(cpu_M0, cpu_env, cpu_M0, tmp);
2023 tcg_temp_free_i32(tmp);
2024 gen_op_iwmmxt_movq_wRn_M0(wrd);
2025 gen_op_iwmmxt_set_mup();
2026 gen_op_iwmmxt_set_cup();
2028 case 0x004: case 0x404: case 0x804: case 0xc04: /* WSRA */
2029 case 0x014: case 0x414: case 0x814: case 0xc14:
2030 if (((insn >> 22) & 3) == 0)
2032 wrd = (insn >> 12) & 0xf;
2033 rd0 = (insn >> 16) & 0xf;
2034 gen_op_iwmmxt_movq_M0_wRn(rd0);
2035 tmp = tcg_temp_new_i32();
2036 if (gen_iwmmxt_shift(insn, 0xff, tmp)) {
2037 tcg_temp_free_i32(tmp);
2040 switch ((insn >> 22) & 3) {
2042 gen_helper_iwmmxt_sraw(cpu_M0, cpu_env, cpu_M0, tmp);
2045 gen_helper_iwmmxt_sral(cpu_M0, cpu_env, cpu_M0, tmp);
2048 gen_helper_iwmmxt_sraq(cpu_M0, cpu_env, cpu_M0, tmp);
2051 tcg_temp_free_i32(tmp);
2052 gen_op_iwmmxt_movq_wRn_M0(wrd);
2053 gen_op_iwmmxt_set_mup();
2054 gen_op_iwmmxt_set_cup();
2056 case 0x104: case 0x504: case 0x904: case 0xd04: /* WSLL */
2057 case 0x114: case 0x514: case 0x914: case 0xd14:
2058 if (((insn >> 22) & 3) == 0)
2060 wrd = (insn >> 12) & 0xf;
2061 rd0 = (insn >> 16) & 0xf;
2062 gen_op_iwmmxt_movq_M0_wRn(rd0);
2063 tmp = tcg_temp_new_i32();
2064 if (gen_iwmmxt_shift(insn, 0xff, tmp)) {
2065 tcg_temp_free_i32(tmp);
2068 switch ((insn >> 22) & 3) {
2070 gen_helper_iwmmxt_sllw(cpu_M0, cpu_env, cpu_M0, tmp);
2073 gen_helper_iwmmxt_slll(cpu_M0, cpu_env, cpu_M0, tmp);
2076 gen_helper_iwmmxt_sllq(cpu_M0, cpu_env, cpu_M0, tmp);
2079 tcg_temp_free_i32(tmp);
2080 gen_op_iwmmxt_movq_wRn_M0(wrd);
2081 gen_op_iwmmxt_set_mup();
2082 gen_op_iwmmxt_set_cup();
2084 case 0x304: case 0x704: case 0xb04: case 0xf04: /* WROR */
2085 case 0x314: case 0x714: case 0xb14: case 0xf14:
2086 if (((insn >> 22) & 3) == 0)
2088 wrd = (insn >> 12) & 0xf;
2089 rd0 = (insn >> 16) & 0xf;
2090 gen_op_iwmmxt_movq_M0_wRn(rd0);
2091 tmp = tcg_temp_new_i32();
2092 switch ((insn >> 22) & 3) {
2094 if (gen_iwmmxt_shift(insn, 0xf, tmp)) {
2095 tcg_temp_free_i32(tmp);
2098 gen_helper_iwmmxt_rorw(cpu_M0, cpu_env, cpu_M0, tmp);
2101 if (gen_iwmmxt_shift(insn, 0x1f, tmp)) {
2102 tcg_temp_free_i32(tmp);
2105 gen_helper_iwmmxt_rorl(cpu_M0, cpu_env, cpu_M0, tmp);
2108 if (gen_iwmmxt_shift(insn, 0x3f, tmp)) {
2109 tcg_temp_free_i32(tmp);
2112 gen_helper_iwmmxt_rorq(cpu_M0, cpu_env, cpu_M0, tmp);
2115 tcg_temp_free_i32(tmp);
2116 gen_op_iwmmxt_movq_wRn_M0(wrd);
2117 gen_op_iwmmxt_set_mup();
2118 gen_op_iwmmxt_set_cup();
2120 case 0x116: case 0x316: case 0x516: case 0x716: /* WMIN */
2121 case 0x916: case 0xb16: case 0xd16: case 0xf16:
2122 wrd = (insn >> 12) & 0xf;
2123 rd0 = (insn >> 16) & 0xf;
2124 rd1 = (insn >> 0) & 0xf;
2125 gen_op_iwmmxt_movq_M0_wRn(rd0);
2126 switch ((insn >> 22) & 3) {
2128 if (insn & (1 << 21))
2129 gen_op_iwmmxt_minsb_M0_wRn(rd1);
2131 gen_op_iwmmxt_minub_M0_wRn(rd1);
2134 if (insn & (1 << 21))
2135 gen_op_iwmmxt_minsw_M0_wRn(rd1);
2137 gen_op_iwmmxt_minuw_M0_wRn(rd1);
2140 if (insn & (1 << 21))
2141 gen_op_iwmmxt_minsl_M0_wRn(rd1);
2143 gen_op_iwmmxt_minul_M0_wRn(rd1);
2148 gen_op_iwmmxt_movq_wRn_M0(wrd);
2149 gen_op_iwmmxt_set_mup();
2151 case 0x016: case 0x216: case 0x416: case 0x616: /* WMAX */
2152 case 0x816: case 0xa16: case 0xc16: case 0xe16:
2153 wrd = (insn >> 12) & 0xf;
2154 rd0 = (insn >> 16) & 0xf;
2155 rd1 = (insn >> 0) & 0xf;
2156 gen_op_iwmmxt_movq_M0_wRn(rd0);
2157 switch ((insn >> 22) & 3) {
2159 if (insn & (1 << 21))
2160 gen_op_iwmmxt_maxsb_M0_wRn(rd1);
2162 gen_op_iwmmxt_maxub_M0_wRn(rd1);
2165 if (insn & (1 << 21))
2166 gen_op_iwmmxt_maxsw_M0_wRn(rd1);
2168 gen_op_iwmmxt_maxuw_M0_wRn(rd1);
2171 if (insn & (1 << 21))
2172 gen_op_iwmmxt_maxsl_M0_wRn(rd1);
2174 gen_op_iwmmxt_maxul_M0_wRn(rd1);
2179 gen_op_iwmmxt_movq_wRn_M0(wrd);
2180 gen_op_iwmmxt_set_mup();
2182 case 0x002: case 0x102: case 0x202: case 0x302: /* WALIGNI */
2183 case 0x402: case 0x502: case 0x602: case 0x702:
2184 wrd = (insn >> 12) & 0xf;
2185 rd0 = (insn >> 16) & 0xf;
2186 rd1 = (insn >> 0) & 0xf;
2187 gen_op_iwmmxt_movq_M0_wRn(rd0);
2188 tmp = tcg_const_i32((insn >> 20) & 3);
2189 iwmmxt_load_reg(cpu_V1, rd1);
2190 gen_helper_iwmmxt_align(cpu_M0, cpu_M0, cpu_V1, tmp);
2192 gen_op_iwmmxt_movq_wRn_M0(wrd);
2193 gen_op_iwmmxt_set_mup();
2195 case 0x01a: case 0x11a: case 0x21a: case 0x31a: /* WSUB */
2196 case 0x41a: case 0x51a: case 0x61a: case 0x71a:
2197 case 0x81a: case 0x91a: case 0xa1a: case 0xb1a:
2198 case 0xc1a: case 0xd1a: case 0xe1a: case 0xf1a:
2199 wrd = (insn >> 12) & 0xf;
2200 rd0 = (insn >> 16) & 0xf;
2201 rd1 = (insn >> 0) & 0xf;
2202 gen_op_iwmmxt_movq_M0_wRn(rd0);
2203 switch ((insn >> 20) & 0xf) {
2205 gen_op_iwmmxt_subnb_M0_wRn(rd1);
2208 gen_op_iwmmxt_subub_M0_wRn(rd1);
2211 gen_op_iwmmxt_subsb_M0_wRn(rd1);
2214 gen_op_iwmmxt_subnw_M0_wRn(rd1);
2217 gen_op_iwmmxt_subuw_M0_wRn(rd1);
2220 gen_op_iwmmxt_subsw_M0_wRn(rd1);
2223 gen_op_iwmmxt_subnl_M0_wRn(rd1);
2226 gen_op_iwmmxt_subul_M0_wRn(rd1);
2229 gen_op_iwmmxt_subsl_M0_wRn(rd1);
2234 gen_op_iwmmxt_movq_wRn_M0(wrd);
2235 gen_op_iwmmxt_set_mup();
2236 gen_op_iwmmxt_set_cup();
2238 case 0x01e: case 0x11e: case 0x21e: case 0x31e: /* WSHUFH */
2239 case 0x41e: case 0x51e: case 0x61e: case 0x71e:
2240 case 0x81e: case 0x91e: case 0xa1e: case 0xb1e:
2241 case 0xc1e: case 0xd1e: case 0xe1e: case 0xf1e:
2242 wrd = (insn >> 12) & 0xf;
2243 rd0 = (insn >> 16) & 0xf;
2244 gen_op_iwmmxt_movq_M0_wRn(rd0);
2245 tmp = tcg_const_i32(((insn >> 16) & 0xf0) | (insn & 0x0f));
2246 gen_helper_iwmmxt_shufh(cpu_M0, cpu_env, cpu_M0, tmp);
2248 gen_op_iwmmxt_movq_wRn_M0(wrd);
2249 gen_op_iwmmxt_set_mup();
2250 gen_op_iwmmxt_set_cup();
2252 case 0x018: case 0x118: case 0x218: case 0x318: /* WADD */
2253 case 0x418: case 0x518: case 0x618: case 0x718:
2254 case 0x818: case 0x918: case 0xa18: case 0xb18:
2255 case 0xc18: case 0xd18: case 0xe18: case 0xf18:
2256 wrd = (insn >> 12) & 0xf;
2257 rd0 = (insn >> 16) & 0xf;
2258 rd1 = (insn >> 0) & 0xf;
2259 gen_op_iwmmxt_movq_M0_wRn(rd0);
2260 switch ((insn >> 20) & 0xf) {
2262 gen_op_iwmmxt_addnb_M0_wRn(rd1);
2265 gen_op_iwmmxt_addub_M0_wRn(rd1);
2268 gen_op_iwmmxt_addsb_M0_wRn(rd1);
2271 gen_op_iwmmxt_addnw_M0_wRn(rd1);
2274 gen_op_iwmmxt_adduw_M0_wRn(rd1);
2277 gen_op_iwmmxt_addsw_M0_wRn(rd1);
2280 gen_op_iwmmxt_addnl_M0_wRn(rd1);
2283 gen_op_iwmmxt_addul_M0_wRn(rd1);
2286 gen_op_iwmmxt_addsl_M0_wRn(rd1);
2291 gen_op_iwmmxt_movq_wRn_M0(wrd);
2292 gen_op_iwmmxt_set_mup();
2293 gen_op_iwmmxt_set_cup();
2295 case 0x008: case 0x108: case 0x208: case 0x308: /* WPACK */
2296 case 0x408: case 0x508: case 0x608: case 0x708:
2297 case 0x808: case 0x908: case 0xa08: case 0xb08:
2298 case 0xc08: case 0xd08: case 0xe08: case 0xf08:
2299 if (!(insn & (1 << 20)) || ((insn >> 22) & 3) == 0)
2301 wrd = (insn >> 12) & 0xf;
2302 rd0 = (insn >> 16) & 0xf;
2303 rd1 = (insn >> 0) & 0xf;
2304 gen_op_iwmmxt_movq_M0_wRn(rd0);
2305 switch ((insn >> 22) & 3) {
2307 if (insn & (1 << 21))
2308 gen_op_iwmmxt_packsw_M0_wRn(rd1);
2310 gen_op_iwmmxt_packuw_M0_wRn(rd1);
2313 if (insn & (1 << 21))
2314 gen_op_iwmmxt_packsl_M0_wRn(rd1);
2316 gen_op_iwmmxt_packul_M0_wRn(rd1);
2319 if (insn & (1 << 21))
2320 gen_op_iwmmxt_packsq_M0_wRn(rd1);
2322 gen_op_iwmmxt_packuq_M0_wRn(rd1);
2325 gen_op_iwmmxt_movq_wRn_M0(wrd);
2326 gen_op_iwmmxt_set_mup();
2327 gen_op_iwmmxt_set_cup();
2329 case 0x201: case 0x203: case 0x205: case 0x207:
2330 case 0x209: case 0x20b: case 0x20d: case 0x20f:
2331 case 0x211: case 0x213: case 0x215: case 0x217:
2332 case 0x219: case 0x21b: case 0x21d: case 0x21f:
2333 wrd = (insn >> 5) & 0xf;
2334 rd0 = (insn >> 12) & 0xf;
2335 rd1 = (insn >> 0) & 0xf;
2336 if (rd0 == 0xf || rd1 == 0xf)
2338 gen_op_iwmmxt_movq_M0_wRn(wrd);
2339 tmp = load_reg(s, rd0);
2340 tmp2 = load_reg(s, rd1);
2341 switch ((insn >> 16) & 0xf) {
2342 case 0x0: /* TMIA */
2343 gen_helper_iwmmxt_muladdsl(cpu_M0, cpu_M0, tmp, tmp2);
2345 case 0x8: /* TMIAPH */
2346 gen_helper_iwmmxt_muladdsw(cpu_M0, cpu_M0, tmp, tmp2);
2348 case 0xc: case 0xd: case 0xe: case 0xf: /* TMIAxy */
2349 if (insn & (1 << 16))
2350 tcg_gen_shri_i32(tmp, tmp, 16);
2351 if (insn & (1 << 17))
2352 tcg_gen_shri_i32(tmp2, tmp2, 16);
2353 gen_helper_iwmmxt_muladdswl(cpu_M0, cpu_M0, tmp, tmp2);
2356 tcg_temp_free_i32(tmp2);
2357 tcg_temp_free_i32(tmp);
2360 tcg_temp_free_i32(tmp2);
2361 tcg_temp_free_i32(tmp);
2362 gen_op_iwmmxt_movq_wRn_M0(wrd);
2363 gen_op_iwmmxt_set_mup();
2372 /* Disassemble an XScale DSP instruction. Returns nonzero if an error occurred
2373 (ie. an undefined instruction). */
2374 static int disas_dsp_insn(CPUState *env, DisasContext *s, uint32_t insn)
2376 int acc, rd0, rd1, rdhi, rdlo;
2379 if ((insn & 0x0ff00f10) == 0x0e200010) {
2380 /* Multiply with Internal Accumulate Format */
2381 rd0 = (insn >> 12) & 0xf;
2383 acc = (insn >> 5) & 7;
2388 tmp = load_reg(s, rd0);
2389 tmp2 = load_reg(s, rd1);
2390 switch ((insn >> 16) & 0xf) {
2392 gen_helper_iwmmxt_muladdsl(cpu_M0, cpu_M0, tmp, tmp2);
2394 case 0x8: /* MIAPH */
2395 gen_helper_iwmmxt_muladdsw(cpu_M0, cpu_M0, tmp, tmp2);
2397 case 0xc: /* MIABB */
2398 case 0xd: /* MIABT */
2399 case 0xe: /* MIATB */
2400 case 0xf: /* MIATT */
2401 if (insn & (1 << 16))
2402 tcg_gen_shri_i32(tmp, tmp, 16);
2403 if (insn & (1 << 17))
2404 tcg_gen_shri_i32(tmp2, tmp2, 16);
2405 gen_helper_iwmmxt_muladdswl(cpu_M0, cpu_M0, tmp, tmp2);
2410 tcg_temp_free_i32(tmp2);
2411 tcg_temp_free_i32(tmp);
2413 gen_op_iwmmxt_movq_wRn_M0(acc);
2417 if ((insn & 0x0fe00ff8) == 0x0c400000) {
2418 /* Internal Accumulator Access Format */
2419 rdhi = (insn >> 16) & 0xf;
2420 rdlo = (insn >> 12) & 0xf;
2426 if (insn & ARM_CP_RW_BIT) { /* MRA */
2427 iwmmxt_load_reg(cpu_V0, acc);
2428 tcg_gen_trunc_i64_i32(cpu_R[rdlo], cpu_V0);
2429 tcg_gen_shri_i64(cpu_V0, cpu_V0, 32);
2430 tcg_gen_trunc_i64_i32(cpu_R[rdhi], cpu_V0);
2431 tcg_gen_andi_i32(cpu_R[rdhi], cpu_R[rdhi], (1 << (40 - 32)) - 1);
2433 tcg_gen_concat_i32_i64(cpu_V0, cpu_R[rdlo], cpu_R[rdhi]);
2434 iwmmxt_store_reg(cpu_V0, acc);
2442 /* Disassemble system coprocessor instruction. Return nonzero if
2443 instruction is not defined. */
2444 static int disas_cp_insn(CPUState *env, DisasContext *s, uint32_t insn)
2447 uint32_t rd = (insn >> 12) & 0xf;
2448 uint32_t cp = (insn >> 8) & 0xf;
2453 if (insn & ARM_CP_RW_BIT) {
2454 if (!env->cp[cp].cp_read)
2456 gen_set_pc_im(s->pc);
2457 tmp = tcg_temp_new_i32();
2458 tmp2 = tcg_const_i32(insn);
2459 gen_helper_get_cp(tmp, cpu_env, tmp2);
2460 tcg_temp_free(tmp2);
2461 store_reg(s, rd, tmp);
2463 if (!env->cp[cp].cp_write)
2465 gen_set_pc_im(s->pc);
2466 tmp = load_reg(s, rd);
2467 tmp2 = tcg_const_i32(insn);
2468 gen_helper_set_cp(cpu_env, tmp2, tmp);
2469 tcg_temp_free(tmp2);
2470 tcg_temp_free_i32(tmp);
2475 static int cp15_user_ok(uint32_t insn)
2477 int cpn = (insn >> 16) & 0xf;
2478 int cpm = insn & 0xf;
2479 int op = ((insn >> 5) & 7) | ((insn >> 18) & 0x38);
2481 if (cpn == 13 && cpm == 0) {
2483 if (op == 2 || (op == 3 && (insn & ARM_CP_RW_BIT)))
2487 /* ISB, DSB, DMB. */
2488 if ((cpm == 5 && op == 4)
2489 || (cpm == 10 && (op == 4 || op == 5)))
2495 static int cp15_tls_load_store(CPUState *env, DisasContext *s, uint32_t insn, uint32_t rd)
2498 int cpn = (insn >> 16) & 0xf;
2499 int cpm = insn & 0xf;
2500 int op = ((insn >> 5) & 7) | ((insn >> 18) & 0x38);
2502 if (!arm_feature(env, ARM_FEATURE_V6K))
2505 if (!(cpn == 13 && cpm == 0))
2508 if (insn & ARM_CP_RW_BIT) {
2511 tmp = load_cpu_field(cp15.c13_tls1);
2514 tmp = load_cpu_field(cp15.c13_tls2);
2517 tmp = load_cpu_field(cp15.c13_tls3);
2522 store_reg(s, rd, tmp);
2525 tmp = load_reg(s, rd);
2528 store_cpu_field(tmp, cp15.c13_tls1);
2531 store_cpu_field(tmp, cp15.c13_tls2);
2534 store_cpu_field(tmp, cp15.c13_tls3);
2537 tcg_temp_free_i32(tmp);
2544 /* Disassemble system coprocessor (cp15) instruction. Return nonzero if
2545 instruction is not defined. */
2546 static int disas_cp15_insn(CPUState *env, DisasContext *s, uint32_t insn)
2551 /* M profile cores use memory mapped registers instead of cp15. */
2552 if (arm_feature(env, ARM_FEATURE_M))
2555 if ((insn & (1 << 25)) == 0) {
2556 if (insn & (1 << 20)) {
2560 /* mcrr. Used for block cache operations, so implement as no-op. */
2563 if ((insn & (1 << 4)) == 0) {
2567 if (IS_USER(s) && !cp15_user_ok(insn)) {
2571 /* Pre-v7 versions of the architecture implemented WFI via coprocessor
2572 * instructions rather than a separate instruction.
2574 if ((insn & 0x0fff0fff) == 0x0e070f90) {
2575 /* 0,c7,c0,4: Standard v6 WFI (also used in some pre-v6 cores).
2576 * In v7, this must NOP.
2578 if (!arm_feature(env, ARM_FEATURE_V7)) {
2579 /* Wait for interrupt. */
2580 gen_set_pc_im(s->pc);
2581 s->is_jmp = DISAS_WFI;
2586 if ((insn & 0x0fff0fff) == 0x0e070f58) {
2587 /* 0,c7,c8,2: Not all pre-v6 cores implemented this WFI,
2588 * so this is slightly over-broad.
2590 if (!arm_feature(env, ARM_FEATURE_V6)) {
2591 /* Wait for interrupt. */
2592 gen_set_pc_im(s->pc);
2593 s->is_jmp = DISAS_WFI;
2596 /* Otherwise fall through to handle via helper function.
2597 * In particular, on v7 and some v6 cores this is one of
2598 * the VA-PA registers.
2602 rd = (insn >> 12) & 0xf;
2604 if (cp15_tls_load_store(env, s, insn, rd))
2607 tmp2 = tcg_const_i32(insn);
2608 if (insn & ARM_CP_RW_BIT) {
2609 tmp = tcg_temp_new_i32();
2610 gen_helper_get_cp15(tmp, cpu_env, tmp2);
2611 /* If the destination register is r15 then sets condition codes. */
2613 store_reg(s, rd, tmp);
2615 tcg_temp_free_i32(tmp);
2617 tmp = load_reg(s, rd);
2618 gen_helper_set_cp15(cpu_env, tmp2, tmp);
2619 tcg_temp_free_i32(tmp);
2620 /* Normally we would always end the TB here, but Linux
2621 * arch/arm/mach-pxa/sleep.S expects two instructions following
2622 * an MMU enable to execute from cache. Imitate this behaviour. */
2623 if (!arm_feature(env, ARM_FEATURE_XSCALE) ||
2624 (insn & 0x0fff0fff) != 0x0e010f10)
2627 tcg_temp_free_i32(tmp2);
2631 #define VFP_REG_SHR(x, n) (((n) > 0) ? (x) >> (n) : (x) << -(n))
2632 #define VFP_SREG(insn, bigbit, smallbit) \
2633 ((VFP_REG_SHR(insn, bigbit - 1) & 0x1e) | (((insn) >> (smallbit)) & 1))
2634 #define VFP_DREG(reg, insn, bigbit, smallbit) do { \
2635 if (arm_feature(env, ARM_FEATURE_VFP3)) { \
2636 reg = (((insn) >> (bigbit)) & 0x0f) \
2637 | (((insn) >> ((smallbit) - 4)) & 0x10); \
2639 if (insn & (1 << (smallbit))) \
2641 reg = ((insn) >> (bigbit)) & 0x0f; \
2644 #define VFP_SREG_D(insn) VFP_SREG(insn, 12, 22)
2645 #define VFP_DREG_D(reg, insn) VFP_DREG(reg, insn, 12, 22)
2646 #define VFP_SREG_N(insn) VFP_SREG(insn, 16, 7)
2647 #define VFP_DREG_N(reg, insn) VFP_DREG(reg, insn, 16, 7)
2648 #define VFP_SREG_M(insn) VFP_SREG(insn, 0, 5)
2649 #define VFP_DREG_M(reg, insn) VFP_DREG(reg, insn, 0, 5)
2651 /* Move between integer and VFP cores. */
2652 static TCGv gen_vfp_mrs(void)
2654 TCGv tmp = tcg_temp_new_i32();
2655 tcg_gen_mov_i32(tmp, cpu_F0s);
2659 static void gen_vfp_msr(TCGv tmp)
2661 tcg_gen_mov_i32(cpu_F0s, tmp);
2662 tcg_temp_free_i32(tmp);
2665 static void gen_neon_dup_u8(TCGv var, int shift)
2667 TCGv tmp = tcg_temp_new_i32();
2669 tcg_gen_shri_i32(var, var, shift);
2670 tcg_gen_ext8u_i32(var, var);
2671 tcg_gen_shli_i32(tmp, var, 8);
2672 tcg_gen_or_i32(var, var, tmp);
2673 tcg_gen_shli_i32(tmp, var, 16);
2674 tcg_gen_or_i32(var, var, tmp);
2675 tcg_temp_free_i32(tmp);
2678 static void gen_neon_dup_low16(TCGv var)
2680 TCGv tmp = tcg_temp_new_i32();
2681 tcg_gen_ext16u_i32(var, var);
2682 tcg_gen_shli_i32(tmp, var, 16);
2683 tcg_gen_or_i32(var, var, tmp);
2684 tcg_temp_free_i32(tmp);
2687 static void gen_neon_dup_high16(TCGv var)
2689 TCGv tmp = tcg_temp_new_i32();
2690 tcg_gen_andi_i32(var, var, 0xffff0000);
2691 tcg_gen_shri_i32(tmp, var, 16);
2692 tcg_gen_or_i32(var, var, tmp);
2693 tcg_temp_free_i32(tmp);
2696 static TCGv gen_load_and_replicate(DisasContext *s, TCGv addr, int size)
2698 /* Load a single Neon element and replicate into a 32 bit TCG reg */
2702 tmp = gen_ld8u(addr, IS_USER(s));
2703 gen_neon_dup_u8(tmp, 0);
2706 tmp = gen_ld16u(addr, IS_USER(s));
2707 gen_neon_dup_low16(tmp);
2710 tmp = gen_ld32(addr, IS_USER(s));
2712 default: /* Avoid compiler warnings. */
2718 /* Disassemble a VFP instruction. Returns nonzero if an error occurred
2719 (ie. an undefined instruction). */
2720 static int disas_vfp_insn(CPUState * env, DisasContext *s, uint32_t insn)
2722 uint32_t rd, rn, rm, op, i, n, offset, delta_d, delta_m, bank_mask;
2728 if (!arm_feature(env, ARM_FEATURE_VFP))
2731 if (!s->vfp_enabled) {
2732 /* VFP disabled. Only allow fmxr/fmrx to/from some control regs. */
2733 if ((insn & 0x0fe00fff) != 0x0ee00a10)
2735 rn = (insn >> 16) & 0xf;
2736 if (rn != ARM_VFP_FPSID && rn != ARM_VFP_FPEXC
2737 && rn != ARM_VFP_MVFR1 && rn != ARM_VFP_MVFR0)
2740 dp = ((insn & 0xf00) == 0xb00);
2741 switch ((insn >> 24) & 0xf) {
2743 if (insn & (1 << 4)) {
2744 /* single register transfer */
2745 rd = (insn >> 12) & 0xf;
2750 VFP_DREG_N(rn, insn);
2753 if (insn & 0x00c00060
2754 && !arm_feature(env, ARM_FEATURE_NEON))
2757 pass = (insn >> 21) & 1;
2758 if (insn & (1 << 22)) {
2760 offset = ((insn >> 5) & 3) * 8;
2761 } else if (insn & (1 << 5)) {
2763 offset = (insn & (1 << 6)) ? 16 : 0;
2768 if (insn & ARM_CP_RW_BIT) {
2770 tmp = neon_load_reg(rn, pass);
2774 tcg_gen_shri_i32(tmp, tmp, offset);
2775 if (insn & (1 << 23))
2781 if (insn & (1 << 23)) {
2783 tcg_gen_shri_i32(tmp, tmp, 16);
2789 tcg_gen_sari_i32(tmp, tmp, 16);
2798 store_reg(s, rd, tmp);
2801 tmp = load_reg(s, rd);
2802 if (insn & (1 << 23)) {
2805 gen_neon_dup_u8(tmp, 0);
2806 } else if (size == 1) {
2807 gen_neon_dup_low16(tmp);
2809 for (n = 0; n <= pass * 2; n++) {
2810 tmp2 = tcg_temp_new_i32();
2811 tcg_gen_mov_i32(tmp2, tmp);
2812 neon_store_reg(rn, n, tmp2);
2814 neon_store_reg(rn, n, tmp);
2819 tmp2 = neon_load_reg(rn, pass);
2820 gen_bfi(tmp, tmp2, tmp, offset, 0xff);
2821 tcg_temp_free_i32(tmp2);
2824 tmp2 = neon_load_reg(rn, pass);
2825 gen_bfi(tmp, tmp2, tmp, offset, 0xffff);
2826 tcg_temp_free_i32(tmp2);
2831 neon_store_reg(rn, pass, tmp);
2835 if ((insn & 0x6f) != 0x00)
2837 rn = VFP_SREG_N(insn);
2838 if (insn & ARM_CP_RW_BIT) {
2840 if (insn & (1 << 21)) {
2841 /* system register */
2846 /* VFP2 allows access to FSID from userspace.
2847 VFP3 restricts all id registers to privileged
2850 && arm_feature(env, ARM_FEATURE_VFP3))
2852 tmp = load_cpu_field(vfp.xregs[rn]);
2857 tmp = load_cpu_field(vfp.xregs[rn]);
2859 case ARM_VFP_FPINST:
2860 case ARM_VFP_FPINST2:
2861 /* Not present in VFP3. */
2863 || arm_feature(env, ARM_FEATURE_VFP3))
2865 tmp = load_cpu_field(vfp.xregs[rn]);
2869 tmp = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]);
2870 tcg_gen_andi_i32(tmp, tmp, 0xf0000000);
2872 tmp = tcg_temp_new_i32();
2873 gen_helper_vfp_get_fpscr(tmp, cpu_env);
2879 || !arm_feature(env, ARM_FEATURE_VFP3))
2881 tmp = load_cpu_field(vfp.xregs[rn]);
2887 gen_mov_F0_vreg(0, rn);
2888 tmp = gen_vfp_mrs();
2891 /* Set the 4 flag bits in the CPSR. */
2893 tcg_temp_free_i32(tmp);
2895 store_reg(s, rd, tmp);
2899 tmp = load_reg(s, rd);
2900 if (insn & (1 << 21)) {
2902 /* system register */
2907 /* Writes are ignored. */
2910 gen_helper_vfp_set_fpscr(cpu_env, tmp);
2911 tcg_temp_free_i32(tmp);
2917 /* TODO: VFP subarchitecture support.
2918 * For now, keep the EN bit only */
2919 tcg_gen_andi_i32(tmp, tmp, 1 << 30);
2920 store_cpu_field(tmp, vfp.xregs[rn]);
2923 case ARM_VFP_FPINST:
2924 case ARM_VFP_FPINST2:
2925 store_cpu_field(tmp, vfp.xregs[rn]);
2932 gen_mov_vreg_F0(0, rn);
2937 /* data processing */
2938 /* The opcode is in bits 23, 21, 20 and 6. */
2939 op = ((insn >> 20) & 8) | ((insn >> 19) & 6) | ((insn >> 6) & 1);
2943 rn = ((insn >> 15) & 0x1e) | ((insn >> 7) & 1);
2945 /* rn is register number */
2946 VFP_DREG_N(rn, insn);
2949 if (op == 15 && (rn == 15 || ((rn & 0x1c) == 0x18))) {
2950 /* Integer or single precision destination. */
2951 rd = VFP_SREG_D(insn);
2953 VFP_DREG_D(rd, insn);
2956 (((rn & 0x1c) == 0x10) || ((rn & 0x14) == 0x14))) {
2957 /* VCVT from int is always from S reg regardless of dp bit.
2958 * VCVT with immediate frac_bits has same format as SREG_M
2960 rm = VFP_SREG_M(insn);
2962 VFP_DREG_M(rm, insn);
2965 rn = VFP_SREG_N(insn);
2966 if (op == 15 && rn == 15) {
2967 /* Double precision destination. */
2968 VFP_DREG_D(rd, insn);
2970 rd = VFP_SREG_D(insn);
2972 /* NB that we implicitly rely on the encoding for the frac_bits
2973 * in VCVT of fixed to float being the same as that of an SREG_M
2975 rm = VFP_SREG_M(insn);
2978 veclen = s->vec_len;
2979 if (op == 15 && rn > 3)
2982 /* Shut up compiler warnings. */
2993 /* Figure out what type of vector operation this is. */
2994 if ((rd & bank_mask) == 0) {
2999 delta_d = (s->vec_stride >> 1) + 1;
3001 delta_d = s->vec_stride + 1;
3003 if ((rm & bank_mask) == 0) {
3004 /* mixed scalar/vector */
3013 /* Load the initial operands. */
3018 /* Integer source */
3019 gen_mov_F0_vreg(0, rm);
3024 gen_mov_F0_vreg(dp, rd);
3025 gen_mov_F1_vreg(dp, rm);
3029 /* Compare with zero */
3030 gen_mov_F0_vreg(dp, rd);
3041 /* Source and destination the same. */
3042 gen_mov_F0_vreg(dp, rd);
3045 /* One source operand. */
3046 gen_mov_F0_vreg(dp, rm);
3050 /* Two source operands. */
3051 gen_mov_F0_vreg(dp, rn);
3052 gen_mov_F1_vreg(dp, rm);
3056 /* Perform the calculation. */
3058 case 0: /* VMLA: fd + (fn * fm) */
3059 /* Note that order of inputs to the add matters for NaNs */
3061 gen_mov_F0_vreg(dp, rd);
3064 case 1: /* VMLS: fd + -(fn * fm) */
3067 gen_mov_F0_vreg(dp, rd);
3070 case 2: /* VNMLS: -fd + (fn * fm) */
3071 /* Note that it isn't valid to replace (-A + B) with (B - A)
3072 * or similar plausible looking simplifications
3073 * because this will give wrong results for NaNs.
3076 gen_mov_F0_vreg(dp, rd);
3080 case 3: /* VNMLA: -fd + -(fn * fm) */
3083 gen_mov_F0_vreg(dp, rd);
3087 case 4: /* mul: fn * fm */
3090 case 5: /* nmul: -(fn * fm) */
3094 case 6: /* add: fn + fm */
3097 case 7: /* sub: fn - fm */
3100 case 8: /* div: fn / fm */
3103 case 14: /* fconst */
3104 if (!arm_feature(env, ARM_FEATURE_VFP3))
3107 n = (insn << 12) & 0x80000000;
3108 i = ((insn >> 12) & 0x70) | (insn & 0xf);
3115 tcg_gen_movi_i64(cpu_F0d, ((uint64_t)n) << 32);
3122 tcg_gen_movi_i32(cpu_F0s, n);
3125 case 15: /* extension space */
3139 case 4: /* vcvtb.f32.f16 */
3140 if (!arm_feature(env, ARM_FEATURE_VFP_FP16))
3142 tmp = gen_vfp_mrs();
3143 tcg_gen_ext16u_i32(tmp, tmp);
3144 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s, tmp, cpu_env);
3145 tcg_temp_free_i32(tmp);
3147 case 5: /* vcvtt.f32.f16 */
3148 if (!arm_feature(env, ARM_FEATURE_VFP_FP16))
3150 tmp = gen_vfp_mrs();
3151 tcg_gen_shri_i32(tmp, tmp, 16);
3152 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s, tmp, cpu_env);
3153 tcg_temp_free_i32(tmp);
3155 case 6: /* vcvtb.f16.f32 */
3156 if (!arm_feature(env, ARM_FEATURE_VFP_FP16))
3158 tmp = tcg_temp_new_i32();
3159 gen_helper_vfp_fcvt_f32_to_f16(tmp, cpu_F0s, cpu_env);
3160 gen_mov_F0_vreg(0, rd);
3161 tmp2 = gen_vfp_mrs();
3162 tcg_gen_andi_i32(tmp2, tmp2, 0xffff0000);
3163 tcg_gen_or_i32(tmp, tmp, tmp2);
3164 tcg_temp_free_i32(tmp2);
3167 case 7: /* vcvtt.f16.f32 */
3168 if (!arm_feature(env, ARM_FEATURE_VFP_FP16))
3170 tmp = tcg_temp_new_i32();
3171 gen_helper_vfp_fcvt_f32_to_f16(tmp, cpu_F0s, cpu_env);
3172 tcg_gen_shli_i32(tmp, tmp, 16);
3173 gen_mov_F0_vreg(0, rd);
3174 tmp2 = gen_vfp_mrs();
3175 tcg_gen_ext16u_i32(tmp2, tmp2);
3176 tcg_gen_or_i32(tmp, tmp, tmp2);
3177 tcg_temp_free_i32(tmp2);
3189 case 11: /* cmpez */
3193 case 15: /* single<->double conversion */
3195 gen_helper_vfp_fcvtsd(cpu_F0s, cpu_F0d, cpu_env);
3197 gen_helper_vfp_fcvtds(cpu_F0d, cpu_F0s, cpu_env);
3199 case 16: /* fuito */
3200 gen_vfp_uito(dp, 0);
3202 case 17: /* fsito */
3203 gen_vfp_sito(dp, 0);
3205 case 20: /* fshto */
3206 if (!arm_feature(env, ARM_FEATURE_VFP3))
3208 gen_vfp_shto(dp, 16 - rm, 0);
3210 case 21: /* fslto */
3211 if (!arm_feature(env, ARM_FEATURE_VFP3))
3213 gen_vfp_slto(dp, 32 - rm, 0);
3215 case 22: /* fuhto */
3216 if (!arm_feature(env, ARM_FEATURE_VFP3))
3218 gen_vfp_uhto(dp, 16 - rm, 0);
3220 case 23: /* fulto */
3221 if (!arm_feature(env, ARM_FEATURE_VFP3))
3223 gen_vfp_ulto(dp, 32 - rm, 0);
3225 case 24: /* ftoui */
3226 gen_vfp_toui(dp, 0);
3228 case 25: /* ftouiz */
3229 gen_vfp_touiz(dp, 0);
3231 case 26: /* ftosi */
3232 gen_vfp_tosi(dp, 0);
3234 case 27: /* ftosiz */
3235 gen_vfp_tosiz(dp, 0);
3237 case 28: /* ftosh */
3238 if (!arm_feature(env, ARM_FEATURE_VFP3))
3240 gen_vfp_tosh(dp, 16 - rm, 0);
3242 case 29: /* ftosl */
3243 if (!arm_feature(env, ARM_FEATURE_VFP3))
3245 gen_vfp_tosl(dp, 32 - rm, 0);
3247 case 30: /* ftouh */
3248 if (!arm_feature(env, ARM_FEATURE_VFP3))
3250 gen_vfp_touh(dp, 16 - rm, 0);
3252 case 31: /* ftoul */
3253 if (!arm_feature(env, ARM_FEATURE_VFP3))
3255 gen_vfp_toul(dp, 32 - rm, 0);
3257 default: /* undefined */
3258 printf ("rn:%d\n", rn);
3262 default: /* undefined */
3263 printf ("op:%d\n", op);
3267 /* Write back the result. */
3268 if (op == 15 && (rn >= 8 && rn <= 11))
3269 ; /* Comparison, do nothing. */
3270 else if (op == 15 && dp && ((rn & 0x1c) == 0x18))
3271 /* VCVT double to int: always integer result. */
3272 gen_mov_vreg_F0(0, rd);
3273 else if (op == 15 && rn == 15)
3275 gen_mov_vreg_F0(!dp, rd);
3277 gen_mov_vreg_F0(dp, rd);
3279 /* break out of the loop if we have finished */
3283 if (op == 15 && delta_m == 0) {
3284 /* single source one-many */
3286 rd = ((rd + delta_d) & (bank_mask - 1))
3288 gen_mov_vreg_F0(dp, rd);
3292 /* Setup the next operands. */
3294 rd = ((rd + delta_d) & (bank_mask - 1))
3298 /* One source operand. */
3299 rm = ((rm + delta_m) & (bank_mask - 1))
3301 gen_mov_F0_vreg(dp, rm);
3303 /* Two source operands. */
3304 rn = ((rn + delta_d) & (bank_mask - 1))
3306 gen_mov_F0_vreg(dp, rn);
3308 rm = ((rm + delta_m) & (bank_mask - 1))
3310 gen_mov_F1_vreg(dp, rm);
3318 if ((insn & 0x03e00000) == 0x00400000) {
3319 /* two-register transfer */
3320 rn = (insn >> 16) & 0xf;
3321 rd = (insn >> 12) & 0xf;
3323 VFP_DREG_M(rm, insn);
3325 rm = VFP_SREG_M(insn);
3328 if (insn & ARM_CP_RW_BIT) {
3331 gen_mov_F0_vreg(0, rm * 2);
3332 tmp = gen_vfp_mrs();
3333 store_reg(s, rd, tmp);
3334 gen_mov_F0_vreg(0, rm * 2 + 1);
3335 tmp = gen_vfp_mrs();
3336 store_reg(s, rn, tmp);
3338 gen_mov_F0_vreg(0, rm);
3339 tmp = gen_vfp_mrs();
3340 store_reg(s, rd, tmp);
3341 gen_mov_F0_vreg(0, rm + 1);
3342 tmp = gen_vfp_mrs();
3343 store_reg(s, rn, tmp);
3348 tmp = load_reg(s, rd);
3350 gen_mov_vreg_F0(0, rm * 2);
3351 tmp = load_reg(s, rn);
3353 gen_mov_vreg_F0(0, rm * 2 + 1);
3355 tmp = load_reg(s, rd);
3357 gen_mov_vreg_F0(0, rm);
3358 tmp = load_reg(s, rn);
3360 gen_mov_vreg_F0(0, rm + 1);
3365 rn = (insn >> 16) & 0xf;
3367 VFP_DREG_D(rd, insn);
3369 rd = VFP_SREG_D(insn);
3370 if (s->thumb && rn == 15) {
3371 addr = tcg_temp_new_i32();
3372 tcg_gen_movi_i32(addr, s->pc & ~2);
3374 addr = load_reg(s, rn);
3376 if ((insn & 0x01200000) == 0x01000000) {
3377 /* Single load/store */
3378 offset = (insn & 0xff) << 2;
3379 if ((insn & (1 << 23)) == 0)
3381 tcg_gen_addi_i32(addr, addr, offset);
3382 if (insn & (1 << 20)) {
3383 gen_vfp_ld(s, dp, addr);
3384 gen_mov_vreg_F0(dp, rd);
3386 gen_mov_F0_vreg(dp, rd);
3387 gen_vfp_st(s, dp, addr);
3389 tcg_temp_free_i32(addr);
3391 /* load/store multiple */
3393 n = (insn >> 1) & 0x7f;
3397 if (insn & (1 << 24)) /* pre-decrement */
3398 tcg_gen_addi_i32(addr, addr, -((insn & 0xff) << 2));
3404 for (i = 0; i < n; i++) {
3405 if (insn & ARM_CP_RW_BIT) {
3407 gen_vfp_ld(s, dp, addr);
3408 gen_mov_vreg_F0(dp, rd + i);
3411 gen_mov_F0_vreg(dp, rd + i);
3412 gen_vfp_st(s, dp, addr);
3414 tcg_gen_addi_i32(addr, addr, offset);
3416 if (insn & (1 << 21)) {
3418 if (insn & (1 << 24))
3419 offset = -offset * n;
3420 else if (dp && (insn & 1))
3426 tcg_gen_addi_i32(addr, addr, offset);
3427 store_reg(s, rn, addr);
3429 tcg_temp_free_i32(addr);
3435 /* Should never happen. */
3441 static inline void gen_goto_tb(DisasContext *s, int n, uint32_t dest)
3443 TranslationBlock *tb;
3446 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
3448 gen_set_pc_im(dest);
3449 tcg_gen_exit_tb((tcg_target_long)tb + n);
3451 gen_set_pc_im(dest);
3456 static inline void gen_jmp (DisasContext *s, uint32_t dest)
3458 if (unlikely(s->singlestep_enabled)) {
3459 /* An indirect jump so that we still trigger the debug exception. */
3464 gen_goto_tb(s, 0, dest);
3465 s->is_jmp = DISAS_TB_JUMP;
3469 static inline void gen_mulxy(TCGv t0, TCGv t1, int x, int y)
3472 tcg_gen_sari_i32(t0, t0, 16);
3476 tcg_gen_sari_i32(t1, t1, 16);
3479 tcg_gen_mul_i32(t0, t0, t1);
3482 /* Return the mask of PSR bits set by a MSR instruction. */
3483 static uint32_t msr_mask(CPUState *env, DisasContext *s, int flags, int spsr) {
3487 if (flags & (1 << 0))
3489 if (flags & (1 << 1))
3491 if (flags & (1 << 2))
3493 if (flags & (1 << 3))
3496 /* Mask out undefined bits. */
3497 mask &= ~CPSR_RESERVED;
3498 if (!arm_feature(env, ARM_FEATURE_V4T))
3500 if (!arm_feature(env, ARM_FEATURE_V5))
3501 mask &= ~CPSR_Q; /* V5TE in reality*/
3502 if (!arm_feature(env, ARM_FEATURE_V6))
3503 mask &= ~(CPSR_E | CPSR_GE);
3504 if (!arm_feature(env, ARM_FEATURE_THUMB2))
3506 /* Mask out execution state bits. */
3509 /* Mask out privileged bits. */
3515 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
3516 static int gen_set_psr(DisasContext *s, uint32_t mask, int spsr, TCGv t0)
3520 /* ??? This is also undefined in system mode. */
3524 tmp = load_cpu_field(spsr);
3525 tcg_gen_andi_i32(tmp, tmp, ~mask);
3526 tcg_gen_andi_i32(t0, t0, mask);
3527 tcg_gen_or_i32(tmp, tmp, t0);
3528 store_cpu_field(tmp, spsr);
3530 gen_set_cpsr(t0, mask);
3532 tcg_temp_free_i32(t0);
3537 /* Returns nonzero if access to the PSR is not permitted. */
3538 static int gen_set_psr_im(DisasContext *s, uint32_t mask, int spsr, uint32_t val)
3541 tmp = tcg_temp_new_i32();
3542 tcg_gen_movi_i32(tmp, val);
3543 return gen_set_psr(s, mask, spsr, tmp);
3546 /* Generate an old-style exception return. Marks pc as dead. */
3547 static void gen_exception_return(DisasContext *s, TCGv pc)
3550 store_reg(s, 15, pc);
3551 tmp = load_cpu_field(spsr);
3552 gen_set_cpsr(tmp, 0xffffffff);
3553 tcg_temp_free_i32(tmp);
3554 s->is_jmp = DISAS_UPDATE;
3557 /* Generate a v6 exception return. Marks both values as dead. */
3558 static void gen_rfe(DisasContext *s, TCGv pc, TCGv cpsr)
3560 gen_set_cpsr(cpsr, 0xffffffff);
3561 tcg_temp_free_i32(cpsr);
3562 store_reg(s, 15, pc);
3563 s->is_jmp = DISAS_UPDATE;
3567 gen_set_condexec (DisasContext *s)
3569 if (s->condexec_mask) {
3570 uint32_t val = (s->condexec_cond << 4) | (s->condexec_mask >> 1);
3571 TCGv tmp = tcg_temp_new_i32();
3572 tcg_gen_movi_i32(tmp, val);
3573 store_cpu_field(tmp, condexec_bits);
3577 static void gen_exception_insn(DisasContext *s, int offset, int excp)
3579 gen_set_condexec(s);
3580 gen_set_pc_im(s->pc - offset);
3581 gen_exception(excp);
3582 s->is_jmp = DISAS_JUMP;
3585 static void gen_nop_hint(DisasContext *s, int val)
3589 gen_set_pc_im(s->pc);
3590 s->is_jmp = DISAS_WFI;
3594 /* TODO: Implement SEV and WFE. May help SMP performance. */
3600 #define CPU_V001 cpu_V0, cpu_V0, cpu_V1
3602 static inline void gen_neon_add(int size, TCGv t0, TCGv t1)
3605 case 0: gen_helper_neon_add_u8(t0, t0, t1); break;
3606 case 1: gen_helper_neon_add_u16(t0, t0, t1); break;
3607 case 2: tcg_gen_add_i32(t0, t0, t1); break;
3612 static inline void gen_neon_rsb(int size, TCGv t0, TCGv t1)
3615 case 0: gen_helper_neon_sub_u8(t0, t1, t0); break;
3616 case 1: gen_helper_neon_sub_u16(t0, t1, t0); break;
3617 case 2: tcg_gen_sub_i32(t0, t1, t0); break;
3622 /* 32-bit pairwise ops end up the same as the elementwise versions. */
3623 #define gen_helper_neon_pmax_s32 gen_helper_neon_max_s32
3624 #define gen_helper_neon_pmax_u32 gen_helper_neon_max_u32
3625 #define gen_helper_neon_pmin_s32 gen_helper_neon_min_s32
3626 #define gen_helper_neon_pmin_u32 gen_helper_neon_min_u32
3628 #define GEN_NEON_INTEGER_OP_ENV(name) do { \
3629 switch ((size << 1) | u) { \
3631 gen_helper_neon_##name##_s8(tmp, cpu_env, tmp, tmp2); \
3634 gen_helper_neon_##name##_u8(tmp, cpu_env, tmp, tmp2); \
3637 gen_helper_neon_##name##_s16(tmp, cpu_env, tmp, tmp2); \
3640 gen_helper_neon_##name##_u16(tmp, cpu_env, tmp, tmp2); \
3643 gen_helper_neon_##name##_s32(tmp, cpu_env, tmp, tmp2); \
3646 gen_helper_neon_##name##_u32(tmp, cpu_env, tmp, tmp2); \
3648 default: return 1; \
3651 #define GEN_NEON_INTEGER_OP(name) do { \
3652 switch ((size << 1) | u) { \
3654 gen_helper_neon_##name##_s8(tmp, tmp, tmp2); \
3657 gen_helper_neon_##name##_u8(tmp, tmp, tmp2); \
3660 gen_helper_neon_##name##_s16(tmp, tmp, tmp2); \
3663 gen_helper_neon_##name##_u16(tmp, tmp, tmp2); \
3666 gen_helper_neon_##name##_s32(tmp, tmp, tmp2); \
3669 gen_helper_neon_##name##_u32(tmp, tmp, tmp2); \
3671 default: return 1; \
3674 static TCGv neon_load_scratch(int scratch)
3676 TCGv tmp = tcg_temp_new_i32();
3677 tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, vfp.scratch[scratch]));
3681 static void neon_store_scratch(int scratch, TCGv var)
3683 tcg_gen_st_i32(var, cpu_env, offsetof(CPUARMState, vfp.scratch[scratch]));
3684 tcg_temp_free_i32(var);
3687 static inline TCGv neon_get_scalar(int size, int reg)
3691 tmp = neon_load_reg(reg & 7, reg >> 4);
3693 gen_neon_dup_high16(tmp);
3695 gen_neon_dup_low16(tmp);
3698 tmp = neon_load_reg(reg & 15, reg >> 4);
3703 static int gen_neon_unzip(int rd, int rm, int size, int q)
3706 if (!q && size == 2) {
3709 tmp = tcg_const_i32(rd);
3710 tmp2 = tcg_const_i32(rm);
3714 gen_helper_neon_qunzip8(tmp, tmp2);
3717 gen_helper_neon_qunzip16(tmp, tmp2);
3720 gen_helper_neon_qunzip32(tmp, tmp2);
3728 gen_helper_neon_unzip8(tmp, tmp2);
3731 gen_helper_neon_unzip16(tmp, tmp2);
3737 tcg_temp_free_i32(tmp);
3738 tcg_temp_free_i32(tmp2);
3742 static int gen_neon_zip(int rd, int rm, int size, int q)
3745 if (!q && size == 2) {
3748 tmp = tcg_const_i32(rd);
3749 tmp2 = tcg_const_i32(rm);
3753 gen_helper_neon_qzip8(tmp, tmp2);
3756 gen_helper_neon_qzip16(tmp, tmp2);
3759 gen_helper_neon_qzip32(tmp, tmp2);
3767 gen_helper_neon_zip8(tmp, tmp2);
3770 gen_helper_neon_zip16(tmp, tmp2);
3776 tcg_temp_free_i32(tmp);
3777 tcg_temp_free_i32(tmp2);
3781 static void gen_neon_trn_u8(TCGv t0, TCGv t1)
3785 rd = tcg_temp_new_i32();
3786 tmp = tcg_temp_new_i32();
3788 tcg_gen_shli_i32(rd, t0, 8);
3789 tcg_gen_andi_i32(rd, rd, 0xff00ff00);
3790 tcg_gen_andi_i32(tmp, t1, 0x00ff00ff);
3791 tcg_gen_or_i32(rd, rd, tmp);
3793 tcg_gen_shri_i32(t1, t1, 8);
3794 tcg_gen_andi_i32(t1, t1, 0x00ff00ff);
3795 tcg_gen_andi_i32(tmp, t0, 0xff00ff00);
3796 tcg_gen_or_i32(t1, t1, tmp);
3797 tcg_gen_mov_i32(t0, rd);
3799 tcg_temp_free_i32(tmp);
3800 tcg_temp_free_i32(rd);
3803 static void gen_neon_trn_u16(TCGv t0, TCGv t1)
3807 rd = tcg_temp_new_i32();
3808 tmp = tcg_temp_new_i32();
3810 tcg_gen_shli_i32(rd, t0, 16);
3811 tcg_gen_andi_i32(tmp, t1, 0xffff);
3812 tcg_gen_or_i32(rd, rd, tmp);
3813 tcg_gen_shri_i32(t1, t1, 16);
3814 tcg_gen_andi_i32(tmp, t0, 0xffff0000);
3815 tcg_gen_or_i32(t1, t1, tmp);
3816 tcg_gen_mov_i32(t0, rd);
3818 tcg_temp_free_i32(tmp);
3819 tcg_temp_free_i32(rd);
3827 } neon_ls_element_type[11] = {
3841 /* Translate a NEON load/store element instruction. Return nonzero if the
3842 instruction is invalid. */
3843 static int disas_neon_ls_insn(CPUState * env, DisasContext *s, uint32_t insn)
3862 if (!s->vfp_enabled)
3864 VFP_DREG_D(rd, insn);
3865 rn = (insn >> 16) & 0xf;
3867 load = (insn & (1 << 21)) != 0;
3868 if ((insn & (1 << 23)) == 0) {
3869 /* Load store all elements. */
3870 op = (insn >> 8) & 0xf;
3871 size = (insn >> 6) & 3;
3874 /* Catch UNDEF cases for bad values of align field */
3877 if (((insn >> 5) & 1) == 1) {
3882 if (((insn >> 4) & 3) == 3) {
3889 nregs = neon_ls_element_type[op].nregs;
3890 interleave = neon_ls_element_type[op].interleave;
3891 spacing = neon_ls_element_type[op].spacing;
3892 if (size == 3 && (interleave | spacing) != 1)
3894 addr = tcg_temp_new_i32();
3895 load_reg_var(s, addr, rn);
3896 stride = (1 << size) * interleave;
3897 for (reg = 0; reg < nregs; reg++) {
3898 if (interleave > 2 || (interleave == 2 && nregs == 2)) {
3899 load_reg_var(s, addr, rn);
3900 tcg_gen_addi_i32(addr, addr, (1 << size) * reg);
3901 } else if (interleave == 2 && nregs == 4 && reg == 2) {
3902 load_reg_var(s, addr, rn);
3903 tcg_gen_addi_i32(addr, addr, 1 << size);
3907 tmp64 = gen_ld64(addr, IS_USER(s));
3908 neon_store_reg64(tmp64, rd);
3909 tcg_temp_free_i64(tmp64);
3911 tmp64 = tcg_temp_new_i64();
3912 neon_load_reg64(tmp64, rd);
3913 gen_st64(tmp64, addr, IS_USER(s));
3915 tcg_gen_addi_i32(addr, addr, stride);
3917 for (pass = 0; pass < 2; pass++) {
3920 tmp = gen_ld32(addr, IS_USER(s));
3921 neon_store_reg(rd, pass, tmp);
3923 tmp = neon_load_reg(rd, pass);
3924 gen_st32(tmp, addr, IS_USER(s));
3926 tcg_gen_addi_i32(addr, addr, stride);
3927 } else if (size == 1) {
3929 tmp = gen_ld16u(addr, IS_USER(s));
3930 tcg_gen_addi_i32(addr, addr, stride);
3931 tmp2 = gen_ld16u(addr, IS_USER(s));
3932 tcg_gen_addi_i32(addr, addr, stride);
3933 tcg_gen_shli_i32(tmp2, tmp2, 16);
3934 tcg_gen_or_i32(tmp, tmp, tmp2);
3935 tcg_temp_free_i32(tmp2);
3936 neon_store_reg(rd, pass, tmp);
3938 tmp = neon_load_reg(rd, pass);
3939 tmp2 = tcg_temp_new_i32();
3940 tcg_gen_shri_i32(tmp2, tmp, 16);
3941 gen_st16(tmp, addr, IS_USER(s));
3942 tcg_gen_addi_i32(addr, addr, stride);
3943 gen_st16(tmp2, addr, IS_USER(s));
3944 tcg_gen_addi_i32(addr, addr, stride);
3946 } else /* size == 0 */ {
3949 for (n = 0; n < 4; n++) {
3950 tmp = gen_ld8u(addr, IS_USER(s));
3951 tcg_gen_addi_i32(addr, addr, stride);
3955 tcg_gen_shli_i32(tmp, tmp, n * 8);
3956 tcg_gen_or_i32(tmp2, tmp2, tmp);
3957 tcg_temp_free_i32(tmp);
3960 neon_store_reg(rd, pass, tmp2);
3962 tmp2 = neon_load_reg(rd, pass);
3963 for (n = 0; n < 4; n++) {
3964 tmp = tcg_temp_new_i32();
3966 tcg_gen_mov_i32(tmp, tmp2);
3968 tcg_gen_shri_i32(tmp, tmp2, n * 8);
3970 gen_st8(tmp, addr, IS_USER(s));
3971 tcg_gen_addi_i32(addr, addr, stride);
3973 tcg_temp_free_i32(tmp2);
3980 tcg_temp_free_i32(addr);
3983 size = (insn >> 10) & 3;
3985 /* Load single element to all lanes. */
3986 int a = (insn >> 4) & 1;
3990 size = (insn >> 6) & 3;
3991 nregs = ((insn >> 8) & 3) + 1;
3994 if (nregs != 4 || a == 0) {
3997 /* For VLD4 size==3 a == 1 means 32 bits at 16 byte alignment */
4000 if (nregs == 1 && a == 1 && size == 0) {
4003 if (nregs == 3 && a == 1) {
4006 addr = tcg_temp_new_i32();
4007 load_reg_var(s, addr, rn);
4009 /* VLD1 to all lanes: bit 5 indicates how many Dregs to write */
4010 tmp = gen_load_and_replicate(s, addr, size);
4011 tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 0));
4012 tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 1));
4013 if (insn & (1 << 5)) {
4014 tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd + 1, 0));
4015 tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd + 1, 1));
4017 tcg_temp_free_i32(tmp);
4019 /* VLD2/3/4 to all lanes: bit 5 indicates register stride */
4020 stride = (insn & (1 << 5)) ? 2 : 1;
4021 for (reg = 0; reg < nregs; reg++) {
4022 tmp = gen_load_and_replicate(s, addr, size);
4023 tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 0));
4024 tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 1));
4025 tcg_temp_free_i32(tmp);
4026 tcg_gen_addi_i32(addr, addr, 1 << size);
4030 tcg_temp_free_i32(addr);
4031 stride = (1 << size) * nregs;
4033 /* Single element. */
4034 int idx = (insn >> 4) & 0xf;
4035 pass = (insn >> 7) & 1;
4038 shift = ((insn >> 5) & 3) * 8;
4042 shift = ((insn >> 6) & 1) * 16;
4043 stride = (insn & (1 << 5)) ? 2 : 1;
4047 stride = (insn & (1 << 6)) ? 2 : 1;
4052 nregs = ((insn >> 8) & 3) + 1;
4053 /* Catch the UNDEF cases. This is unavoidably a bit messy. */
4056 if (((idx & (1 << size)) != 0) ||
4057 (size == 2 && ((idx & 3) == 1 || (idx & 3) == 2))) {
4062 if ((idx & 1) != 0) {
4067 if (size == 2 && (idx & 2) != 0) {
4072 if ((size == 2) && ((idx & 3) == 3)) {
4079 if ((rd + stride * (nregs - 1)) > 31) {
4080 /* Attempts to write off the end of the register file
4081 * are UNPREDICTABLE; we choose to UNDEF because otherwise
4082 * the neon_load_reg() would write off the end of the array.
4086 addr = tcg_temp_new_i32();
4087 load_reg_var(s, addr, rn);
4088 for (reg = 0; reg < nregs; reg++) {
4092 tmp = gen_ld8u(addr, IS_USER(s));
4095 tmp = gen_ld16u(addr, IS_USER(s));
4098 tmp = gen_ld32(addr, IS_USER(s));
4100 default: /* Avoid compiler warnings. */
4104 tmp2 = neon_load_reg(rd, pass);
4105 gen_bfi(tmp, tmp2, tmp, shift, size ? 0xffff : 0xff);
4106 tcg_temp_free_i32(tmp2);
4108 neon_store_reg(rd, pass, tmp);
4109 } else { /* Store */
4110 tmp = neon_load_reg(rd, pass);
4112 tcg_gen_shri_i32(tmp, tmp, shift);
4115 gen_st8(tmp, addr, IS_USER(s));
4118 gen_st16(tmp, addr, IS_USER(s));
4121 gen_st32(tmp, addr, IS_USER(s));
4126 tcg_gen_addi_i32(addr, addr, 1 << size);
4128 tcg_temp_free_i32(addr);
4129 stride = nregs * (1 << size);
4135 base = load_reg(s, rn);
4137 tcg_gen_addi_i32(base, base, stride);
4140 index = load_reg(s, rm);
4141 tcg_gen_add_i32(base, base, index);
4142 tcg_temp_free_i32(index);
4144 store_reg(s, rn, base);
4149 /* Bitwise select. dest = c ? t : f. Clobbers T and F. */
4150 static void gen_neon_bsl(TCGv dest, TCGv t, TCGv f, TCGv c)
4152 tcg_gen_and_i32(t, t, c);
4153 tcg_gen_andc_i32(f, f, c);
4154 tcg_gen_or_i32(dest, t, f);
4157 static inline void gen_neon_narrow(int size, TCGv dest, TCGv_i64 src)
4160 case 0: gen_helper_neon_narrow_u8(dest, src); break;
4161 case 1: gen_helper_neon_narrow_u16(dest, src); break;
4162 case 2: tcg_gen_trunc_i64_i32(dest, src); break;
4167 static inline void gen_neon_narrow_sats(int size, TCGv dest, TCGv_i64 src)
4170 case 0: gen_helper_neon_narrow_sat_s8(dest, src); break;
4171 case 1: gen_helper_neon_narrow_sat_s16(dest, src); break;
4172 case 2: gen_helper_neon_narrow_sat_s32(dest, src); break;
4177 static inline void gen_neon_narrow_satu(int size, TCGv dest, TCGv_i64 src)
4180 case 0: gen_helper_neon_narrow_sat_u8(dest, src); break;
4181 case 1: gen_helper_neon_narrow_sat_u16(dest, src); break;
4182 case 2: gen_helper_neon_narrow_sat_u32(dest, src); break;
4187 static inline void gen_neon_unarrow_sats(int size, TCGv dest, TCGv_i64 src)
4190 case 0: gen_helper_neon_unarrow_sat8(dest, src); break;
4191 case 1: gen_helper_neon_unarrow_sat16(dest, src); break;
4192 case 2: gen_helper_neon_unarrow_sat32(dest, src); break;
4197 static inline void gen_neon_shift_narrow(int size, TCGv var, TCGv shift,
4203 case 1: gen_helper_neon_rshl_u16(var, var, shift); break;
4204 case 2: gen_helper_neon_rshl_u32(var, var, shift); break;
4209 case 1: gen_helper_neon_rshl_s16(var, var, shift); break;
4210 case 2: gen_helper_neon_rshl_s32(var, var, shift); break;
4217 case 1: gen_helper_neon_shl_u16(var, var, shift); break;
4218 case 2: gen_helper_neon_shl_u32(var, var, shift); break;
4223 case 1: gen_helper_neon_shl_s16(var, var, shift); break;
4224 case 2: gen_helper_neon_shl_s32(var, var, shift); break;
4231 static inline void gen_neon_widen(TCGv_i64 dest, TCGv src, int size, int u)
4235 case 0: gen_helper_neon_widen_u8(dest, src); break;
4236 case 1: gen_helper_neon_widen_u16(dest, src); break;
4237 case 2: tcg_gen_extu_i32_i64(dest, src); break;
4242 case 0: gen_helper_neon_widen_s8(dest, src); break;
4243 case 1: gen_helper_neon_widen_s16(dest, src); break;
4244 case 2: tcg_gen_ext_i32_i64(dest, src); break;
4248 tcg_temp_free_i32(src);
4251 static inline void gen_neon_addl(int size)
4254 case 0: gen_helper_neon_addl_u16(CPU_V001); break;
4255 case 1: gen_helper_neon_addl_u32(CPU_V001); break;
4256 case 2: tcg_gen_add_i64(CPU_V001); break;
4261 static inline void gen_neon_subl(int size)
4264 case 0: gen_helper_neon_subl_u16(CPU_V001); break;
4265 case 1: gen_helper_neon_subl_u32(CPU_V001); break;
4266 case 2: tcg_gen_sub_i64(CPU_V001); break;
4271 static inline void gen_neon_negl(TCGv_i64 var, int size)
4274 case 0: gen_helper_neon_negl_u16(var, var); break;
4275 case 1: gen_helper_neon_negl_u32(var, var); break;
4276 case 2: gen_helper_neon_negl_u64(var, var); break;
4281 static inline void gen_neon_addl_saturate(TCGv_i64 op0, TCGv_i64 op1, int size)
4284 case 1: gen_helper_neon_addl_saturate_s32(op0, op0, op1); break;
4285 case 2: gen_helper_neon_addl_saturate_s64(op0, op0, op1); break;
4290 static inline void gen_neon_mull(TCGv_i64 dest, TCGv a, TCGv b, int size, int u)
4294 switch ((size << 1) | u) {
4295 case 0: gen_helper_neon_mull_s8(dest, a, b); break;
4296 case 1: gen_helper_neon_mull_u8(dest, a, b); break;
4297 case 2: gen_helper_neon_mull_s16(dest, a, b); break;
4298 case 3: gen_helper_neon_mull_u16(dest, a, b); break;
4300 tmp = gen_muls_i64_i32(a, b);
4301 tcg_gen_mov_i64(dest, tmp);
4302 tcg_temp_free_i64(tmp);
4305 tmp = gen_mulu_i64_i32(a, b);
4306 tcg_gen_mov_i64(dest, tmp);
4307 tcg_temp_free_i64(tmp);
4312 /* gen_helper_neon_mull_[su]{8|16} do not free their parameters.
4313 Don't forget to clean them now. */
4315 tcg_temp_free_i32(a);
4316 tcg_temp_free_i32(b);
4320 static void gen_neon_narrow_op(int op, int u, int size, TCGv dest, TCGv_i64 src)
4324 gen_neon_unarrow_sats(size, dest, src);
4326 gen_neon_narrow(size, dest, src);
4330 gen_neon_narrow_satu(size, dest, src);
4332 gen_neon_narrow_sats(size, dest, src);
4337 /* Symbolic constants for op fields for Neon 3-register same-length.
4338 * The values correspond to bits [11:8,4]; see the ARM ARM DDI0406B
4341 #define NEON_3R_VHADD 0
4342 #define NEON_3R_VQADD 1
4343 #define NEON_3R_VRHADD 2
4344 #define NEON_3R_LOGIC 3 /* VAND,VBIC,VORR,VMOV,VORN,VEOR,VBIF,VBIT,VBSL */
4345 #define NEON_3R_VHSUB 4
4346 #define NEON_3R_VQSUB 5
4347 #define NEON_3R_VCGT 6
4348 #define NEON_3R_VCGE 7
4349 #define NEON_3R_VSHL 8
4350 #define NEON_3R_VQSHL 9
4351 #define NEON_3R_VRSHL 10
4352 #define NEON_3R_VQRSHL 11
4353 #define NEON_3R_VMAX 12
4354 #define NEON_3R_VMIN 13
4355 #define NEON_3R_VABD 14
4356 #define NEON_3R_VABA 15
4357 #define NEON_3R_VADD_VSUB 16
4358 #define NEON_3R_VTST_VCEQ 17
4359 #define NEON_3R_VML 18 /* VMLA, VMLAL, VMLS, VMLSL */
4360 #define NEON_3R_VMUL 19
4361 #define NEON_3R_VPMAX 20
4362 #define NEON_3R_VPMIN 21
4363 #define NEON_3R_VQDMULH_VQRDMULH 22
4364 #define NEON_3R_VPADD 23
4365 #define NEON_3R_FLOAT_ARITH 26 /* float VADD, VSUB, VPADD, VABD */
4366 #define NEON_3R_FLOAT_MULTIPLY 27 /* float VMLA, VMLS, VMUL */
4367 #define NEON_3R_FLOAT_CMP 28 /* float VCEQ, VCGE, VCGT */
4368 #define NEON_3R_FLOAT_ACMP 29 /* float VACGE, VACGT, VACLE, VACLT */
4369 #define NEON_3R_FLOAT_MINMAX 30 /* float VMIN, VMAX */
4370 #define NEON_3R_VRECPS_VRSQRTS 31 /* float VRECPS, VRSQRTS */
4372 static const uint8_t neon_3r_sizes[] = {
4373 [NEON_3R_VHADD] = 0x7,
4374 [NEON_3R_VQADD] = 0xf,
4375 [NEON_3R_VRHADD] = 0x7,
4376 [NEON_3R_LOGIC] = 0xf, /* size field encodes op type */
4377 [NEON_3R_VHSUB] = 0x7,
4378 [NEON_3R_VQSUB] = 0xf,
4379 [NEON_3R_VCGT] = 0x7,
4380 [NEON_3R_VCGE] = 0x7,
4381 [NEON_3R_VSHL] = 0xf,
4382 [NEON_3R_VQSHL] = 0xf,
4383 [NEON_3R_VRSHL] = 0xf,
4384 [NEON_3R_VQRSHL] = 0xf,
4385 [NEON_3R_VMAX] = 0x7,
4386 [NEON_3R_VMIN] = 0x7,
4387 [NEON_3R_VABD] = 0x7,
4388 [NEON_3R_VABA] = 0x7,
4389 [NEON_3R_VADD_VSUB] = 0xf,
4390 [NEON_3R_VTST_VCEQ] = 0x7,
4391 [NEON_3R_VML] = 0x7,
4392 [NEON_3R_VMUL] = 0x7,
4393 [NEON_3R_VPMAX] = 0x7,
4394 [NEON_3R_VPMIN] = 0x7,
4395 [NEON_3R_VQDMULH_VQRDMULH] = 0x6,
4396 [NEON_3R_VPADD] = 0x7,
4397 [NEON_3R_FLOAT_ARITH] = 0x5, /* size bit 1 encodes op */
4398 [NEON_3R_FLOAT_MULTIPLY] = 0x5, /* size bit 1 encodes op */
4399 [NEON_3R_FLOAT_CMP] = 0x5, /* size bit 1 encodes op */
4400 [NEON_3R_FLOAT_ACMP] = 0x5, /* size bit 1 encodes op */
4401 [NEON_3R_FLOAT_MINMAX] = 0x5, /* size bit 1 encodes op */
4402 [NEON_3R_VRECPS_VRSQRTS] = 0x5, /* size bit 1 encodes op */
4405 /* Symbolic constants for op fields for Neon 2-register miscellaneous.
4406 * The values correspond to bits [17:16,10:7]; see the ARM ARM DDI0406B
4409 #define NEON_2RM_VREV64 0
4410 #define NEON_2RM_VREV32 1
4411 #define NEON_2RM_VREV16 2
4412 #define NEON_2RM_VPADDL 4
4413 #define NEON_2RM_VPADDL_U 5
4414 #define NEON_2RM_VCLS 8
4415 #define NEON_2RM_VCLZ 9
4416 #define NEON_2RM_VCNT 10
4417 #define NEON_2RM_VMVN 11
4418 #define NEON_2RM_VPADAL 12
4419 #define NEON_2RM_VPADAL_U 13
4420 #define NEON_2RM_VQABS 14
4421 #define NEON_2RM_VQNEG 15
4422 #define NEON_2RM_VCGT0 16
4423 #define NEON_2RM_VCGE0 17
4424 #define NEON_2RM_VCEQ0 18
4425 #define NEON_2RM_VCLE0 19
4426 #define NEON_2RM_VCLT0 20
4427 #define NEON_2RM_VABS 22
4428 #define NEON_2RM_VNEG 23
4429 #define NEON_2RM_VCGT0_F 24
4430 #define NEON_2RM_VCGE0_F 25
4431 #define NEON_2RM_VCEQ0_F 26
4432 #define NEON_2RM_VCLE0_F 27
4433 #define NEON_2RM_VCLT0_F 28
4434 #define NEON_2RM_VABS_F 30
4435 #define NEON_2RM_VNEG_F 31
4436 #define NEON_2RM_VSWP 32
4437 #define NEON_2RM_VTRN 33
4438 #define NEON_2RM_VUZP 34
4439 #define NEON_2RM_VZIP 35
4440 #define NEON_2RM_VMOVN 36 /* Includes VQMOVN, VQMOVUN */
4441 #define NEON_2RM_VQMOVN 37 /* Includes VQMOVUN */
4442 #define NEON_2RM_VSHLL 38
4443 #define NEON_2RM_VCVT_F16_F32 44
4444 #define NEON_2RM_VCVT_F32_F16 46
4445 #define NEON_2RM_VRECPE 56
4446 #define NEON_2RM_VRSQRTE 57
4447 #define NEON_2RM_VRECPE_F 58
4448 #define NEON_2RM_VRSQRTE_F 59
4449 #define NEON_2RM_VCVT_FS 60
4450 #define NEON_2RM_VCVT_FU 61
4451 #define NEON_2RM_VCVT_SF 62
4452 #define NEON_2RM_VCVT_UF 63
4454 static int neon_2rm_is_float_op(int op)
4456 /* Return true if this neon 2reg-misc op is float-to-float */
4457 return (op == NEON_2RM_VABS_F || op == NEON_2RM_VNEG_F ||
4458 op >= NEON_2RM_VRECPE_F);
4461 /* Each entry in this array has bit n set if the insn allows
4462 * size value n (otherwise it will UNDEF). Since unallocated
4463 * op values will have no bits set they always UNDEF.
4465 static const uint8_t neon_2rm_sizes[] = {
4466 [NEON_2RM_VREV64] = 0x7,
4467 [NEON_2RM_VREV32] = 0x3,
4468 [NEON_2RM_VREV16] = 0x1,
4469 [NEON_2RM_VPADDL] = 0x7,
4470 [NEON_2RM_VPADDL_U] = 0x7,
4471 [NEON_2RM_VCLS] = 0x7,
4472 [NEON_2RM_VCLZ] = 0x7,
4473 [NEON_2RM_VCNT] = 0x1,
4474 [NEON_2RM_VMVN] = 0x1,
4475 [NEON_2RM_VPADAL] = 0x7,
4476 [NEON_2RM_VPADAL_U] = 0x7,
4477 [NEON_2RM_VQABS] = 0x7,
4478 [NEON_2RM_VQNEG] = 0x7,
4479 [NEON_2RM_VCGT0] = 0x7,
4480 [NEON_2RM_VCGE0] = 0x7,
4481 [NEON_2RM_VCEQ0] = 0x7,
4482 [NEON_2RM_VCLE0] = 0x7,
4483 [NEON_2RM_VCLT0] = 0x7,
4484 [NEON_2RM_VABS] = 0x7,
4485 [NEON_2RM_VNEG] = 0x7,
4486 [NEON_2RM_VCGT0_F] = 0x4,
4487 [NEON_2RM_VCGE0_F] = 0x4,
4488 [NEON_2RM_VCEQ0_F] = 0x4,
4489 [NEON_2RM_VCLE0_F] = 0x4,
4490 [NEON_2RM_VCLT0_F] = 0x4,
4491 [NEON_2RM_VABS_F] = 0x4,
4492 [NEON_2RM_VNEG_F] = 0x4,
4493 [NEON_2RM_VSWP] = 0x1,
4494 [NEON_2RM_VTRN] = 0x7,
4495 [NEON_2RM_VUZP] = 0x7,
4496 [NEON_2RM_VZIP] = 0x7,
4497 [NEON_2RM_VMOVN] = 0x7,
4498 [NEON_2RM_VQMOVN] = 0x7,
4499 [NEON_2RM_VSHLL] = 0x7,
4500 [NEON_2RM_VCVT_F16_F32] = 0x2,
4501 [NEON_2RM_VCVT_F32_F16] = 0x2,
4502 [NEON_2RM_VRECPE] = 0x4,
4503 [NEON_2RM_VRSQRTE] = 0x4,
4504 [NEON_2RM_VRECPE_F] = 0x4,
4505 [NEON_2RM_VRSQRTE_F] = 0x4,
4506 [NEON_2RM_VCVT_FS] = 0x4,
4507 [NEON_2RM_VCVT_FU] = 0x4,
4508 [NEON_2RM_VCVT_SF] = 0x4,
4509 [NEON_2RM_VCVT_UF] = 0x4,
4512 /* Translate a NEON data processing instruction. Return nonzero if the
4513 instruction is invalid.
4514 We process data in a mixture of 32-bit and 64-bit chunks.
4515 Mostly we use 32-bit chunks so we can use normal scalar instructions. */
4517 static int disas_neon_data_insn(CPUState * env, DisasContext *s, uint32_t insn)
4529 TCGv tmp, tmp2, tmp3, tmp4, tmp5;
4532 if (!s->vfp_enabled)
4534 q = (insn & (1 << 6)) != 0;
4535 u = (insn >> 24) & 1;
4536 VFP_DREG_D(rd, insn);
4537 VFP_DREG_N(rn, insn);
4538 VFP_DREG_M(rm, insn);
4539 size = (insn >> 20) & 3;
4540 if ((insn & (1 << 23)) == 0) {
4541 /* Three register same length. */
4542 op = ((insn >> 7) & 0x1e) | ((insn >> 4) & 1);
4543 /* Catch invalid op and bad size combinations: UNDEF */
4544 if ((neon_3r_sizes[op] & (1 << size)) == 0) {
4547 /* All insns of this form UNDEF for either this condition or the
4548 * superset of cases "Q==1"; we catch the latter later.
4550 if (q && ((rd | rn | rm) & 1)) {
4553 if (size == 3 && op != NEON_3R_LOGIC) {
4554 /* 64-bit element instructions. */
4555 for (pass = 0; pass < (q ? 2 : 1); pass++) {
4556 neon_load_reg64(cpu_V0, rn + pass);
4557 neon_load_reg64(cpu_V1, rm + pass);
4561 gen_helper_neon_qadd_u64(cpu_V0, cpu_V0, cpu_V1);
4563 gen_helper_neon_qadd_s64(cpu_V0, cpu_V0, cpu_V1);
4568 gen_helper_neon_qsub_u64(cpu_V0, cpu_V0, cpu_V1);
4570 gen_helper_neon_qsub_s64(cpu_V0, cpu_V0, cpu_V1);
4575 gen_helper_neon_shl_u64(cpu_V0, cpu_V1, cpu_V0);
4577 gen_helper_neon_shl_s64(cpu_V0, cpu_V1, cpu_V0);
4582 gen_helper_neon_qshl_u64(cpu_V0, cpu_V1, cpu_V0);
4584 gen_helper_neon_qshl_s64(cpu_V0, cpu_V1, cpu_V0);
4589 gen_helper_neon_rshl_u64(cpu_V0, cpu_V1, cpu_V0);
4591 gen_helper_neon_rshl_s64(cpu_V0, cpu_V1, cpu_V0);
4594 case NEON_3R_VQRSHL:
4596 gen_helper_neon_qrshl_u64(cpu_V0, cpu_V1, cpu_V0);
4598 gen_helper_neon_qrshl_s64(cpu_V0, cpu_V1, cpu_V0);
4601 case NEON_3R_VADD_VSUB:
4603 tcg_gen_sub_i64(CPU_V001);
4605 tcg_gen_add_i64(CPU_V001);
4611 neon_store_reg64(cpu_V0, rd + pass);
4620 case NEON_3R_VQRSHL:
4623 /* Shift instruction operands are reversed. */
4638 case NEON_3R_FLOAT_ARITH:
4639 pairwise = (u && size < 2); /* if VPADD (float) */
4641 case NEON_3R_FLOAT_MINMAX:
4642 pairwise = u; /* if VPMIN/VPMAX (float) */
4644 case NEON_3R_FLOAT_CMP:
4646 /* no encoding for U=0 C=1x */
4650 case NEON_3R_FLOAT_ACMP:
4655 case NEON_3R_VRECPS_VRSQRTS:
4661 if (u && (size != 0)) {
4662 /* UNDEF on invalid size for polynomial subcase */
4670 if (pairwise && q) {
4671 /* All the pairwise insns UNDEF if Q is set */
4675 for (pass = 0; pass < (q ? 4 : 2); pass++) {
4680 tmp = neon_load_reg(rn, 0);
4681 tmp2 = neon_load_reg(rn, 1);
4683 tmp = neon_load_reg(rm, 0);
4684 tmp2 = neon_load_reg(rm, 1);
4688 tmp = neon_load_reg(rn, pass);
4689 tmp2 = neon_load_reg(rm, pass);
4693 GEN_NEON_INTEGER_OP(hadd);
4696 GEN_NEON_INTEGER_OP(qadd);
4698 case NEON_3R_VRHADD:
4699 GEN_NEON_INTEGER_OP(rhadd);
4701 case NEON_3R_LOGIC: /* Logic ops. */
4702 switch ((u << 2) | size) {
4704 tcg_gen_and_i32(tmp, tmp, tmp2);
4707 tcg_gen_andc_i32(tmp, tmp, tmp2);
4710 tcg_gen_or_i32(tmp, tmp, tmp2);
4713 tcg_gen_orc_i32(tmp, tmp, tmp2);
4716 tcg_gen_xor_i32(tmp, tmp, tmp2);
4719 tmp3 = neon_load_reg(rd, pass);
4720 gen_neon_bsl(tmp, tmp, tmp2, tmp3);
4721 tcg_temp_free_i32(tmp3);
4724 tmp3 = neon_load_reg(rd, pass);
4725 gen_neon_bsl(tmp, tmp, tmp3, tmp2);
4726 tcg_temp_free_i32(tmp3);
4729 tmp3 = neon_load_reg(rd, pass);
4730 gen_neon_bsl(tmp, tmp3, tmp, tmp2);
4731 tcg_temp_free_i32(tmp3);
4736 GEN_NEON_INTEGER_OP(hsub);
4739 GEN_NEON_INTEGER_OP(qsub);
4742 GEN_NEON_INTEGER_OP(cgt);
4745 GEN_NEON_INTEGER_OP(cge);
4748 GEN_NEON_INTEGER_OP(shl);
4751 GEN_NEON_INTEGER_OP(qshl);
4754 GEN_NEON_INTEGER_OP(rshl);
4756 case NEON_3R_VQRSHL:
4757 GEN_NEON_INTEGER_OP(qrshl);
4760 GEN_NEON_INTEGER_OP(max);
4763 GEN_NEON_INTEGER_OP(min);
4766 GEN_NEON_INTEGER_OP(abd);
4769 GEN_NEON_INTEGER_OP(abd);
4770 tcg_temp_free_i32(tmp2);
4771 tmp2 = neon_load_reg(rd, pass);
4772 gen_neon_add(size, tmp, tmp2);
4774 case NEON_3R_VADD_VSUB:
4775 if (!u) { /* VADD */
4776 gen_neon_add(size, tmp, tmp2);
4779 case 0: gen_helper_neon_sub_u8(tmp, tmp, tmp2); break;
4780 case 1: gen_helper_neon_sub_u16(tmp, tmp, tmp2); break;
4781 case 2: tcg_gen_sub_i32(tmp, tmp, tmp2); break;
4786 case NEON_3R_VTST_VCEQ:
4787 if (!u) { /* VTST */
4789 case 0: gen_helper_neon_tst_u8(tmp, tmp, tmp2); break;
4790 case 1: gen_helper_neon_tst_u16(tmp, tmp, tmp2); break;
4791 case 2: gen_helper_neon_tst_u32(tmp, tmp, tmp2); break;
4796 case 0: gen_helper_neon_ceq_u8(tmp, tmp, tmp2); break;
4797 case 1: gen_helper_neon_ceq_u16(tmp, tmp, tmp2); break;
4798 case 2: gen_helper_neon_ceq_u32(tmp, tmp, tmp2); break;
4803 case NEON_3R_VML: /* VMLA, VMLAL, VMLS,VMLSL */
4805 case 0: gen_helper_neon_mul_u8(tmp, tmp, tmp2); break;
4806 case 1: gen_helper_neon_mul_u16(tmp, tmp, tmp2); break;
4807 case 2: tcg_gen_mul_i32(tmp, tmp, tmp2); break;
4810 tcg_temp_free_i32(tmp2);
4811 tmp2 = neon_load_reg(rd, pass);
4813 gen_neon_rsb(size, tmp, tmp2);
4815 gen_neon_add(size, tmp, tmp2);
4819 if (u) { /* polynomial */
4820 gen_helper_neon_mul_p8(tmp, tmp, tmp2);
4821 } else { /* Integer */
4823 case 0: gen_helper_neon_mul_u8(tmp, tmp, tmp2); break;
4824 case 1: gen_helper_neon_mul_u16(tmp, tmp, tmp2); break;
4825 case 2: tcg_gen_mul_i32(tmp, tmp, tmp2); break;
4831 GEN_NEON_INTEGER_OP(pmax);
4834 GEN_NEON_INTEGER_OP(pmin);
4836 case NEON_3R_VQDMULH_VQRDMULH: /* Multiply high. */
4837 if (!u) { /* VQDMULH */
4839 case 1: gen_helper_neon_qdmulh_s16(tmp, tmp, tmp2); break;
4840 case 2: gen_helper_neon_qdmulh_s32(tmp, tmp, tmp2); break;
4843 } else { /* VQRDMULH */
4845 case 1: gen_helper_neon_qrdmulh_s16(tmp, tmp, tmp2); break;
4846 case 2: gen_helper_neon_qrdmulh_s32(tmp, tmp, tmp2); break;
4853 case 0: gen_helper_neon_padd_u8(tmp, tmp, tmp2); break;
4854 case 1: gen_helper_neon_padd_u16(tmp, tmp, tmp2); break;
4855 case 2: tcg_gen_add_i32(tmp, tmp, tmp2); break;
4859 case NEON_3R_FLOAT_ARITH: /* Floating point arithmetic. */
4861 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
4862 switch ((u << 2) | size) {
4865 gen_helper_vfp_adds(tmp, tmp, tmp2, fpstatus);
4868 gen_helper_vfp_subs(tmp, tmp, tmp2, fpstatus);
4871 gen_helper_neon_abd_f32(tmp, tmp, tmp2, fpstatus);
4876 tcg_temp_free_ptr(fpstatus);
4879 case NEON_3R_FLOAT_MULTIPLY:
4881 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
4882 gen_helper_vfp_muls(tmp, tmp, tmp2, fpstatus);
4884 tcg_temp_free_i32(tmp2);
4885 tmp2 = neon_load_reg(rd, pass);
4887 gen_helper_vfp_adds(tmp, tmp, tmp2, fpstatus);
4889 gen_helper_vfp_subs(tmp, tmp2, tmp, fpstatus);
4892 tcg_temp_free_ptr(fpstatus);
4895 case NEON_3R_FLOAT_CMP:
4897 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
4899 gen_helper_neon_ceq_f32(tmp, tmp, tmp2, fpstatus);
4902 gen_helper_neon_cge_f32(tmp, tmp, tmp2, fpstatus);
4904 gen_helper_neon_cgt_f32(tmp, tmp, tmp2, fpstatus);
4907 tcg_temp_free_ptr(fpstatus);
4910 case NEON_3R_FLOAT_ACMP:
4912 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
4914 gen_helper_neon_acge_f32(tmp, tmp, tmp2, fpstatus);
4916 gen_helper_neon_acgt_f32(tmp, tmp, tmp2, fpstatus);
4918 tcg_temp_free_ptr(fpstatus);
4921 case NEON_3R_FLOAT_MINMAX:
4923 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
4925 gen_helper_neon_max_f32(tmp, tmp, tmp2, fpstatus);
4927 gen_helper_neon_min_f32(tmp, tmp, tmp2, fpstatus);
4929 tcg_temp_free_ptr(fpstatus);
4932 case NEON_3R_VRECPS_VRSQRTS:
4934 gen_helper_recps_f32(tmp, tmp, tmp2, cpu_env);
4936 gen_helper_rsqrts_f32(tmp, tmp, tmp2, cpu_env);
4941 tcg_temp_free_i32(tmp2);
4943 /* Save the result. For elementwise operations we can put it
4944 straight into the destination register. For pairwise operations
4945 we have to be careful to avoid clobbering the source operands. */
4946 if (pairwise && rd == rm) {
4947 neon_store_scratch(pass, tmp);
4949 neon_store_reg(rd, pass, tmp);
4953 if (pairwise && rd == rm) {
4954 for (pass = 0; pass < (q ? 4 : 2); pass++) {
4955 tmp = neon_load_scratch(pass);
4956 neon_store_reg(rd, pass, tmp);
4959 /* End of 3 register same size operations. */
4960 } else if (insn & (1 << 4)) {
4961 if ((insn & 0x00380080) != 0) {
4962 /* Two registers and shift. */
4963 op = (insn >> 8) & 0xf;
4964 if (insn & (1 << 7)) {
4972 while ((insn & (1 << (size + 19))) == 0)
4975 shift = (insn >> 16) & ((1 << (3 + size)) - 1);
4976 /* To avoid excessive dumplication of ops we implement shift
4977 by immediate using the variable shift operations. */
4979 /* Shift by immediate:
4980 VSHR, VSRA, VRSHR, VRSRA, VSRI, VSHL, VQSHL, VQSHLU. */
4981 if (q && ((rd | rm) & 1)) {
4984 if (!u && (op == 4 || op == 6)) {
4987 /* Right shifts are encoded as N - shift, where N is the
4988 element size in bits. */
4990 shift = shift - (1 << (size + 3));
4998 imm = (uint8_t) shift;
5003 imm = (uint16_t) shift;
5014 for (pass = 0; pass < count; pass++) {
5016 neon_load_reg64(cpu_V0, rm + pass);
5017 tcg_gen_movi_i64(cpu_V1, imm);
5022 gen_helper_neon_shl_u64(cpu_V0, cpu_V0, cpu_V1);
5024 gen_helper_neon_shl_s64(cpu_V0, cpu_V0, cpu_V1);
5029 gen_helper_neon_rshl_u64(cpu_V0, cpu_V0, cpu_V1);
5031 gen_helper_neon_rshl_s64(cpu_V0, cpu_V0, cpu_V1);
5034 case 5: /* VSHL, VSLI */
5035 gen_helper_neon_shl_u64(cpu_V0, cpu_V0, cpu_V1);
5037 case 6: /* VQSHLU */
5038 gen_helper_neon_qshlu_s64(cpu_V0, cpu_V0, cpu_V1);
5042 gen_helper_neon_qshl_u64(cpu_V0,
5045 gen_helper_neon_qshl_s64(cpu_V0,
5050 if (op == 1 || op == 3) {
5052 neon_load_reg64(cpu_V1, rd + pass);
5053 tcg_gen_add_i64(cpu_V0, cpu_V0, cpu_V1);
5054 } else if (op == 4 || (op == 5 && u)) {
5056 neon_load_reg64(cpu_V1, rd + pass);
5058 if (shift < -63 || shift > 63) {
5062 mask = 0xffffffffffffffffull >> -shift;
5064 mask = 0xffffffffffffffffull << shift;
5067 tcg_gen_andi_i64(cpu_V1, cpu_V1, ~mask);
5068 tcg_gen_or_i64(cpu_V0, cpu_V0, cpu_V1);
5070 neon_store_reg64(cpu_V0, rd + pass);
5071 } else { /* size < 3 */
5072 /* Operands in T0 and T1. */
5073 tmp = neon_load_reg(rm, pass);
5074 tmp2 = tcg_temp_new_i32();
5075 tcg_gen_movi_i32(tmp2, imm);
5079 GEN_NEON_INTEGER_OP(shl);
5083 GEN_NEON_INTEGER_OP(rshl);
5086 case 5: /* VSHL, VSLI */
5088 case 0: gen_helper_neon_shl_u8(tmp, tmp, tmp2); break;
5089 case 1: gen_helper_neon_shl_u16(tmp, tmp, tmp2); break;
5090 case 2: gen_helper_neon_shl_u32(tmp, tmp, tmp2); break;
5094 case 6: /* VQSHLU */
5097 gen_helper_neon_qshlu_s8(tmp, tmp, tmp2);
5100 gen_helper_neon_qshlu_s16(tmp, tmp, tmp2);
5103 gen_helper_neon_qshlu_s32(tmp, tmp, tmp2);
5110 GEN_NEON_INTEGER_OP(qshl);
5113 tcg_temp_free_i32(tmp2);
5115 if (op == 1 || op == 3) {
5117 tmp2 = neon_load_reg(rd, pass);
5118 gen_neon_add(size, tmp, tmp2);
5119 tcg_temp_free_i32(tmp2);
5120 } else if (op == 4 || (op == 5 && u)) {
5125 mask = 0xff >> -shift;
5127 mask = (uint8_t)(0xff << shift);
5133 mask = 0xffff >> -shift;
5135 mask = (uint16_t)(0xffff << shift);
5139 if (shift < -31 || shift > 31) {
5143 mask = 0xffffffffu >> -shift;
5145 mask = 0xffffffffu << shift;
5151 tmp2 = neon_load_reg(rd, pass);
5152 tcg_gen_andi_i32(tmp, tmp, mask);
5153 tcg_gen_andi_i32(tmp2, tmp2, ~mask);
5154 tcg_gen_or_i32(tmp, tmp, tmp2);
5155 tcg_temp_free_i32(tmp2);
5157 neon_store_reg(rd, pass, tmp);
5160 } else if (op < 10) {
5161 /* Shift by immediate and narrow:
5162 VSHRN, VRSHRN, VQSHRN, VQRSHRN. */
5163 int input_unsigned = (op == 8) ? !u : u;
5167 shift = shift - (1 << (size + 3));
5170 tmp64 = tcg_const_i64(shift);
5171 neon_load_reg64(cpu_V0, rm);
5172 neon_load_reg64(cpu_V1, rm + 1);
5173 for (pass = 0; pass < 2; pass++) {
5181 if (input_unsigned) {
5182 gen_helper_neon_rshl_u64(cpu_V0, in, tmp64);
5184 gen_helper_neon_rshl_s64(cpu_V0, in, tmp64);
5187 if (input_unsigned) {
5188 gen_helper_neon_shl_u64(cpu_V0, in, tmp64);
5190 gen_helper_neon_shl_s64(cpu_V0, in, tmp64);
5193 tmp = tcg_temp_new_i32();
5194 gen_neon_narrow_op(op == 8, u, size - 1, tmp, cpu_V0);
5195 neon_store_reg(rd, pass, tmp);
5197 tcg_temp_free_i64(tmp64);
5200 imm = (uint16_t)shift;
5204 imm = (uint32_t)shift;
5206 tmp2 = tcg_const_i32(imm);
5207 tmp4 = neon_load_reg(rm + 1, 0);
5208 tmp5 = neon_load_reg(rm + 1, 1);
5209 for (pass = 0; pass < 2; pass++) {
5211 tmp = neon_load_reg(rm, 0);
5215 gen_neon_shift_narrow(size, tmp, tmp2, q,
5218 tmp3 = neon_load_reg(rm, 1);
5222 gen_neon_shift_narrow(size, tmp3, tmp2, q,
5224 tcg_gen_concat_i32_i64(cpu_V0, tmp, tmp3);
5225 tcg_temp_free_i32(tmp);
5226 tcg_temp_free_i32(tmp3);
5227 tmp = tcg_temp_new_i32();
5228 gen_neon_narrow_op(op == 8, u, size - 1, tmp, cpu_V0);
5229 neon_store_reg(rd, pass, tmp);
5231 tcg_temp_free_i32(tmp2);
5233 } else if (op == 10) {
5235 if (q || (rd & 1)) {
5238 tmp = neon_load_reg(rm, 0);
5239 tmp2 = neon_load_reg(rm, 1);
5240 for (pass = 0; pass < 2; pass++) {
5244 gen_neon_widen(cpu_V0, tmp, size, u);
5247 /* The shift is less than the width of the source
5248 type, so we can just shift the whole register. */
5249 tcg_gen_shli_i64(cpu_V0, cpu_V0, shift);
5250 /* Widen the result of shift: we need to clear
5251 * the potential overflow bits resulting from
5252 * left bits of the narrow input appearing as
5253 * right bits of left the neighbour narrow
5255 if (size < 2 || !u) {
5258 imm = (0xffu >> (8 - shift));
5260 } else if (size == 1) {
5261 imm = 0xffff >> (16 - shift);
5264 imm = 0xffffffff >> (32 - shift);
5267 imm64 = imm | (((uint64_t)imm) << 32);
5271 tcg_gen_andi_i64(cpu_V0, cpu_V0, ~imm64);
5274 neon_store_reg64(cpu_V0, rd + pass);
5276 } else if (op >= 14) {
5277 /* VCVT fixed-point. */
5278 if (!(insn & (1 << 21)) || (q && ((rd | rm) & 1))) {
5281 /* We have already masked out the must-be-1 top bit of imm6,
5282 * hence this 32-shift where the ARM ARM has 64-imm6.
5285 for (pass = 0; pass < (q ? 4 : 2); pass++) {
5286 tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, pass));
5289 gen_vfp_ulto(0, shift, 1);
5291 gen_vfp_slto(0, shift, 1);
5294 gen_vfp_toul(0, shift, 1);
5296 gen_vfp_tosl(0, shift, 1);
5298 tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, pass));
5303 } else { /* (insn & 0x00380080) == 0 */
5305 if (q && (rd & 1)) {
5309 op = (insn >> 8) & 0xf;
5310 /* One register and immediate. */
5311 imm = (u << 7) | ((insn >> 12) & 0x70) | (insn & 0xf);
5312 invert = (insn & (1 << 5)) != 0;
5313 /* Note that op = 2,3,4,5,6,7,10,11,12,13 imm=0 is UNPREDICTABLE.
5314 * We choose to not special-case this and will behave as if a
5315 * valid constant encoding of 0 had been given.
5334 imm = (imm << 8) | (imm << 24);
5337 imm = (imm << 8) | 0xff;
5340 imm = (imm << 16) | 0xffff;
5343 imm |= (imm << 8) | (imm << 16) | (imm << 24);
5351 imm = ((imm & 0x80) << 24) | ((imm & 0x3f) << 19)
5352 | ((imm & 0x40) ? (0x1f << 25) : (1 << 30));
5358 for (pass = 0; pass < (q ? 4 : 2); pass++) {
5359 if (op & 1 && op < 12) {
5360 tmp = neon_load_reg(rd, pass);
5362 /* The immediate value has already been inverted, so
5364 tcg_gen_andi_i32(tmp, tmp, imm);
5366 tcg_gen_ori_i32(tmp, tmp, imm);
5370 tmp = tcg_temp_new_i32();
5371 if (op == 14 && invert) {
5375 for (n = 0; n < 4; n++) {
5376 if (imm & (1 << (n + (pass & 1) * 4)))
5377 val |= 0xff << (n * 8);
5379 tcg_gen_movi_i32(tmp, val);
5381 tcg_gen_movi_i32(tmp, imm);
5384 neon_store_reg(rd, pass, tmp);
5387 } else { /* (insn & 0x00800010 == 0x00800000) */
5389 op = (insn >> 8) & 0xf;
5390 if ((insn & (1 << 6)) == 0) {
5391 /* Three registers of different lengths. */
5395 /* undefreq: bit 0 : UNDEF if size != 0
5396 * bit 1 : UNDEF if size == 0
5397 * bit 2 : UNDEF if U == 1
5398 * Note that [1:0] set implies 'always UNDEF'
5401 /* prewiden, src1_wide, src2_wide, undefreq */
5402 static const int neon_3reg_wide[16][4] = {
5403 {1, 0, 0, 0}, /* VADDL */
5404 {1, 1, 0, 0}, /* VADDW */
5405 {1, 0, 0, 0}, /* VSUBL */
5406 {1, 1, 0, 0}, /* VSUBW */
5407 {0, 1, 1, 0}, /* VADDHN */
5408 {0, 0, 0, 0}, /* VABAL */
5409 {0, 1, 1, 0}, /* VSUBHN */
5410 {0, 0, 0, 0}, /* VABDL */
5411 {0, 0, 0, 0}, /* VMLAL */
5412 {0, 0, 0, 6}, /* VQDMLAL */
5413 {0, 0, 0, 0}, /* VMLSL */
5414 {0, 0, 0, 6}, /* VQDMLSL */
5415 {0, 0, 0, 0}, /* Integer VMULL */
5416 {0, 0, 0, 2}, /* VQDMULL */
5417 {0, 0, 0, 5}, /* Polynomial VMULL */
5418 {0, 0, 0, 3}, /* Reserved: always UNDEF */
5421 prewiden = neon_3reg_wide[op][0];
5422 src1_wide = neon_3reg_wide[op][1];
5423 src2_wide = neon_3reg_wide[op][2];
5424 undefreq = neon_3reg_wide[op][3];
5426 if (((undefreq & 1) && (size != 0)) ||
5427 ((undefreq & 2) && (size == 0)) ||
5428 ((undefreq & 4) && u)) {
5431 if ((src1_wide && (rn & 1)) ||
5432 (src2_wide && (rm & 1)) ||
5433 (!src2_wide && (rd & 1))) {
5437 /* Avoid overlapping operands. Wide source operands are
5438 always aligned so will never overlap with wide
5439 destinations in problematic ways. */
5440 if (rd == rm && !src2_wide) {
5441 tmp = neon_load_reg(rm, 1);
5442 neon_store_scratch(2, tmp);
5443 } else if (rd == rn && !src1_wide) {
5444 tmp = neon_load_reg(rn, 1);
5445 neon_store_scratch(2, tmp);
5448 for (pass = 0; pass < 2; pass++) {
5450 neon_load_reg64(cpu_V0, rn + pass);
5453 if (pass == 1 && rd == rn) {
5454 tmp = neon_load_scratch(2);
5456 tmp = neon_load_reg(rn, pass);
5459 gen_neon_widen(cpu_V0, tmp, size, u);
5463 neon_load_reg64(cpu_V1, rm + pass);
5466 if (pass == 1 && rd == rm) {
5467 tmp2 = neon_load_scratch(2);
5469 tmp2 = neon_load_reg(rm, pass);
5472 gen_neon_widen(cpu_V1, tmp2, size, u);
5476 case 0: case 1: case 4: /* VADDL, VADDW, VADDHN, VRADDHN */
5477 gen_neon_addl(size);
5479 case 2: case 3: case 6: /* VSUBL, VSUBW, VSUBHN, VRSUBHN */
5480 gen_neon_subl(size);
5482 case 5: case 7: /* VABAL, VABDL */
5483 switch ((size << 1) | u) {
5485 gen_helper_neon_abdl_s16(cpu_V0, tmp, tmp2);
5488 gen_helper_neon_abdl_u16(cpu_V0, tmp, tmp2);
5491 gen_helper_neon_abdl_s32(cpu_V0, tmp, tmp2);
5494 gen_helper_neon_abdl_u32(cpu_V0, tmp, tmp2);
5497 gen_helper_neon_abdl_s64(cpu_V0, tmp, tmp2);
5500 gen_helper_neon_abdl_u64(cpu_V0, tmp, tmp2);
5504 tcg_temp_free_i32(tmp2);
5505 tcg_temp_free_i32(tmp);
5507 case 8: case 9: case 10: case 11: case 12: case 13:
5508 /* VMLAL, VQDMLAL, VMLSL, VQDMLSL, VMULL, VQDMULL */
5509 gen_neon_mull(cpu_V0, tmp, tmp2, size, u);
5511 case 14: /* Polynomial VMULL */
5512 gen_helper_neon_mull_p8(cpu_V0, tmp, tmp2);
5513 tcg_temp_free_i32(tmp2);
5514 tcg_temp_free_i32(tmp);
5516 default: /* 15 is RESERVED: caught earlier */
5521 gen_neon_addl_saturate(cpu_V0, cpu_V0, size);
5522 neon_store_reg64(cpu_V0, rd + pass);
5523 } else if (op == 5 || (op >= 8 && op <= 11)) {
5525 neon_load_reg64(cpu_V1, rd + pass);
5527 case 10: /* VMLSL */
5528 gen_neon_negl(cpu_V0, size);
5530 case 5: case 8: /* VABAL, VMLAL */
5531 gen_neon_addl(size);
5533 case 9: case 11: /* VQDMLAL, VQDMLSL */
5534 gen_neon_addl_saturate(cpu_V0, cpu_V0, size);
5536 gen_neon_negl(cpu_V0, size);
5538 gen_neon_addl_saturate(cpu_V0, cpu_V1, size);
5543 neon_store_reg64(cpu_V0, rd + pass);
5544 } else if (op == 4 || op == 6) {
5545 /* Narrowing operation. */
5546 tmp = tcg_temp_new_i32();
5550 gen_helper_neon_narrow_high_u8(tmp, cpu_V0);
5553 gen_helper_neon_narrow_high_u16(tmp, cpu_V0);
5556 tcg_gen_shri_i64(cpu_V0, cpu_V0, 32);
5557 tcg_gen_trunc_i64_i32(tmp, cpu_V0);
5564 gen_helper_neon_narrow_round_high_u8(tmp, cpu_V0);
5567 gen_helper_neon_narrow_round_high_u16(tmp, cpu_V0);
5570 tcg_gen_addi_i64(cpu_V0, cpu_V0, 1u << 31);
5571 tcg_gen_shri_i64(cpu_V0, cpu_V0, 32);
5572 tcg_gen_trunc_i64_i32(tmp, cpu_V0);
5580 neon_store_reg(rd, 0, tmp3);
5581 neon_store_reg(rd, 1, tmp);
5584 /* Write back the result. */
5585 neon_store_reg64(cpu_V0, rd + pass);
5589 /* Two registers and a scalar. NB that for ops of this form
5590 * the ARM ARM labels bit 24 as Q, but it is in our variable
5597 case 1: /* Float VMLA scalar */
5598 case 5: /* Floating point VMLS scalar */
5599 case 9: /* Floating point VMUL scalar */
5604 case 0: /* Integer VMLA scalar */
5605 case 4: /* Integer VMLS scalar */
5606 case 8: /* Integer VMUL scalar */
5607 case 12: /* VQDMULH scalar */
5608 case 13: /* VQRDMULH scalar */
5609 if (u && ((rd | rn) & 1)) {
5612 tmp = neon_get_scalar(size, rm);
5613 neon_store_scratch(0, tmp);
5614 for (pass = 0; pass < (u ? 4 : 2); pass++) {
5615 tmp = neon_load_scratch(0);
5616 tmp2 = neon_load_reg(rn, pass);
5619 gen_helper_neon_qdmulh_s16(tmp, tmp, tmp2);
5621 gen_helper_neon_qdmulh_s32(tmp, tmp, tmp2);
5623 } else if (op == 13) {
5625 gen_helper_neon_qrdmulh_s16(tmp, tmp, tmp2);
5627 gen_helper_neon_qrdmulh_s32(tmp, tmp, tmp2);
5629 } else if (op & 1) {
5630 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
5631 gen_helper_vfp_muls(tmp, tmp, tmp2, fpstatus);
5632 tcg_temp_free_ptr(fpstatus);
5635 case 0: gen_helper_neon_mul_u8(tmp, tmp, tmp2); break;
5636 case 1: gen_helper_neon_mul_u16(tmp, tmp, tmp2); break;
5637 case 2: tcg_gen_mul_i32(tmp, tmp, tmp2); break;
5641 tcg_temp_free_i32(tmp2);
5644 tmp2 = neon_load_reg(rd, pass);
5647 gen_neon_add(size, tmp, tmp2);
5651 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
5652 gen_helper_vfp_adds(tmp, tmp, tmp2, fpstatus);
5653 tcg_temp_free_ptr(fpstatus);
5657 gen_neon_rsb(size, tmp, tmp2);
5661 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
5662 gen_helper_vfp_subs(tmp, tmp2, tmp, fpstatus);
5663 tcg_temp_free_ptr(fpstatus);
5669 tcg_temp_free_i32(tmp2);
5671 neon_store_reg(rd, pass, tmp);
5674 case 3: /* VQDMLAL scalar */
5675 case 7: /* VQDMLSL scalar */
5676 case 11: /* VQDMULL scalar */
5681 case 2: /* VMLAL sclar */
5682 case 6: /* VMLSL scalar */
5683 case 10: /* VMULL scalar */
5687 tmp2 = neon_get_scalar(size, rm);
5688 /* We need a copy of tmp2 because gen_neon_mull
5689 * deletes it during pass 0. */
5690 tmp4 = tcg_temp_new_i32();
5691 tcg_gen_mov_i32(tmp4, tmp2);
5692 tmp3 = neon_load_reg(rn, 1);
5694 for (pass = 0; pass < 2; pass++) {
5696 tmp = neon_load_reg(rn, 0);
5701 gen_neon_mull(cpu_V0, tmp, tmp2, size, u);
5703 neon_load_reg64(cpu_V1, rd + pass);
5707 gen_neon_negl(cpu_V0, size);
5710 gen_neon_addl(size);
5713 gen_neon_addl_saturate(cpu_V0, cpu_V0, size);
5715 gen_neon_negl(cpu_V0, size);
5717 gen_neon_addl_saturate(cpu_V0, cpu_V1, size);
5723 gen_neon_addl_saturate(cpu_V0, cpu_V0, size);
5728 neon_store_reg64(cpu_V0, rd + pass);
5733 default: /* 14 and 15 are RESERVED */
5737 } else { /* size == 3 */
5740 imm = (insn >> 8) & 0xf;
5745 if (q && ((rd | rn | rm) & 1)) {
5750 neon_load_reg64(cpu_V0, rn);
5752 neon_load_reg64(cpu_V1, rn + 1);
5754 } else if (imm == 8) {
5755 neon_load_reg64(cpu_V0, rn + 1);
5757 neon_load_reg64(cpu_V1, rm);
5760 tmp64 = tcg_temp_new_i64();
5762 neon_load_reg64(cpu_V0, rn);
5763 neon_load_reg64(tmp64, rn + 1);
5765 neon_load_reg64(cpu_V0, rn + 1);
5766 neon_load_reg64(tmp64, rm);
5768 tcg_gen_shri_i64(cpu_V0, cpu_V0, (imm & 7) * 8);
5769 tcg_gen_shli_i64(cpu_V1, tmp64, 64 - ((imm & 7) * 8));
5770 tcg_gen_or_i64(cpu_V0, cpu_V0, cpu_V1);
5772 neon_load_reg64(cpu_V1, rm);
5774 neon_load_reg64(cpu_V1, rm + 1);
5777 tcg_gen_shli_i64(cpu_V1, cpu_V1, 64 - (imm * 8));
5778 tcg_gen_shri_i64(tmp64, tmp64, imm * 8);
5779 tcg_gen_or_i64(cpu_V1, cpu_V1, tmp64);
5780 tcg_temp_free_i64(tmp64);
5783 neon_load_reg64(cpu_V0, rn);
5784 tcg_gen_shri_i64(cpu_V0, cpu_V0, imm * 8);
5785 neon_load_reg64(cpu_V1, rm);
5786 tcg_gen_shli_i64(cpu_V1, cpu_V1, 64 - (imm * 8));
5787 tcg_gen_or_i64(cpu_V0, cpu_V0, cpu_V1);
5789 neon_store_reg64(cpu_V0, rd);
5791 neon_store_reg64(cpu_V1, rd + 1);
5793 } else if ((insn & (1 << 11)) == 0) {
5794 /* Two register misc. */
5795 op = ((insn >> 12) & 0x30) | ((insn >> 7) & 0xf);
5796 size = (insn >> 18) & 3;
5797 /* UNDEF for unknown op values and bad op-size combinations */
5798 if ((neon_2rm_sizes[op] & (1 << size)) == 0) {
5801 if ((op != NEON_2RM_VMOVN && op != NEON_2RM_VQMOVN) &&
5802 q && ((rm | rd) & 1)) {
5806 case NEON_2RM_VREV64:
5807 for (pass = 0; pass < (q ? 2 : 1); pass++) {
5808 tmp = neon_load_reg(rm, pass * 2);
5809 tmp2 = neon_load_reg(rm, pass * 2 + 1);
5811 case 0: tcg_gen_bswap32_i32(tmp, tmp); break;
5812 case 1: gen_swap_half(tmp); break;
5813 case 2: /* no-op */ break;
5816 neon_store_reg(rd, pass * 2 + 1, tmp);
5818 neon_store_reg(rd, pass * 2, tmp2);
5821 case 0: tcg_gen_bswap32_i32(tmp2, tmp2); break;
5822 case 1: gen_swap_half(tmp2); break;
5825 neon_store_reg(rd, pass * 2, tmp2);
5829 case NEON_2RM_VPADDL: case NEON_2RM_VPADDL_U:
5830 case NEON_2RM_VPADAL: case NEON_2RM_VPADAL_U:
5831 for (pass = 0; pass < q + 1; pass++) {
5832 tmp = neon_load_reg(rm, pass * 2);
5833 gen_neon_widen(cpu_V0, tmp, size, op & 1);
5834 tmp = neon_load_reg(rm, pass * 2 + 1);
5835 gen_neon_widen(cpu_V1, tmp, size, op & 1);
5837 case 0: gen_helper_neon_paddl_u16(CPU_V001); break;
5838 case 1: gen_helper_neon_paddl_u32(CPU_V001); break;
5839 case 2: tcg_gen_add_i64(CPU_V001); break;
5842 if (op >= NEON_2RM_VPADAL) {
5844 neon_load_reg64(cpu_V1, rd + pass);
5845 gen_neon_addl(size);
5847 neon_store_reg64(cpu_V0, rd + pass);
5853 for (n = 0; n < (q ? 4 : 2); n += 2) {
5854 tmp = neon_load_reg(rm, n);
5855 tmp2 = neon_load_reg(rd, n + 1);
5856 neon_store_reg(rm, n, tmp2);
5857 neon_store_reg(rd, n + 1, tmp);
5864 if (gen_neon_unzip(rd, rm, size, q)) {
5869 if (gen_neon_zip(rd, rm, size, q)) {
5873 case NEON_2RM_VMOVN: case NEON_2RM_VQMOVN:
5874 /* also VQMOVUN; op field and mnemonics don't line up */
5879 for (pass = 0; pass < 2; pass++) {
5880 neon_load_reg64(cpu_V0, rm + pass);
5881 tmp = tcg_temp_new_i32();
5882 gen_neon_narrow_op(op == NEON_2RM_VMOVN, q, size,
5887 neon_store_reg(rd, 0, tmp2);
5888 neon_store_reg(rd, 1, tmp);
5892 case NEON_2RM_VSHLL:
5893 if (q || (rd & 1)) {
5896 tmp = neon_load_reg(rm, 0);
5897 tmp2 = neon_load_reg(rm, 1);
5898 for (pass = 0; pass < 2; pass++) {
5901 gen_neon_widen(cpu_V0, tmp, size, 1);
5902 tcg_gen_shli_i64(cpu_V0, cpu_V0, 8 << size);
5903 neon_store_reg64(cpu_V0, rd + pass);
5906 case NEON_2RM_VCVT_F16_F32:
5907 if (!arm_feature(env, ARM_FEATURE_VFP_FP16) ||
5911 tmp = tcg_temp_new_i32();
5912 tmp2 = tcg_temp_new_i32();
5913 tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 0));
5914 gen_helper_neon_fcvt_f32_to_f16(tmp, cpu_F0s, cpu_env);
5915 tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 1));
5916 gen_helper_neon_fcvt_f32_to_f16(tmp2, cpu_F0s, cpu_env);
5917 tcg_gen_shli_i32(tmp2, tmp2, 16);
5918 tcg_gen_or_i32(tmp2, tmp2, tmp);
5919 tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 2));
5920 gen_helper_neon_fcvt_f32_to_f16(tmp, cpu_F0s, cpu_env);
5921 tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 3));
5922 neon_store_reg(rd, 0, tmp2);
5923 tmp2 = tcg_temp_new_i32();
5924 gen_helper_neon_fcvt_f32_to_f16(tmp2, cpu_F0s, cpu_env);
5925 tcg_gen_shli_i32(tmp2, tmp2, 16);
5926 tcg_gen_or_i32(tmp2, tmp2, tmp);
5927 neon_store_reg(rd, 1, tmp2);
5928 tcg_temp_free_i32(tmp);
5930 case NEON_2RM_VCVT_F32_F16:
5931 if (!arm_feature(env, ARM_FEATURE_VFP_FP16) ||
5935 tmp3 = tcg_temp_new_i32();
5936 tmp = neon_load_reg(rm, 0);
5937 tmp2 = neon_load_reg(rm, 1);
5938 tcg_gen_ext16u_i32(tmp3, tmp);
5939 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env);
5940 tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 0));
5941 tcg_gen_shri_i32(tmp3, tmp, 16);
5942 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env);
5943 tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 1));
5944 tcg_temp_free_i32(tmp);
5945 tcg_gen_ext16u_i32(tmp3, tmp2);
5946 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env);
5947 tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 2));
5948 tcg_gen_shri_i32(tmp3, tmp2, 16);
5949 gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env);
5950 tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 3));
5951 tcg_temp_free_i32(tmp2);
5952 tcg_temp_free_i32(tmp3);
5956 for (pass = 0; pass < (q ? 4 : 2); pass++) {
5957 if (neon_2rm_is_float_op(op)) {
5958 tcg_gen_ld_f32(cpu_F0s, cpu_env,
5959 neon_reg_offset(rm, pass));
5962 tmp = neon_load_reg(rm, pass);
5965 case NEON_2RM_VREV32:
5967 case 0: tcg_gen_bswap32_i32(tmp, tmp); break;
5968 case 1: gen_swap_half(tmp); break;
5972 case NEON_2RM_VREV16:
5977 case 0: gen_helper_neon_cls_s8(tmp, tmp); break;
5978 case 1: gen_helper_neon_cls_s16(tmp, tmp); break;
5979 case 2: gen_helper_neon_cls_s32(tmp, tmp); break;
5985 case 0: gen_helper_neon_clz_u8(tmp, tmp); break;
5986 case 1: gen_helper_neon_clz_u16(tmp, tmp); break;
5987 case 2: gen_helper_clz(tmp, tmp); break;
5992 gen_helper_neon_cnt_u8(tmp, tmp);
5995 tcg_gen_not_i32(tmp, tmp);
5997 case NEON_2RM_VQABS:
5999 case 0: gen_helper_neon_qabs_s8(tmp, tmp); break;
6000 case 1: gen_helper_neon_qabs_s16(tmp, tmp); break;
6001 case 2: gen_helper_neon_qabs_s32(tmp, tmp); break;
6005 case NEON_2RM_VQNEG:
6007 case 0: gen_helper_neon_qneg_s8(tmp, tmp); break;
6008 case 1: gen_helper_neon_qneg_s16(tmp, tmp); break;
6009 case 2: gen_helper_neon_qneg_s32(tmp, tmp); break;
6013 case NEON_2RM_VCGT0: case NEON_2RM_VCLE0:
6014 tmp2 = tcg_const_i32(0);
6016 case 0: gen_helper_neon_cgt_s8(tmp, tmp, tmp2); break;
6017 case 1: gen_helper_neon_cgt_s16(tmp, tmp, tmp2); break;
6018 case 2: gen_helper_neon_cgt_s32(tmp, tmp, tmp2); break;
6021 tcg_temp_free(tmp2);
6022 if (op == NEON_2RM_VCLE0) {
6023 tcg_gen_not_i32(tmp, tmp);
6026 case NEON_2RM_VCGE0: case NEON_2RM_VCLT0:
6027 tmp2 = tcg_const_i32(0);
6029 case 0: gen_helper_neon_cge_s8(tmp, tmp, tmp2); break;
6030 case 1: gen_helper_neon_cge_s16(tmp, tmp, tmp2); break;
6031 case 2: gen_helper_neon_cge_s32(tmp, tmp, tmp2); break;
6034 tcg_temp_free(tmp2);
6035 if (op == NEON_2RM_VCLT0) {
6036 tcg_gen_not_i32(tmp, tmp);
6039 case NEON_2RM_VCEQ0:
6040 tmp2 = tcg_const_i32(0);
6042 case 0: gen_helper_neon_ceq_u8(tmp, tmp, tmp2); break;
6043 case 1: gen_helper_neon_ceq_u16(tmp, tmp, tmp2); break;
6044 case 2: gen_helper_neon_ceq_u32(tmp, tmp, tmp2); break;
6047 tcg_temp_free(tmp2);
6051 case 0: gen_helper_neon_abs_s8(tmp, tmp); break;
6052 case 1: gen_helper_neon_abs_s16(tmp, tmp); break;
6053 case 2: tcg_gen_abs_i32(tmp, tmp); break;
6058 tmp2 = tcg_const_i32(0);
6059 gen_neon_rsb(size, tmp, tmp2);
6060 tcg_temp_free(tmp2);
6062 case NEON_2RM_VCGT0_F:
6064 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
6065 tmp2 = tcg_const_i32(0);
6066 gen_helper_neon_cgt_f32(tmp, tmp, tmp2, fpstatus);
6067 tcg_temp_free(tmp2);
6068 tcg_temp_free_ptr(fpstatus);
6071 case NEON_2RM_VCGE0_F:
6073 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
6074 tmp2 = tcg_const_i32(0);
6075 gen_helper_neon_cge_f32(tmp, tmp, tmp2, fpstatus);
6076 tcg_temp_free(tmp2);
6077 tcg_temp_free_ptr(fpstatus);
6080 case NEON_2RM_VCEQ0_F:
6082 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
6083 tmp2 = tcg_const_i32(0);
6084 gen_helper_neon_ceq_f32(tmp, tmp, tmp2, fpstatus);
6085 tcg_temp_free(tmp2);
6086 tcg_temp_free_ptr(fpstatus);
6089 case NEON_2RM_VCLE0_F:
6091 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
6092 tmp2 = tcg_const_i32(0);
6093 gen_helper_neon_cge_f32(tmp, tmp2, tmp, fpstatus);
6094 tcg_temp_free(tmp2);
6095 tcg_temp_free_ptr(fpstatus);
6098 case NEON_2RM_VCLT0_F:
6100 TCGv_ptr fpstatus = get_fpstatus_ptr(1);
6101 tmp2 = tcg_const_i32(0);
6102 gen_helper_neon_cgt_f32(tmp, tmp2, tmp, fpstatus);
6103 tcg_temp_free(tmp2);
6104 tcg_temp_free_ptr(fpstatus);
6107 case NEON_2RM_VABS_F:
6110 case NEON_2RM_VNEG_F:
6114 tmp2 = neon_load_reg(rd, pass);
6115 neon_store_reg(rm, pass, tmp2);
6118 tmp2 = neon_load_reg(rd, pass);
6120 case 0: gen_neon_trn_u8(tmp, tmp2); break;
6121 case 1: gen_neon_trn_u16(tmp, tmp2); break;
6124 neon_store_reg(rm, pass, tmp2);
6126 case NEON_2RM_VRECPE:
6127 gen_helper_recpe_u32(tmp, tmp, cpu_env);
6129 case NEON_2RM_VRSQRTE:
6130 gen_helper_rsqrte_u32(tmp, tmp, cpu_env);
6132 case NEON_2RM_VRECPE_F:
6133 gen_helper_recpe_f32(cpu_F0s, cpu_F0s, cpu_env);
6135 case NEON_2RM_VRSQRTE_F:
6136 gen_helper_rsqrte_f32(cpu_F0s, cpu_F0s, cpu_env);
6138 case NEON_2RM_VCVT_FS: /* VCVT.F32.S32 */
6141 case NEON_2RM_VCVT_FU: /* VCVT.F32.U32 */
6144 case NEON_2RM_VCVT_SF: /* VCVT.S32.F32 */
6145 gen_vfp_tosiz(0, 1);
6147 case NEON_2RM_VCVT_UF: /* VCVT.U32.F32 */
6148 gen_vfp_touiz(0, 1);
6151 /* Reserved op values were caught by the
6152 * neon_2rm_sizes[] check earlier.
6156 if (neon_2rm_is_float_op(op)) {
6157 tcg_gen_st_f32(cpu_F0s, cpu_env,
6158 neon_reg_offset(rd, pass));
6160 neon_store_reg(rd, pass, tmp);
6165 } else if ((insn & (1 << 10)) == 0) {
6167 int n = ((insn >> 8) & 3) + 1;
6168 if ((rn + n) > 32) {
6169 /* This is UNPREDICTABLE; we choose to UNDEF to avoid the
6170 * helper function running off the end of the register file.
6175 if (insn & (1 << 6)) {
6176 tmp = neon_load_reg(rd, 0);
6178 tmp = tcg_temp_new_i32();
6179 tcg_gen_movi_i32(tmp, 0);
6181 tmp2 = neon_load_reg(rm, 0);
6182 tmp4 = tcg_const_i32(rn);
6183 tmp5 = tcg_const_i32(n);
6184 gen_helper_neon_tbl(tmp2, tmp2, tmp, tmp4, tmp5);
6185 tcg_temp_free_i32(tmp);
6186 if (insn & (1 << 6)) {
6187 tmp = neon_load_reg(rd, 1);
6189 tmp = tcg_temp_new_i32();
6190 tcg_gen_movi_i32(tmp, 0);
6192 tmp3 = neon_load_reg(rm, 1);
6193 gen_helper_neon_tbl(tmp3, tmp3, tmp, tmp4, tmp5);
6194 tcg_temp_free_i32(tmp5);
6195 tcg_temp_free_i32(tmp4);
6196 neon_store_reg(rd, 0, tmp2);
6197 neon_store_reg(rd, 1, tmp3);
6198 tcg_temp_free_i32(tmp);
6199 } else if ((insn & 0x380) == 0) {
6201 if ((insn & (7 << 16)) == 0 || (q && (rd & 1))) {
6204 if (insn & (1 << 19)) {
6205 tmp = neon_load_reg(rm, 1);
6207 tmp = neon_load_reg(rm, 0);
6209 if (insn & (1 << 16)) {
6210 gen_neon_dup_u8(tmp, ((insn >> 17) & 3) * 8);
6211 } else if (insn & (1 << 17)) {
6212 if ((insn >> 18) & 1)
6213 gen_neon_dup_high16(tmp);
6215 gen_neon_dup_low16(tmp);
6217 for (pass = 0; pass < (q ? 4 : 2); pass++) {
6218 tmp2 = tcg_temp_new_i32();
6219 tcg_gen_mov_i32(tmp2, tmp);
6220 neon_store_reg(rd, pass, tmp2);
6222 tcg_temp_free_i32(tmp);
6231 static int disas_cp14_read(CPUState * env, DisasContext *s, uint32_t insn)
6233 int crn = (insn >> 16) & 0xf;
6234 int crm = insn & 0xf;
6235 int op1 = (insn >> 21) & 7;
6236 int op2 = (insn >> 5) & 7;
6237 int rt = (insn >> 12) & 0xf;
6240 /* Minimal set of debug registers, since we don't support debug */
6241 if (op1 == 0 && crn == 0 && op2 == 0) {
6244 /* DBGDIDR: just RAZ. In particular this means the
6245 * "debug architecture version" bits will read as
6246 * a reserved value, which should cause Linux to
6247 * not try to use the debug hardware.
6249 tmp = tcg_const_i32(0);
6250 store_reg(s, rt, tmp);
6254 /* DBGDRAR and DBGDSAR: v7 only. Always RAZ since we
6255 * don't implement memory mapped debug components
6257 if (ENABLE_ARCH_7) {
6258 tmp = tcg_const_i32(0);
6259 store_reg(s, rt, tmp);
6268 if (arm_feature(env, ARM_FEATURE_THUMB2EE)) {
6269 if (op1 == 6 && crn == 0 && crm == 0 && op2 == 0) {
6273 tmp = load_cpu_field(teecr);
6274 store_reg(s, rt, tmp);
6277 if (op1 == 6 && crn == 1 && crm == 0 && op2 == 0) {
6279 if (IS_USER(s) && (env->teecr & 1))
6281 tmp = load_cpu_field(teehbr);
6282 store_reg(s, rt, tmp);
6286 fprintf(stderr, "Unknown cp14 read op1:%d crn:%d crm:%d op2:%d\n",
6287 op1, crn, crm, op2);
6291 static int disas_cp14_write(CPUState * env, DisasContext *s, uint32_t insn)
6293 int crn = (insn >> 16) & 0xf;
6294 int crm = insn & 0xf;
6295 int op1 = (insn >> 21) & 7;
6296 int op2 = (insn >> 5) & 7;
6297 int rt = (insn >> 12) & 0xf;
6300 if (arm_feature(env, ARM_FEATURE_THUMB2EE)) {
6301 if (op1 == 6 && crn == 0 && crm == 0 && op2 == 0) {
6305 tmp = load_reg(s, rt);
6306 gen_helper_set_teecr(cpu_env, tmp);
6307 tcg_temp_free_i32(tmp);
6310 if (op1 == 6 && crn == 1 && crm == 0 && op2 == 0) {
6312 if (IS_USER(s) && (env->teecr & 1))
6314 tmp = load_reg(s, rt);
6315 store_cpu_field(tmp, teehbr);
6319 fprintf(stderr, "Unknown cp14 write op1:%d crn:%d crm:%d op2:%d\n",
6320 op1, crn, crm, op2);
6324 static int disas_coproc_insn(CPUState * env, DisasContext *s, uint32_t insn)
6328 cpnum = (insn >> 8) & 0xf;
6329 if (arm_feature(env, ARM_FEATURE_XSCALE)
6330 && ((env->cp15.c15_cpar ^ 0x3fff) & (1 << cpnum)))
6336 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
6337 return disas_iwmmxt_insn(env, s, insn);
6338 } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
6339 return disas_dsp_insn(env, s, insn);
6344 return disas_vfp_insn (env, s, insn);
6346 /* Coprocessors 7-15 are architecturally reserved by ARM.
6347 Unfortunately Intel decided to ignore this. */
6348 if (arm_feature(env, ARM_FEATURE_XSCALE))
6350 if (insn & (1 << 20))
6351 return disas_cp14_read(env, s, insn);
6353 return disas_cp14_write(env, s, insn);
6355 return disas_cp15_insn (env, s, insn);
6358 /* Unknown coprocessor. See if the board has hooked it. */
6359 return disas_cp_insn (env, s, insn);
6364 /* Store a 64-bit value to a register pair. Clobbers val. */
6365 static void gen_storeq_reg(DisasContext *s, int rlow, int rhigh, TCGv_i64 val)
6368 tmp = tcg_temp_new_i32();
6369 tcg_gen_trunc_i64_i32(tmp, val);
6370 store_reg(s, rlow, tmp);
6371 tmp = tcg_temp_new_i32();
6372 tcg_gen_shri_i64(val, val, 32);
6373 tcg_gen_trunc_i64_i32(tmp, val);
6374 store_reg(s, rhigh, tmp);
6377 /* load a 32-bit value from a register and perform a 64-bit accumulate. */
6378 static void gen_addq_lo(DisasContext *s, TCGv_i64 val, int rlow)
6383 /* Load value and extend to 64 bits. */
6384 tmp = tcg_temp_new_i64();
6385 tmp2 = load_reg(s, rlow);
6386 tcg_gen_extu_i32_i64(tmp, tmp2);
6387 tcg_temp_free_i32(tmp2);
6388 tcg_gen_add_i64(val, val, tmp);
6389 tcg_temp_free_i64(tmp);
6392 /* load and add a 64-bit value from a register pair. */
6393 static void gen_addq(DisasContext *s, TCGv_i64 val, int rlow, int rhigh)
6399 /* Load 64-bit value rd:rn. */
6400 tmpl = load_reg(s, rlow);
6401 tmph = load_reg(s, rhigh);
6402 tmp = tcg_temp_new_i64();
6403 tcg_gen_concat_i32_i64(tmp, tmpl, tmph);
6404 tcg_temp_free_i32(tmpl);
6405 tcg_temp_free_i32(tmph);
6406 tcg_gen_add_i64(val, val, tmp);
6407 tcg_temp_free_i64(tmp);
6410 /* Set N and Z flags from a 64-bit value. */
6411 static void gen_logicq_cc(TCGv_i64 val)
6413 TCGv tmp = tcg_temp_new_i32();
6414 gen_helper_logicq_cc(tmp, val);
6416 tcg_temp_free_i32(tmp);
6419 /* Load/Store exclusive instructions are implemented by remembering
6420 the value/address loaded, and seeing if these are the same
6421 when the store is performed. This should be is sufficient to implement
6422 the architecturally mandated semantics, and avoids having to monitor
6425 In system emulation mode only one CPU will be running at once, so
6426 this sequence is effectively atomic. In user emulation mode we
6427 throw an exception and handle the atomic operation elsewhere. */
6428 static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
6429 TCGv addr, int size)
6435 tmp = gen_ld8u(addr, IS_USER(s));
6438 tmp = gen_ld16u(addr, IS_USER(s));
6442 tmp = gen_ld32(addr, IS_USER(s));
6447 tcg_gen_mov_i32(cpu_exclusive_val, tmp);
6448 store_reg(s, rt, tmp);
6450 TCGv tmp2 = tcg_temp_new_i32();
6451 tcg_gen_addi_i32(tmp2, addr, 4);
6452 tmp = gen_ld32(tmp2, IS_USER(s));
6453 tcg_temp_free_i32(tmp2);
6454 tcg_gen_mov_i32(cpu_exclusive_high, tmp);
6455 store_reg(s, rt2, tmp);
6457 tcg_gen_mov_i32(cpu_exclusive_addr, addr);
6460 static void gen_clrex(DisasContext *s)
6462 tcg_gen_movi_i32(cpu_exclusive_addr, -1);
6465 #ifdef CONFIG_USER_ONLY
6466 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
6467 TCGv addr, int size)
6469 tcg_gen_mov_i32(cpu_exclusive_test, addr);
6470 tcg_gen_movi_i32(cpu_exclusive_info,
6471 size | (rd << 4) | (rt << 8) | (rt2 << 12));
6472 gen_exception_insn(s, 4, EXCP_STREX);
6475 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
6476 TCGv addr, int size)
6482 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]) {
6488 fail_label = gen_new_label();
6489 done_label = gen_new_label();
6490 tcg_gen_brcond_i32(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);
6493 tmp = gen_ld8u(addr, IS_USER(s));
6496 tmp = gen_ld16u(addr, IS_USER(s));
6500 tmp = gen_ld32(addr, IS_USER(s));
6505 tcg_gen_brcond_i32(TCG_COND_NE, tmp, cpu_exclusive_val, fail_label);
6506 tcg_temp_free_i32(tmp);
6508 TCGv tmp2 = tcg_temp_new_i32();
6509 tcg_gen_addi_i32(tmp2, addr, 4);
6510 tmp = gen_ld32(tmp2, IS_USER(s));
6511 tcg_temp_free_i32(tmp2);
6512 tcg_gen_brcond_i32(TCG_COND_NE, tmp, cpu_exclusive_high, fail_label);
6513 tcg_temp_free_i32(tmp);
6515 tmp = load_reg(s, rt);
6518 gen_st8(tmp, addr, IS_USER(s));
6521 gen_st16(tmp, addr, IS_USER(s));
6525 gen_st32(tmp, addr, IS_USER(s));
6531 tcg_gen_addi_i32(addr, addr, 4);
6532 tmp = load_reg(s, rt2);
6533 gen_st32(tmp, addr, IS_USER(s));
6535 tcg_gen_movi_i32(cpu_R[rd], 0);
6536 tcg_gen_br(done_label);
6537 gen_set_label(fail_label);
6538 tcg_gen_movi_i32(cpu_R[rd], 1);
6539 gen_set_label(done_label);
6540 tcg_gen_movi_i32(cpu_exclusive_addr, -1);
6544 static void disas_arm_insn(CPUState * env, DisasContext *s)
6546 unsigned int cond, insn, val, op1, i, shift, rm, rs, rn, rd, sh;
6553 insn = ldl_code(s->pc);
6556 /* M variants do not implement ARM mode. */
6561 /* In ARMv3 and v4 the NV condition is UNPREDICTABLE; we
6562 * choose to UNDEF. In ARMv5 and above the space is used
6563 * for miscellaneous unconditional instructions.
6567 /* Unconditional instructions. */
6568 if (((insn >> 25) & 7) == 1) {
6569 /* NEON Data processing. */
6570 if (!arm_feature(env, ARM_FEATURE_NEON))
6573 if (disas_neon_data_insn(env, s, insn))
6577 if ((insn & 0x0f100000) == 0x04000000) {
6578 /* NEON load/store. */
6579 if (!arm_feature(env, ARM_FEATURE_NEON))
6582 if (disas_neon_ls_insn(env, s, insn))
6586 if (((insn & 0x0f30f000) == 0x0510f000) ||
6587 ((insn & 0x0f30f010) == 0x0710f000)) {
6588 if ((insn & (1 << 22)) == 0) {
6590 if (!arm_feature(env, ARM_FEATURE_V7MP)) {
6594 /* Otherwise PLD; v5TE+ */
6598 if (((insn & 0x0f70f000) == 0x0450f000) ||
6599 ((insn & 0x0f70f010) == 0x0650f000)) {
6601 return; /* PLI; V7 */
6603 if (((insn & 0x0f700000) == 0x04100000) ||
6604 ((insn & 0x0f700010) == 0x06100000)) {
6605 if (!arm_feature(env, ARM_FEATURE_V7MP)) {
6608 return; /* v7MP: Unallocated memory hint: must NOP */
6611 if ((insn & 0x0ffffdff) == 0x01010000) {
6614 if (insn & (1 << 9)) {
6615 /* BE8 mode not implemented. */
6619 } else if ((insn & 0x0fffff00) == 0x057ff000) {
6620 switch ((insn >> 4) & 0xf) {
6629 /* We don't emulate caches so these are a no-op. */
6634 } else if ((insn & 0x0e5fffe0) == 0x084d0500) {
6640 op1 = (insn & 0x1f);
6641 addr = tcg_temp_new_i32();
6642 tmp = tcg_const_i32(op1);
6643 gen_helper_get_r13_banked(addr, cpu_env, tmp);
6644 tcg_temp_free_i32(tmp);
6645 i = (insn >> 23) & 3;
6647 case 0: offset = -4; break; /* DA */
6648 case 1: offset = 0; break; /* IA */
6649 case 2: offset = -8; break; /* DB */
6650 case 3: offset = 4; break; /* IB */
6654 tcg_gen_addi_i32(addr, addr, offset);
6655 tmp = load_reg(s, 14);
6656 gen_st32(tmp, addr, 0);
6657 tmp = load_cpu_field(spsr);
6658 tcg_gen_addi_i32(addr, addr, 4);
6659 gen_st32(tmp, addr, 0);
6660 if (insn & (1 << 21)) {
6661 /* Base writeback. */
6663 case 0: offset = -8; break;
6664 case 1: offset = 4; break;
6665 case 2: offset = -4; break;
6666 case 3: offset = 0; break;
6670 tcg_gen_addi_i32(addr, addr, offset);
6671 tmp = tcg_const_i32(op1);
6672 gen_helper_set_r13_banked(cpu_env, tmp, addr);
6673 tcg_temp_free_i32(tmp);
6674 tcg_temp_free_i32(addr);
6676 tcg_temp_free_i32(addr);
6679 } else if ((insn & 0x0e50ffe0) == 0x08100a00) {
6685 rn = (insn >> 16) & 0xf;
6686 addr = load_reg(s, rn);
6687 i = (insn >> 23) & 3;
6689 case 0: offset = -4; break; /* DA */
6690 case 1: offset = 0; break; /* IA */
6691 case 2: offset = -8; break; /* DB */
6692 case 3: offset = 4; break; /* IB */
6696 tcg_gen_addi_i32(addr, addr, offset);
6697 /* Load PC into tmp and CPSR into tmp2. */
6698 tmp = gen_ld32(addr, 0);
6699 tcg_gen_addi_i32(addr, addr, 4);
6700 tmp2 = gen_ld32(addr, 0);
6701 if (insn & (1 << 21)) {
6702 /* Base writeback. */
6704 case 0: offset = -8; break;
6705 case 1: offset = 4; break;
6706 case 2: offset = -4; break;
6707 case 3: offset = 0; break;
6711 tcg_gen_addi_i32(addr, addr, offset);
6712 store_reg(s, rn, addr);
6714 tcg_temp_free_i32(addr);
6716 gen_rfe(s, tmp, tmp2);
6718 } else if ((insn & 0x0e000000) == 0x0a000000) {
6719 /* branch link and change to thumb (blx <offset>) */
6722 val = (uint32_t)s->pc;
6723 tmp = tcg_temp_new_i32();
6724 tcg_gen_movi_i32(tmp, val);
6725 store_reg(s, 14, tmp);
6726 /* Sign-extend the 24-bit offset */
6727 offset = (((int32_t)insn) << 8) >> 8;
6728 /* offset * 4 + bit24 * 2 + (thumb bit) */
6729 val += (offset << 2) | ((insn >> 23) & 2) | 1;
6730 /* pipeline offset */
6732 /* protected by ARCH(5); above, near the start of uncond block */
6735 } else if ((insn & 0x0e000f00) == 0x0c000100) {
6736 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
6737 /* iWMMXt register transfer. */
6738 if (env->cp15.c15_cpar & (1 << 1))
6739 if (!disas_iwmmxt_insn(env, s, insn))
6742 } else if ((insn & 0x0fe00000) == 0x0c400000) {
6743 /* Coprocessor double register transfer. */
6745 } else if ((insn & 0x0f000010) == 0x0e000010) {
6746 /* Additional coprocessor register transfer. */
6747 } else if ((insn & 0x0ff10020) == 0x01000000) {
6750 /* cps (privileged) */
6754 if (insn & (1 << 19)) {
6755 if (insn & (1 << 8))
6757 if (insn & (1 << 7))
6759 if (insn & (1 << 6))
6761 if (insn & (1 << 18))
6764 if (insn & (1 << 17)) {
6766 val |= (insn & 0x1f);
6769 gen_set_psr_im(s, mask, 0, val);
6776 /* if not always execute, we generate a conditional jump to
6778 s->condlabel = gen_new_label();
6779 gen_test_cc(cond ^ 1, s->condlabel);
6782 if ((insn & 0x0f900000) == 0x03000000) {
6783 if ((insn & (1 << 21)) == 0) {
6785 rd = (insn >> 12) & 0xf;
6786 val = ((insn >> 4) & 0xf000) | (insn & 0xfff);
6787 if ((insn & (1 << 22)) == 0) {
6789 tmp = tcg_temp_new_i32();
6790 tcg_gen_movi_i32(tmp, val);
6793 tmp = load_reg(s, rd);
6794 tcg_gen_ext16u_i32(tmp, tmp);
6795 tcg_gen_ori_i32(tmp, tmp, val << 16);
6797 store_reg(s, rd, tmp);
6799 if (((insn >> 12) & 0xf) != 0xf)
6801 if (((insn >> 16) & 0xf) == 0) {
6802 gen_nop_hint(s, insn & 0xff);
6804 /* CPSR = immediate */
6806 shift = ((insn >> 8) & 0xf) * 2;
6808 val = (val >> shift) | (val << (32 - shift));
6809 i = ((insn & (1 << 22)) != 0);
6810 if (gen_set_psr_im(s, msr_mask(env, s, (insn >> 16) & 0xf, i), i, val))
6814 } else if ((insn & 0x0f900000) == 0x01000000
6815 && (insn & 0x00000090) != 0x00000090) {
6816 /* miscellaneous instructions */
6817 op1 = (insn >> 21) & 3;
6818 sh = (insn >> 4) & 0xf;
6821 case 0x0: /* move program status register */
6824 tmp = load_reg(s, rm);
6825 i = ((op1 & 2) != 0);
6826 if (gen_set_psr(s, msr_mask(env, s, (insn >> 16) & 0xf, i), i, tmp))
6830 rd = (insn >> 12) & 0xf;
6834 tmp = load_cpu_field(spsr);
6836 tmp = tcg_temp_new_i32();
6837 gen_helper_cpsr_read(tmp);
6839 store_reg(s, rd, tmp);
6844 /* branch/exchange thumb (bx). */
6846 tmp = load_reg(s, rm);
6848 } else if (op1 == 3) {
6851 rd = (insn >> 12) & 0xf;
6852 tmp = load_reg(s, rm);
6853 gen_helper_clz(tmp, tmp);
6854 store_reg(s, rd, tmp);
6862 /* Trivial implementation equivalent to bx. */
6863 tmp = load_reg(s, rm);
6874 /* branch link/exchange thumb (blx) */
6875 tmp = load_reg(s, rm);
6876 tmp2 = tcg_temp_new_i32();
6877 tcg_gen_movi_i32(tmp2, s->pc);
6878 store_reg(s, 14, tmp2);
6881 case 0x5: /* saturating add/subtract */
6883 rd = (insn >> 12) & 0xf;
6884 rn = (insn >> 16) & 0xf;
6885 tmp = load_reg(s, rm);
6886 tmp2 = load_reg(s, rn);
6888 gen_helper_double_saturate(tmp2, tmp2);
6890 gen_helper_sub_saturate(tmp, tmp, tmp2);
6892 gen_helper_add_saturate(tmp, tmp, tmp2);
6893 tcg_temp_free_i32(tmp2);
6894 store_reg(s, rd, tmp);
6897 /* SMC instruction (op1 == 3)
6898 and undefined instructions (op1 == 0 || op1 == 2)
6905 gen_exception_insn(s, 4, EXCP_BKPT);
6907 case 0x8: /* signed multiply */
6912 rs = (insn >> 8) & 0xf;
6913 rn = (insn >> 12) & 0xf;
6914 rd = (insn >> 16) & 0xf;
6916 /* (32 * 16) >> 16 */
6917 tmp = load_reg(s, rm);
6918 tmp2 = load_reg(s, rs);
6920 tcg_gen_sari_i32(tmp2, tmp2, 16);
6923 tmp64 = gen_muls_i64_i32(tmp, tmp2);
6924 tcg_gen_shri_i64(tmp64, tmp64, 16);
6925 tmp = tcg_temp_new_i32();
6926 tcg_gen_trunc_i64_i32(tmp, tmp64);
6927 tcg_temp_free_i64(tmp64);
6928 if ((sh & 2) == 0) {
6929 tmp2 = load_reg(s, rn);
6930 gen_helper_add_setq(tmp, tmp, tmp2);
6931 tcg_temp_free_i32(tmp2);
6933 store_reg(s, rd, tmp);
6936 tmp = load_reg(s, rm);
6937 tmp2 = load_reg(s, rs);
6938 gen_mulxy(tmp, tmp2, sh & 2, sh & 4);
6939 tcg_temp_free_i32(tmp2);
6941 tmp64 = tcg_temp_new_i64();
6942 tcg_gen_ext_i32_i64(tmp64, tmp);
6943 tcg_temp_free_i32(tmp);
6944 gen_addq(s, tmp64, rn, rd);
6945 gen_storeq_reg(s, rn, rd, tmp64);
6946 tcg_temp_free_i64(tmp64);
6949 tmp2 = load_reg(s, rn);
6950 gen_helper_add_setq(tmp, tmp, tmp2);
6951 tcg_temp_free_i32(tmp2);
6953 store_reg(s, rd, tmp);
6960 } else if (((insn & 0x0e000000) == 0 &&
6961 (insn & 0x00000090) != 0x90) ||
6962 ((insn & 0x0e000000) == (1 << 25))) {
6963 int set_cc, logic_cc, shiftop;
6965 op1 = (insn >> 21) & 0xf;
6966 set_cc = (insn >> 20) & 1;
6967 logic_cc = table_logic_cc[op1] & set_cc;
6969 /* data processing instruction */
6970 if (insn & (1 << 25)) {
6971 /* immediate operand */
6973 shift = ((insn >> 8) & 0xf) * 2;
6975 val = (val >> shift) | (val << (32 - shift));
6977 tmp2 = tcg_temp_new_i32();
6978 tcg_gen_movi_i32(tmp2, val);
6979 if (logic_cc && shift) {
6980 gen_set_CF_bit31(tmp2);
6985 tmp2 = load_reg(s, rm);
6986 shiftop = (insn >> 5) & 3;
6987 if (!(insn & (1 << 4))) {
6988 shift = (insn >> 7) & 0x1f;
6989 gen_arm_shift_im(tmp2, shiftop, shift, logic_cc);
6991 rs = (insn >> 8) & 0xf;
6992 tmp = load_reg(s, rs);
6993 gen_arm_shift_reg(tmp2, shiftop, tmp, logic_cc);
6996 if (op1 != 0x0f && op1 != 0x0d) {
6997 rn = (insn >> 16) & 0xf;
6998 tmp = load_reg(s, rn);
7002 rd = (insn >> 12) & 0xf;
7005 tcg_gen_and_i32(tmp, tmp, tmp2);
7009 store_reg_bx(env, s, rd, tmp);
7012 tcg_gen_xor_i32(tmp, tmp, tmp2);
7016 store_reg_bx(env, s, rd, tmp);
7019 if (set_cc && rd == 15) {
7020 /* SUBS r15, ... is used for exception return. */
7024 gen_helper_sub_cc(tmp, tmp, tmp2);
7025 gen_exception_return(s, tmp);
7028 gen_helper_sub_cc(tmp, tmp, tmp2);
7030 tcg_gen_sub_i32(tmp, tmp, tmp2);
7032 store_reg_bx(env, s, rd, tmp);
7037 gen_helper_sub_cc(tmp, tmp2, tmp);
7039 tcg_gen_sub_i32(tmp, tmp2, tmp);
7041 store_reg_bx(env, s, rd, tmp);
7045 gen_helper_add_cc(tmp, tmp, tmp2);
7047 tcg_gen_add_i32(tmp, tmp, tmp2);
7049 store_reg_bx(env, s, rd, tmp);
7053 gen_helper_adc_cc(tmp, tmp, tmp2);
7055 gen_add_carry(tmp, tmp, tmp2);
7057 store_reg_bx(env, s, rd, tmp);
7061 gen_helper_sbc_cc(tmp, tmp, tmp2);
7063 gen_sub_carry(tmp, tmp, tmp2);
7065 store_reg_bx(env, s, rd, tmp);
7069 gen_helper_sbc_cc(tmp, tmp2, tmp);
7071 gen_sub_carry(tmp, tmp2, tmp);
7073 store_reg_bx(env, s, rd, tmp);
7077 tcg_gen_and_i32(tmp, tmp, tmp2);
7080 tcg_temp_free_i32(tmp);
7084 tcg_gen_xor_i32(tmp, tmp, tmp2);
7087 tcg_temp_free_i32(tmp);
7091 gen_helper_sub_cc(tmp, tmp, tmp2);
7093 tcg_temp_free_i32(tmp);
7097 gen_helper_add_cc(tmp, tmp, tmp2);
7099 tcg_temp_free_i32(tmp);
7102 tcg_gen_or_i32(tmp, tmp, tmp2);
7106 store_reg_bx(env, s, rd, tmp);
7109 if (logic_cc && rd == 15) {
7110 /* MOVS r15, ... is used for exception return. */
7114 gen_exception_return(s, tmp2);
7119 store_reg_bx(env, s, rd, tmp2);
7123 tcg_gen_andc_i32(tmp, tmp, tmp2);
7127 store_reg_bx(env, s, rd, tmp);
7131 tcg_gen_not_i32(tmp2, tmp2);
7135 store_reg_bx(env, s, rd, tmp2);
7138 if (op1 != 0x0f && op1 != 0x0d) {
7139 tcg_temp_free_i32(tmp2);
7142 /* other instructions */
7143 op1 = (insn >> 24) & 0xf;
7147 /* multiplies, extra load/stores */
7148 sh = (insn >> 5) & 3;
7151 rd = (insn >> 16) & 0xf;
7152 rn = (insn >> 12) & 0xf;
7153 rs = (insn >> 8) & 0xf;
7155 op1 = (insn >> 20) & 0xf;
7157 case 0: case 1: case 2: case 3: case 6:
7159 tmp = load_reg(s, rs);
7160 tmp2 = load_reg(s, rm);
7161 tcg_gen_mul_i32(tmp, tmp, tmp2);
7162 tcg_temp_free_i32(tmp2);
7163 if (insn & (1 << 22)) {
7164 /* Subtract (mls) */
7166 tmp2 = load_reg(s, rn);
7167 tcg_gen_sub_i32(tmp, tmp2, tmp);
7168 tcg_temp_free_i32(tmp2);
7169 } else if (insn & (1 << 21)) {
7171 tmp2 = load_reg(s, rn);
7172 tcg_gen_add_i32(tmp, tmp, tmp2);
7173 tcg_temp_free_i32(tmp2);
7175 if (insn & (1 << 20))
7177 store_reg(s, rd, tmp);
7180 /* 64 bit mul double accumulate (UMAAL) */
7182 tmp = load_reg(s, rs);
7183 tmp2 = load_reg(s, rm);
7184 tmp64 = gen_mulu_i64_i32(tmp, tmp2);
7185 gen_addq_lo(s, tmp64, rn);
7186 gen_addq_lo(s, tmp64, rd);
7187 gen_storeq_reg(s, rn, rd, tmp64);
7188 tcg_temp_free_i64(tmp64);
7190 case 8: case 9: case 10: case 11:
7191 case 12: case 13: case 14: case 15:
7192 /* 64 bit mul: UMULL, UMLAL, SMULL, SMLAL. */
7193 tmp = load_reg(s, rs);
7194 tmp2 = load_reg(s, rm);
7195 if (insn & (1 << 22)) {
7196 tmp64 = gen_muls_i64_i32(tmp, tmp2);
7198 tmp64 = gen_mulu_i64_i32(tmp, tmp2);
7200 if (insn & (1 << 21)) { /* mult accumulate */
7201 gen_addq(s, tmp64, rn, rd);
7203 if (insn & (1 << 20)) {
7204 gen_logicq_cc(tmp64);
7206 gen_storeq_reg(s, rn, rd, tmp64);
7207 tcg_temp_free_i64(tmp64);
7213 rn = (insn >> 16) & 0xf;
7214 rd = (insn >> 12) & 0xf;
7215 if (insn & (1 << 23)) {
7216 /* load/store exclusive */
7217 op1 = (insn >> 21) & 0x3;
7222 addr = tcg_temp_local_new_i32();
7223 load_reg_var(s, addr, rn);
7224 if (insn & (1 << 20)) {
7227 gen_load_exclusive(s, rd, 15, addr, 2);
7229 case 1: /* ldrexd */
7230 gen_load_exclusive(s, rd, rd + 1, addr, 3);
7232 case 2: /* ldrexb */
7233 gen_load_exclusive(s, rd, 15, addr, 0);
7235 case 3: /* ldrexh */
7236 gen_load_exclusive(s, rd, 15, addr, 1);
7245 gen_store_exclusive(s, rd, rm, 15, addr, 2);
7247 case 1: /* strexd */
7248 gen_store_exclusive(s, rd, rm, rm + 1, addr, 3);
7250 case 2: /* strexb */
7251 gen_store_exclusive(s, rd, rm, 15, addr, 0);
7253 case 3: /* strexh */
7254 gen_store_exclusive(s, rd, rm, 15, addr, 1);
7260 tcg_temp_free(addr);
7262 /* SWP instruction */
7265 /* ??? This is not really atomic. However we know
7266 we never have multiple CPUs running in parallel,
7267 so it is good enough. */
7268 addr = load_reg(s, rn);
7269 tmp = load_reg(s, rm);
7270 if (insn & (1 << 22)) {
7271 tmp2 = gen_ld8u(addr, IS_USER(s));
7272 gen_st8(tmp, addr, IS_USER(s));
7274 tmp2 = gen_ld32(addr, IS_USER(s));
7275 gen_st32(tmp, addr, IS_USER(s));
7277 tcg_temp_free_i32(addr);
7278 store_reg(s, rd, tmp2);
7284 /* Misc load/store */
7285 rn = (insn >> 16) & 0xf;
7286 rd = (insn >> 12) & 0xf;
7287 addr = load_reg(s, rn);
7288 if (insn & (1 << 24))
7289 gen_add_datah_offset(s, insn, 0, addr);
7291 if (insn & (1 << 20)) {
7295 tmp = gen_ld16u(addr, IS_USER(s));
7298 tmp = gen_ld8s(addr, IS_USER(s));
7302 tmp = gen_ld16s(addr, IS_USER(s));
7306 } else if (sh & 2) {
7311 tmp = load_reg(s, rd);
7312 gen_st32(tmp, addr, IS_USER(s));
7313 tcg_gen_addi_i32(addr, addr, 4);
7314 tmp = load_reg(s, rd + 1);
7315 gen_st32(tmp, addr, IS_USER(s));
7319 tmp = gen_ld32(addr, IS_USER(s));
7320 store_reg(s, rd, tmp);
7321 tcg_gen_addi_i32(addr, addr, 4);
7322 tmp = gen_ld32(addr, IS_USER(s));
7326 address_offset = -4;
7329 tmp = load_reg(s, rd);
7330 gen_st16(tmp, addr, IS_USER(s));
7333 /* Perform base writeback before the loaded value to
7334 ensure correct behavior with overlapping index registers.
7335 ldrd with base writeback is is undefined if the
7336 destination and index registers overlap. */
7337 if (!(insn & (1 << 24))) {
7338 gen_add_datah_offset(s, insn, address_offset, addr);
7339 store_reg(s, rn, addr);
7340 } else if (insn & (1 << 21)) {
7342 tcg_gen_addi_i32(addr, addr, address_offset);
7343 store_reg(s, rn, addr);
7345 tcg_temp_free_i32(addr);
7348 /* Complete the load. */
7349 store_reg(s, rd, tmp);
7358 if (insn & (1 << 4)) {
7360 /* Armv6 Media instructions. */
7362 rn = (insn >> 16) & 0xf;
7363 rd = (insn >> 12) & 0xf;
7364 rs = (insn >> 8) & 0xf;
7365 switch ((insn >> 23) & 3) {
7366 case 0: /* Parallel add/subtract. */
7367 op1 = (insn >> 20) & 7;
7368 tmp = load_reg(s, rn);
7369 tmp2 = load_reg(s, rm);
7370 sh = (insn >> 5) & 7;
7371 if ((op1 & 3) == 0 || sh == 5 || sh == 6)
7373 gen_arm_parallel_addsub(op1, sh, tmp, tmp2);
7374 tcg_temp_free_i32(tmp2);
7375 store_reg(s, rd, tmp);
7378 if ((insn & 0x00700020) == 0) {
7379 /* Halfword pack. */
7380 tmp = load_reg(s, rn);
7381 tmp2 = load_reg(s, rm);
7382 shift = (insn >> 7) & 0x1f;
7383 if (insn & (1 << 6)) {
7387 tcg_gen_sari_i32(tmp2, tmp2, shift);
7388 tcg_gen_andi_i32(tmp, tmp, 0xffff0000);
7389 tcg_gen_ext16u_i32(tmp2, tmp2);
7393 tcg_gen_shli_i32(tmp2, tmp2, shift);
7394 tcg_gen_ext16u_i32(tmp, tmp);
7395 tcg_gen_andi_i32(tmp2, tmp2, 0xffff0000);
7397 tcg_gen_or_i32(tmp, tmp, tmp2);
7398 tcg_temp_free_i32(tmp2);
7399 store_reg(s, rd, tmp);
7400 } else if ((insn & 0x00200020) == 0x00200000) {
7402 tmp = load_reg(s, rm);
7403 shift = (insn >> 7) & 0x1f;
7404 if (insn & (1 << 6)) {
7407 tcg_gen_sari_i32(tmp, tmp, shift);
7409 tcg_gen_shli_i32(tmp, tmp, shift);
7411 sh = (insn >> 16) & 0x1f;
7412 tmp2 = tcg_const_i32(sh);
7413 if (insn & (1 << 22))
7414 gen_helper_usat(tmp, tmp, tmp2);
7416 gen_helper_ssat(tmp, tmp, tmp2);
7417 tcg_temp_free_i32(tmp2);
7418 store_reg(s, rd, tmp);
7419 } else if ((insn & 0x00300fe0) == 0x00200f20) {
7421 tmp = load_reg(s, rm);
7422 sh = (insn >> 16) & 0x1f;
7423 tmp2 = tcg_const_i32(sh);
7424 if (insn & (1 << 22))
7425 gen_helper_usat16(tmp, tmp, tmp2);
7427 gen_helper_ssat16(tmp, tmp, tmp2);
7428 tcg_temp_free_i32(tmp2);
7429 store_reg(s, rd, tmp);
7430 } else if ((insn & 0x00700fe0) == 0x00000fa0) {
7432 tmp = load_reg(s, rn);
7433 tmp2 = load_reg(s, rm);
7434 tmp3 = tcg_temp_new_i32();
7435 tcg_gen_ld_i32(tmp3, cpu_env, offsetof(CPUState, GE));
7436 gen_helper_sel_flags(tmp, tmp3, tmp, tmp2);
7437 tcg_temp_free_i32(tmp3);
7438 tcg_temp_free_i32(tmp2);
7439 store_reg(s, rd, tmp);
7440 } else if ((insn & 0x000003e0) == 0x00000060) {
7441 tmp = load_reg(s, rm);
7442 shift = (insn >> 10) & 3;
7443 /* ??? In many cases it's not necessary to do a
7444 rotate, a shift is sufficient. */
7446 tcg_gen_rotri_i32(tmp, tmp, shift * 8);
7447 op1 = (insn >> 20) & 7;
7449 case 0: gen_sxtb16(tmp); break;
7450 case 2: gen_sxtb(tmp); break;
7451 case 3: gen_sxth(tmp); break;
7452 case 4: gen_uxtb16(tmp); break;
7453 case 6: gen_uxtb(tmp); break;
7454 case 7: gen_uxth(tmp); break;
7455 default: goto illegal_op;
7458 tmp2 = load_reg(s, rn);
7459 if ((op1 & 3) == 0) {
7460 gen_add16(tmp, tmp2);
7462 tcg_gen_add_i32(tmp, tmp, tmp2);
7463 tcg_temp_free_i32(tmp2);
7466 store_reg(s, rd, tmp);
7467 } else if ((insn & 0x003f0f60) == 0x003f0f20) {
7469 tmp = load_reg(s, rm);
7470 if (insn & (1 << 22)) {
7471 if (insn & (1 << 7)) {
7475 gen_helper_rbit(tmp, tmp);
7478 if (insn & (1 << 7))
7481 tcg_gen_bswap32_i32(tmp, tmp);
7483 store_reg(s, rd, tmp);
7488 case 2: /* Multiplies (Type 3). */
7489 tmp = load_reg(s, rm);
7490 tmp2 = load_reg(s, rs);
7491 if (insn & (1 << 20)) {
7492 /* Signed multiply most significant [accumulate].
7493 (SMMUL, SMMLA, SMMLS) */
7494 tmp64 = gen_muls_i64_i32(tmp, tmp2);
7497 tmp = load_reg(s, rd);
7498 if (insn & (1 << 6)) {
7499 tmp64 = gen_subq_msw(tmp64, tmp);
7501 tmp64 = gen_addq_msw(tmp64, tmp);
7504 if (insn & (1 << 5)) {
7505 tcg_gen_addi_i64(tmp64, tmp64, 0x80000000u);
7507 tcg_gen_shri_i64(tmp64, tmp64, 32);
7508 tmp = tcg_temp_new_i32();
7509 tcg_gen_trunc_i64_i32(tmp, tmp64);
7510 tcg_temp_free_i64(tmp64);
7511 store_reg(s, rn, tmp);
7513 if (insn & (1 << 5))
7514 gen_swap_half(tmp2);
7515 gen_smul_dual(tmp, tmp2);
7516 if (insn & (1 << 6)) {
7517 /* This subtraction cannot overflow. */
7518 tcg_gen_sub_i32(tmp, tmp, tmp2);
7520 /* This addition cannot overflow 32 bits;
7521 * however it may overflow considered as a signed
7522 * operation, in which case we must set the Q flag.
7524 gen_helper_add_setq(tmp, tmp, tmp2);
7526 tcg_temp_free_i32(tmp2);
7527 if (insn & (1 << 22)) {
7528 /* smlald, smlsld */
7529 tmp64 = tcg_temp_new_i64();
7530 tcg_gen_ext_i32_i64(tmp64, tmp);
7531 tcg_temp_free_i32(tmp);
7532 gen_addq(s, tmp64, rd, rn);
7533 gen_storeq_reg(s, rd, rn, tmp64);
7534 tcg_temp_free_i64(tmp64);
7536 /* smuad, smusd, smlad, smlsd */
7539 tmp2 = load_reg(s, rd);
7540 gen_helper_add_setq(tmp, tmp, tmp2);
7541 tcg_temp_free_i32(tmp2);
7543 store_reg(s, rn, tmp);
7548 op1 = ((insn >> 17) & 0x38) | ((insn >> 5) & 7);
7550 case 0: /* Unsigned sum of absolute differences. */
7552 tmp = load_reg(s, rm);
7553 tmp2 = load_reg(s, rs);
7554 gen_helper_usad8(tmp, tmp, tmp2);
7555 tcg_temp_free_i32(tmp2);
7557 tmp2 = load_reg(s, rd);
7558 tcg_gen_add_i32(tmp, tmp, tmp2);
7559 tcg_temp_free_i32(tmp2);
7561 store_reg(s, rn, tmp);
7563 case 0x20: case 0x24: case 0x28: case 0x2c:
7564 /* Bitfield insert/clear. */
7566 shift = (insn >> 7) & 0x1f;
7567 i = (insn >> 16) & 0x1f;
7570 tmp = tcg_temp_new_i32();
7571 tcg_gen_movi_i32(tmp, 0);
7573 tmp = load_reg(s, rm);
7576 tmp2 = load_reg(s, rd);
7577 gen_bfi(tmp, tmp2, tmp, shift, (1u << i) - 1);
7578 tcg_temp_free_i32(tmp2);
7580 store_reg(s, rd, tmp);
7582 case 0x12: case 0x16: case 0x1a: case 0x1e: /* sbfx */
7583 case 0x32: case 0x36: case 0x3a: case 0x3e: /* ubfx */
7585 tmp = load_reg(s, rm);
7586 shift = (insn >> 7) & 0x1f;
7587 i = ((insn >> 16) & 0x1f) + 1;
7592 gen_ubfx(tmp, shift, (1u << i) - 1);
7594 gen_sbfx(tmp, shift, i);
7597 store_reg(s, rd, tmp);
7607 /* Check for undefined extension instructions
7608 * per the ARM Bible IE:
7609 * xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
7611 sh = (0xf << 20) | (0xf << 4);
7612 if (op1 == 0x7 && ((insn & sh) == sh))
7616 /* load/store byte/word */
7617 rn = (insn >> 16) & 0xf;
7618 rd = (insn >> 12) & 0xf;
7619 tmp2 = load_reg(s, rn);
7620 i = (IS_USER(s) || (insn & 0x01200000) == 0x00200000);
7621 if (insn & (1 << 24))
7622 gen_add_data_offset(s, insn, tmp2);
7623 if (insn & (1 << 20)) {
7625 if (insn & (1 << 22)) {
7626 tmp = gen_ld8u(tmp2, i);
7628 tmp = gen_ld32(tmp2, i);
7632 tmp = load_reg(s, rd);
7633 if (insn & (1 << 22))
7634 gen_st8(tmp, tmp2, i);
7636 gen_st32(tmp, tmp2, i);
7638 if (!(insn & (1 << 24))) {
7639 gen_add_data_offset(s, insn, tmp2);
7640 store_reg(s, rn, tmp2);
7641 } else if (insn & (1 << 21)) {
7642 store_reg(s, rn, tmp2);
7644 tcg_temp_free_i32(tmp2);
7646 if (insn & (1 << 20)) {
7647 /* Complete the load. */
7648 store_reg_from_load(env, s, rd, tmp);
7654 int j, n, user, loaded_base;
7656 /* load/store multiple words */
7657 /* XXX: store correct base if write back */
7659 if (insn & (1 << 22)) {
7661 goto illegal_op; /* only usable in supervisor mode */
7663 if ((insn & (1 << 15)) == 0)
7666 rn = (insn >> 16) & 0xf;
7667 addr = load_reg(s, rn);
7669 /* compute total size */
7671 TCGV_UNUSED(loaded_var);
7674 if (insn & (1 << i))
7677 /* XXX: test invalid n == 0 case ? */
7678 if (insn & (1 << 23)) {
7679 if (insn & (1 << 24)) {
7681 tcg_gen_addi_i32(addr, addr, 4);
7683 /* post increment */
7686 if (insn & (1 << 24)) {
7688 tcg_gen_addi_i32(addr, addr, -(n * 4));
7690 /* post decrement */
7692 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
7697 if (insn & (1 << i)) {
7698 if (insn & (1 << 20)) {
7700 tmp = gen_ld32(addr, IS_USER(s));
7702 tmp2 = tcg_const_i32(i);
7703 gen_helper_set_user_reg(tmp2, tmp);
7704 tcg_temp_free_i32(tmp2);
7705 tcg_temp_free_i32(tmp);
7706 } else if (i == rn) {
7710 store_reg_from_load(env, s, i, tmp);
7715 /* special case: r15 = PC + 8 */
7716 val = (long)s->pc + 4;
7717 tmp = tcg_temp_new_i32();
7718 tcg_gen_movi_i32(tmp, val);
7720 tmp = tcg_temp_new_i32();
7721 tmp2 = tcg_const_i32(i);
7722 gen_helper_get_user_reg(tmp, tmp2);
7723 tcg_temp_free_i32(tmp2);
7725 tmp = load_reg(s, i);
7727 gen_st32(tmp, addr, IS_USER(s));
7730 /* no need to add after the last transfer */
7732 tcg_gen_addi_i32(addr, addr, 4);
7735 if (insn & (1 << 21)) {
7737 if (insn & (1 << 23)) {
7738 if (insn & (1 << 24)) {
7741 /* post increment */
7742 tcg_gen_addi_i32(addr, addr, 4);
7745 if (insn & (1 << 24)) {
7748 tcg_gen_addi_i32(addr, addr, -((n - 1) * 4));
7750 /* post decrement */
7751 tcg_gen_addi_i32(addr, addr, -(n * 4));
7754 store_reg(s, rn, addr);
7756 tcg_temp_free_i32(addr);
7759 store_reg(s, rn, loaded_var);
7761 if ((insn & (1 << 22)) && !user) {
7762 /* Restore CPSR from SPSR. */
7763 tmp = load_cpu_field(spsr);
7764 gen_set_cpsr(tmp, 0xffffffff);
7765 tcg_temp_free_i32(tmp);
7766 s->is_jmp = DISAS_UPDATE;
7775 /* branch (and link) */
7776 val = (int32_t)s->pc;
7777 if (insn & (1 << 24)) {
7778 tmp = tcg_temp_new_i32();
7779 tcg_gen_movi_i32(tmp, val);
7780 store_reg(s, 14, tmp);
7782 offset = (((int32_t)insn << 8) >> 8);
7783 val += (offset << 2) + 4;
7791 if (disas_coproc_insn(env, s, insn))
7796 gen_set_pc_im(s->pc);
7797 s->is_jmp = DISAS_SWI;
7801 gen_exception_insn(s, 4, EXCP_UDEF);
7807 /* Return true if this is a Thumb-2 logical op. */
7809 thumb2_logic_op(int op)
7814 /* Generate code for a Thumb-2 data processing operation. If CONDS is nonzero
7815 then set condition code flags based on the result of the operation.
7816 If SHIFTER_OUT is nonzero then set the carry flag for logical operations
7817 to the high bit of T1.
7818 Returns zero if the opcode is valid. */
7821 gen_thumb2_data_op(DisasContext *s, int op, int conds, uint32_t shifter_out, TCGv t0, TCGv t1)
7828 tcg_gen_and_i32(t0, t0, t1);
7832 tcg_gen_andc_i32(t0, t0, t1);
7836 tcg_gen_or_i32(t0, t0, t1);
7840 tcg_gen_orc_i32(t0, t0, t1);
7844 tcg_gen_xor_i32(t0, t0, t1);
7849 gen_helper_add_cc(t0, t0, t1);
7851 tcg_gen_add_i32(t0, t0, t1);
7855 gen_helper_adc_cc(t0, t0, t1);
7861 gen_helper_sbc_cc(t0, t0, t1);
7863 gen_sub_carry(t0, t0, t1);
7867 gen_helper_sub_cc(t0, t0, t1);
7869 tcg_gen_sub_i32(t0, t0, t1);
7873 gen_helper_sub_cc(t0, t1, t0);
7875 tcg_gen_sub_i32(t0, t1, t0);
7877 default: /* 5, 6, 7, 9, 12, 15. */
7883 gen_set_CF_bit31(t1);
7888 /* Translate a 32-bit thumb instruction. Returns nonzero if the instruction
7890 static int disas_thumb2_insn(CPUState *env, DisasContext *s, uint16_t insn_hw1)
7892 uint32_t insn, imm, shift, offset;
7893 uint32_t rd, rn, rm, rs;
7904 if (!(arm_feature(env, ARM_FEATURE_THUMB2)
7905 || arm_feature (env, ARM_FEATURE_M))) {
7906 /* Thumb-1 cores may need to treat bl and blx as a pair of
7907 16-bit instructions to get correct prefetch abort behavior. */
7909 if ((insn & (1 << 12)) == 0) {
7911 /* Second half of blx. */
7912 offset = ((insn & 0x7ff) << 1);
7913 tmp = load_reg(s, 14);
7914 tcg_gen_addi_i32(tmp, tmp, offset);
7915 tcg_gen_andi_i32(tmp, tmp, 0xfffffffc);
7917 tmp2 = tcg_temp_new_i32();
7918 tcg_gen_movi_i32(tmp2, s->pc | 1);
7919 store_reg(s, 14, tmp2);
7923 if (insn & (1 << 11)) {
7924 /* Second half of bl. */
7925 offset = ((insn & 0x7ff) << 1) | 1;
7926 tmp = load_reg(s, 14);
7927 tcg_gen_addi_i32(tmp, tmp, offset);
7929 tmp2 = tcg_temp_new_i32();
7930 tcg_gen_movi_i32(tmp2, s->pc | 1);
7931 store_reg(s, 14, tmp2);
7935 if ((s->pc & ~TARGET_PAGE_MASK) == 0) {
7936 /* Instruction spans a page boundary. Implement it as two
7937 16-bit instructions in case the second half causes an
7939 offset = ((int32_t)insn << 21) >> 9;
7940 tcg_gen_movi_i32(cpu_R[14], s->pc + 2 + offset);
7943 /* Fall through to 32-bit decode. */
7946 insn = lduw_code(s->pc);
7948 insn |= (uint32_t)insn_hw1 << 16;
7950 if ((insn & 0xf800e800) != 0xf000e800) {
7954 rn = (insn >> 16) & 0xf;
7955 rs = (insn >> 12) & 0xf;
7956 rd = (insn >> 8) & 0xf;
7958 switch ((insn >> 25) & 0xf) {
7959 case 0: case 1: case 2: case 3:
7960 /* 16-bit instructions. Should never happen. */
7963 if (insn & (1 << 22)) {
7964 /* Other load/store, table branch. */
7965 if (insn & 0x01200000) {
7966 /* Load/store doubleword. */
7968 addr = tcg_temp_new_i32();
7969 tcg_gen_movi_i32(addr, s->pc & ~3);
7971 addr = load_reg(s, rn);
7973 offset = (insn & 0xff) * 4;
7974 if ((insn & (1 << 23)) == 0)
7976 if (insn & (1 << 24)) {
7977 tcg_gen_addi_i32(addr, addr, offset);
7980 if (insn & (1 << 20)) {
7982 tmp = gen_ld32(addr, IS_USER(s));
7983 store_reg(s, rs, tmp);
7984 tcg_gen_addi_i32(addr, addr, 4);
7985 tmp = gen_ld32(addr, IS_USER(s));
7986 store_reg(s, rd, tmp);
7989 tmp = load_reg(s, rs);
7990 gen_st32(tmp, addr, IS_USER(s));
7991 tcg_gen_addi_i32(addr, addr, 4);
7992 tmp = load_reg(s, rd);
7993 gen_st32(tmp, addr, IS_USER(s));
7995 if (insn & (1 << 21)) {
7996 /* Base writeback. */
7999 tcg_gen_addi_i32(addr, addr, offset - 4);
8000 store_reg(s, rn, addr);
8002 tcg_temp_free_i32(addr);
8004 } else if ((insn & (1 << 23)) == 0) {
8005 /* Load/store exclusive word. */
8006 addr = tcg_temp_local_new();
8007 load_reg_var(s, addr, rn);
8008 tcg_gen_addi_i32(addr, addr, (insn & 0xff) << 2);
8009 if (insn & (1 << 20)) {
8010 gen_load_exclusive(s, rs, 15, addr, 2);
8012 gen_store_exclusive(s, rd, rs, 15, addr, 2);
8014 tcg_temp_free(addr);
8015 } else if ((insn & (1 << 6)) == 0) {
8018 addr = tcg_temp_new_i32();
8019 tcg_gen_movi_i32(addr, s->pc);
8021 addr = load_reg(s, rn);
8023 tmp = load_reg(s, rm);
8024 tcg_gen_add_i32(addr, addr, tmp);
8025 if (insn & (1 << 4)) {
8027 tcg_gen_add_i32(addr, addr, tmp);
8028 tcg_temp_free_i32(tmp);
8029 tmp = gen_ld16u(addr, IS_USER(s));
8031 tcg_temp_free_i32(tmp);
8032 tmp = gen_ld8u(addr, IS_USER(s));
8034 tcg_temp_free_i32(addr);
8035 tcg_gen_shli_i32(tmp, tmp, 1);
8036 tcg_gen_addi_i32(tmp, tmp, s->pc);
8037 store_reg(s, 15, tmp);
8039 /* Load/store exclusive byte/halfword/doubleword. */
8041 op = (insn >> 4) & 0x3;
8045 addr = tcg_temp_local_new();
8046 load_reg_var(s, addr, rn);
8047 if (insn & (1 << 20)) {
8048 gen_load_exclusive(s, rs, rd, addr, op);
8050 gen_store_exclusive(s, rm, rs, rd, addr, op);
8052 tcg_temp_free(addr);
8055 /* Load/store multiple, RFE, SRS. */
8056 if (((insn >> 23) & 1) == ((insn >> 24) & 1)) {
8057 /* Not available in user mode. */
8060 if (insn & (1 << 20)) {
8062 addr = load_reg(s, rn);
8063 if ((insn & (1 << 24)) == 0)
8064 tcg_gen_addi_i32(addr, addr, -8);
8065 /* Load PC into tmp and CPSR into tmp2. */
8066 tmp = gen_ld32(addr, 0);
8067 tcg_gen_addi_i32(addr, addr, 4);
8068 tmp2 = gen_ld32(addr, 0);
8069 if (insn & (1 << 21)) {
8070 /* Base writeback. */
8071 if (insn & (1 << 24)) {
8072 tcg_gen_addi_i32(addr, addr, 4);
8074 tcg_gen_addi_i32(addr, addr, -4);
8076 store_reg(s, rn, addr);
8078 tcg_temp_free_i32(addr);
8080 gen_rfe(s, tmp, tmp2);
8084 addr = tcg_temp_new_i32();
8085 tmp = tcg_const_i32(op);
8086 gen_helper_get_r13_banked(addr, cpu_env, tmp);
8087 tcg_temp_free_i32(tmp);
8088 if ((insn & (1 << 24)) == 0) {
8089 tcg_gen_addi_i32(addr, addr, -8);
8091 tmp = load_reg(s, 14);
8092 gen_st32(tmp, addr, 0);
8093 tcg_gen_addi_i32(addr, addr, 4);
8094 tmp = tcg_temp_new_i32();
8095 gen_helper_cpsr_read(tmp);
8096 gen_st32(tmp, addr, 0);
8097 if (insn & (1 << 21)) {
8098 if ((insn & (1 << 24)) == 0) {
8099 tcg_gen_addi_i32(addr, addr, -4);
8101 tcg_gen_addi_i32(addr, addr, 4);
8103 tmp = tcg_const_i32(op);
8104 gen_helper_set_r13_banked(cpu_env, tmp, addr);
8105 tcg_temp_free_i32(tmp);
8107 tcg_temp_free_i32(addr);
8111 int i, loaded_base = 0;
8113 /* Load/store multiple. */
8114 addr = load_reg(s, rn);
8116 for (i = 0; i < 16; i++) {
8117 if (insn & (1 << i))
8120 if (insn & (1 << 24)) {
8121 tcg_gen_addi_i32(addr, addr, -offset);
8124 TCGV_UNUSED(loaded_var);
8125 for (i = 0; i < 16; i++) {
8126 if ((insn & (1 << i)) == 0)
8128 if (insn & (1 << 20)) {
8130 tmp = gen_ld32(addr, IS_USER(s));
8133 } else if (i == rn) {
8137 store_reg(s, i, tmp);
8141 tmp = load_reg(s, i);
8142 gen_st32(tmp, addr, IS_USER(s));
8144 tcg_gen_addi_i32(addr, addr, 4);
8147 store_reg(s, rn, loaded_var);
8149 if (insn & (1 << 21)) {
8150 /* Base register writeback. */
8151 if (insn & (1 << 24)) {
8152 tcg_gen_addi_i32(addr, addr, -offset);
8154 /* Fault if writeback register is in register list. */
8155 if (insn & (1 << rn))
8157 store_reg(s, rn, addr);
8159 tcg_temp_free_i32(addr);
8166 op = (insn >> 21) & 0xf;
8168 /* Halfword pack. */
8169 tmp = load_reg(s, rn);
8170 tmp2 = load_reg(s, rm);
8171 shift = ((insn >> 10) & 0x1c) | ((insn >> 6) & 0x3);
8172 if (insn & (1 << 5)) {
8176 tcg_gen_sari_i32(tmp2, tmp2, shift);
8177 tcg_gen_andi_i32(tmp, tmp, 0xffff0000);
8178 tcg_gen_ext16u_i32(tmp2, tmp2);
8182 tcg_gen_shli_i32(tmp2, tmp2, shift);
8183 tcg_gen_ext16u_i32(tmp, tmp);
8184 tcg_gen_andi_i32(tmp2, tmp2, 0xffff0000);
8186 tcg_gen_or_i32(tmp, tmp, tmp2);
8187 tcg_temp_free_i32(tmp2);
8188 store_reg(s, rd, tmp);
8190 /* Data processing register constant shift. */
8192 tmp = tcg_temp_new_i32();
8193 tcg_gen_movi_i32(tmp, 0);
8195 tmp = load_reg(s, rn);
8197 tmp2 = load_reg(s, rm);
8199 shiftop = (insn >> 4) & 3;
8200 shift = ((insn >> 6) & 3) | ((insn >> 10) & 0x1c);
8201 conds = (insn & (1 << 20)) != 0;
8202 logic_cc = (conds && thumb2_logic_op(op));
8203 gen_arm_shift_im(tmp2, shiftop, shift, logic_cc);
8204 if (gen_thumb2_data_op(s, op, conds, 0, tmp, tmp2))
8206 tcg_temp_free_i32(tmp2);
8208 store_reg(s, rd, tmp);
8210 tcg_temp_free_i32(tmp);
8214 case 13: /* Misc data processing. */
8215 op = ((insn >> 22) & 6) | ((insn >> 7) & 1);
8216 if (op < 4 && (insn & 0xf000) != 0xf000)
8219 case 0: /* Register controlled shift. */
8220 tmp = load_reg(s, rn);
8221 tmp2 = load_reg(s, rm);
8222 if ((insn & 0x70) != 0)
8224 op = (insn >> 21) & 3;
8225 logic_cc = (insn & (1 << 20)) != 0;
8226 gen_arm_shift_reg(tmp, op, tmp2, logic_cc);
8229 store_reg_bx(env, s, rd, tmp);
8231 case 1: /* Sign/zero extend. */
8232 tmp = load_reg(s, rm);
8233 shift = (insn >> 4) & 3;
8234 /* ??? In many cases it's not necessary to do a
8235 rotate, a shift is sufficient. */
8237 tcg_gen_rotri_i32(tmp, tmp, shift * 8);
8238 op = (insn >> 20) & 7;
8240 case 0: gen_sxth(tmp); break;
8241 case 1: gen_uxth(tmp); break;
8242 case 2: gen_sxtb16(tmp); break;
8243 case 3: gen_uxtb16(tmp); break;
8244 case 4: gen_sxtb(tmp); break;
8245 case 5: gen_uxtb(tmp); break;
8246 default: goto illegal_op;
8249 tmp2 = load_reg(s, rn);
8250 if ((op >> 1) == 1) {
8251 gen_add16(tmp, tmp2);
8253 tcg_gen_add_i32(tmp, tmp, tmp2);
8254 tcg_temp_free_i32(tmp2);
8257 store_reg(s, rd, tmp);
8259 case 2: /* SIMD add/subtract. */
8260 op = (insn >> 20) & 7;
8261 shift = (insn >> 4) & 7;
8262 if ((op & 3) == 3 || (shift & 3) == 3)
8264 tmp = load_reg(s, rn);
8265 tmp2 = load_reg(s, rm);
8266 gen_thumb2_parallel_addsub(op, shift, tmp, tmp2);
8267 tcg_temp_free_i32(tmp2);
8268 store_reg(s, rd, tmp);
8270 case 3: /* Other data processing. */
8271 op = ((insn >> 17) & 0x38) | ((insn >> 4) & 7);
8273 /* Saturating add/subtract. */
8274 tmp = load_reg(s, rn);
8275 tmp2 = load_reg(s, rm);
8277 gen_helper_double_saturate(tmp, tmp);
8279 gen_helper_sub_saturate(tmp, tmp2, tmp);
8281 gen_helper_add_saturate(tmp, tmp, tmp2);
8282 tcg_temp_free_i32(tmp2);
8284 tmp = load_reg(s, rn);
8286 case 0x0a: /* rbit */
8287 gen_helper_rbit(tmp, tmp);
8289 case 0x08: /* rev */
8290 tcg_gen_bswap32_i32(tmp, tmp);
8292 case 0x09: /* rev16 */
8295 case 0x0b: /* revsh */
8298 case 0x10: /* sel */
8299 tmp2 = load_reg(s, rm);
8300 tmp3 = tcg_temp_new_i32();
8301 tcg_gen_ld_i32(tmp3, cpu_env, offsetof(CPUState, GE));
8302 gen_helper_sel_flags(tmp, tmp3, tmp, tmp2);
8303 tcg_temp_free_i32(tmp3);
8304 tcg_temp_free_i32(tmp2);
8306 case 0x18: /* clz */
8307 gen_helper_clz(tmp, tmp);
8313 store_reg(s, rd, tmp);
8315 case 4: case 5: /* 32-bit multiply. Sum of absolute differences. */
8316 op = (insn >> 4) & 0xf;
8317 tmp = load_reg(s, rn);
8318 tmp2 = load_reg(s, rm);
8319 switch ((insn >> 20) & 7) {
8320 case 0: /* 32 x 32 -> 32 */
8321 tcg_gen_mul_i32(tmp, tmp, tmp2);
8322 tcg_temp_free_i32(tmp2);
8324 tmp2 = load_reg(s, rs);
8326 tcg_gen_sub_i32(tmp, tmp2, tmp);
8328 tcg_gen_add_i32(tmp, tmp, tmp2);
8329 tcg_temp_free_i32(tmp2);
8332 case 1: /* 16 x 16 -> 32 */
8333 gen_mulxy(tmp, tmp2, op & 2, op & 1);
8334 tcg_temp_free_i32(tmp2);
8336 tmp2 = load_reg(s, rs);
8337 gen_helper_add_setq(tmp, tmp, tmp2);
8338 tcg_temp_free_i32(tmp2);
8341 case 2: /* Dual multiply add. */
8342 case 4: /* Dual multiply subtract. */
8344 gen_swap_half(tmp2);
8345 gen_smul_dual(tmp, tmp2);
8346 if (insn & (1 << 22)) {
8347 /* This subtraction cannot overflow. */
8348 tcg_gen_sub_i32(tmp, tmp, tmp2);
8350 /* This addition cannot overflow 32 bits;
8351 * however it may overflow considered as a signed
8352 * operation, in which case we must set the Q flag.
8354 gen_helper_add_setq(tmp, tmp, tmp2);
8356 tcg_temp_free_i32(tmp2);
8359 tmp2 = load_reg(s, rs);
8360 gen_helper_add_setq(tmp, tmp, tmp2);
8361 tcg_temp_free_i32(tmp2);
8364 case 3: /* 32 * 16 -> 32msb */
8366 tcg_gen_sari_i32(tmp2, tmp2, 16);
8369 tmp64 = gen_muls_i64_i32(tmp, tmp2);
8370 tcg_gen_shri_i64(tmp64, tmp64, 16);
8371 tmp = tcg_temp_new_i32();
8372 tcg_gen_trunc_i64_i32(tmp, tmp64);
8373 tcg_temp_free_i64(tmp64);
8376 tmp2 = load_reg(s, rs);
8377 gen_helper_add_setq(tmp, tmp, tmp2);
8378 tcg_temp_free_i32(tmp2);
8381 case 5: case 6: /* 32 * 32 -> 32msb (SMMUL, SMMLA, SMMLS) */
8382 tmp64 = gen_muls_i64_i32(tmp, tmp2);
8384 tmp = load_reg(s, rs);
8385 if (insn & (1 << 20)) {
8386 tmp64 = gen_addq_msw(tmp64, tmp);
8388 tmp64 = gen_subq_msw(tmp64, tmp);
8391 if (insn & (1 << 4)) {
8392 tcg_gen_addi_i64(tmp64, tmp64, 0x80000000u);
8394 tcg_gen_shri_i64(tmp64, tmp64, 32);
8395 tmp = tcg_temp_new_i32();
8396 tcg_gen_trunc_i64_i32(tmp, tmp64);
8397 tcg_temp_free_i64(tmp64);
8399 case 7: /* Unsigned sum of absolute differences. */
8400 gen_helper_usad8(tmp, tmp, tmp2);
8401 tcg_temp_free_i32(tmp2);
8403 tmp2 = load_reg(s, rs);
8404 tcg_gen_add_i32(tmp, tmp, tmp2);
8405 tcg_temp_free_i32(tmp2);
8409 store_reg(s, rd, tmp);
8411 case 6: case 7: /* 64-bit multiply, Divide. */
8412 op = ((insn >> 4) & 0xf) | ((insn >> 16) & 0x70);
8413 tmp = load_reg(s, rn);
8414 tmp2 = load_reg(s, rm);
8415 if ((op & 0x50) == 0x10) {
8417 if (!arm_feature(env, ARM_FEATURE_DIV))
8420 gen_helper_udiv(tmp, tmp, tmp2);
8422 gen_helper_sdiv(tmp, tmp, tmp2);
8423 tcg_temp_free_i32(tmp2);
8424 store_reg(s, rd, tmp);
8425 } else if ((op & 0xe) == 0xc) {
8426 /* Dual multiply accumulate long. */
8428 gen_swap_half(tmp2);
8429 gen_smul_dual(tmp, tmp2);
8431 tcg_gen_sub_i32(tmp, tmp, tmp2);
8433 tcg_gen_add_i32(tmp, tmp, tmp2);
8435 tcg_temp_free_i32(tmp2);
8437 tmp64 = tcg_temp_new_i64();
8438 tcg_gen_ext_i32_i64(tmp64, tmp);
8439 tcg_temp_free_i32(tmp);
8440 gen_addq(s, tmp64, rs, rd);
8441 gen_storeq_reg(s, rs, rd, tmp64);
8442 tcg_temp_free_i64(tmp64);
8445 /* Unsigned 64-bit multiply */
8446 tmp64 = gen_mulu_i64_i32(tmp, tmp2);
8450 gen_mulxy(tmp, tmp2, op & 2, op & 1);
8451 tcg_temp_free_i32(tmp2);
8452 tmp64 = tcg_temp_new_i64();
8453 tcg_gen_ext_i32_i64(tmp64, tmp);
8454 tcg_temp_free_i32(tmp);
8456 /* Signed 64-bit multiply */
8457 tmp64 = gen_muls_i64_i32(tmp, tmp2);
8462 gen_addq_lo(s, tmp64, rs);
8463 gen_addq_lo(s, tmp64, rd);
8464 } else if (op & 0x40) {
8465 /* 64-bit accumulate. */
8466 gen_addq(s, tmp64, rs, rd);
8468 gen_storeq_reg(s, rs, rd, tmp64);
8469 tcg_temp_free_i64(tmp64);
8474 case 6: case 7: case 14: case 15:
8476 if (((insn >> 24) & 3) == 3) {
8477 /* Translate into the equivalent ARM encoding. */
8478 insn = (insn & 0xe2ffffff) | ((insn & (1 << 28)) >> 4) | (1 << 28);
8479 if (disas_neon_data_insn(env, s, insn))
8482 if (insn & (1 << 28))
8484 if (disas_coproc_insn (env, s, insn))
8488 case 8: case 9: case 10: case 11:
8489 if (insn & (1 << 15)) {
8490 /* Branches, misc control. */
8491 if (insn & 0x5000) {
8492 /* Unconditional branch. */
8493 /* signextend(hw1[10:0]) -> offset[:12]. */
8494 offset = ((int32_t)insn << 5) >> 9 & ~(int32_t)0xfff;
8495 /* hw1[10:0] -> offset[11:1]. */
8496 offset |= (insn & 0x7ff) << 1;
8497 /* (~hw2[13, 11] ^ offset[24]) -> offset[23,22]
8498 offset[24:22] already have the same value because of the
8499 sign extension above. */
8500 offset ^= ((~insn) & (1 << 13)) << 10;
8501 offset ^= ((~insn) & (1 << 11)) << 11;
8503 if (insn & (1 << 14)) {
8504 /* Branch and link. */
8505 tcg_gen_movi_i32(cpu_R[14], s->pc | 1);
8509 if (insn & (1 << 12)) {
8514 offset &= ~(uint32_t)2;
8515 /* thumb2 bx, no need to check */
8516 gen_bx_im(s, offset);
8518 } else if (((insn >> 23) & 7) == 7) {
8520 if (insn & (1 << 13))
8523 if (insn & (1 << 26)) {
8524 /* Secure monitor call (v6Z) */
8525 goto illegal_op; /* not implemented. */
8527 op = (insn >> 20) & 7;
8529 case 0: /* msr cpsr. */
8531 tmp = load_reg(s, rn);
8532 addr = tcg_const_i32(insn & 0xff);
8533 gen_helper_v7m_msr(cpu_env, addr, tmp);
8534 tcg_temp_free_i32(addr);
8535 tcg_temp_free_i32(tmp);
8540 case 1: /* msr spsr. */
8543 tmp = load_reg(s, rn);
8545 msr_mask(env, s, (insn >> 8) & 0xf, op == 1),
8549 case 2: /* cps, nop-hint. */
8550 if (((insn >> 8) & 7) == 0) {
8551 gen_nop_hint(s, insn & 0xff);
8553 /* Implemented as NOP in user mode. */
8558 if (insn & (1 << 10)) {
8559 if (insn & (1 << 7))
8561 if (insn & (1 << 6))
8563 if (insn & (1 << 5))
8565 if (insn & (1 << 9))
8566 imm = CPSR_A | CPSR_I | CPSR_F;
8568 if (insn & (1 << 8)) {
8570 imm |= (insn & 0x1f);
8573 gen_set_psr_im(s, offset, 0, imm);
8576 case 3: /* Special control operations. */
8578 op = (insn >> 4) & 0xf;
8586 /* These execute as NOPs. */
8593 /* Trivial implementation equivalent to bx. */
8594 tmp = load_reg(s, rn);
8597 case 5: /* Exception return. */
8601 if (rn != 14 || rd != 15) {
8604 tmp = load_reg(s, rn);
8605 tcg_gen_subi_i32(tmp, tmp, insn & 0xff);
8606 gen_exception_return(s, tmp);
8608 case 6: /* mrs cpsr. */
8609 tmp = tcg_temp_new_i32();
8611 addr = tcg_const_i32(insn & 0xff);
8612 gen_helper_v7m_mrs(tmp, cpu_env, addr);
8613 tcg_temp_free_i32(addr);
8615 gen_helper_cpsr_read(tmp);
8617 store_reg(s, rd, tmp);
8619 case 7: /* mrs spsr. */
8620 /* Not accessible in user mode. */
8621 if (IS_USER(s) || IS_M(env))
8623 tmp = load_cpu_field(spsr);
8624 store_reg(s, rd, tmp);
8629 /* Conditional branch. */
8630 op = (insn >> 22) & 0xf;
8631 /* Generate a conditional jump to next instruction. */
8632 s->condlabel = gen_new_label();
8633 gen_test_cc(op ^ 1, s->condlabel);
8636 /* offset[11:1] = insn[10:0] */
8637 offset = (insn & 0x7ff) << 1;
8638 /* offset[17:12] = insn[21:16]. */
8639 offset |= (insn & 0x003f0000) >> 4;
8640 /* offset[31:20] = insn[26]. */
8641 offset |= ((int32_t)((insn << 5) & 0x80000000)) >> 11;
8642 /* offset[18] = insn[13]. */
8643 offset |= (insn & (1 << 13)) << 5;
8644 /* offset[19] = insn[11]. */
8645 offset |= (insn & (1 << 11)) << 8;
8647 /* jump to the offset */
8648 gen_jmp(s, s->pc + offset);
8651 /* Data processing immediate. */
8652 if (insn & (1 << 25)) {
8653 if (insn & (1 << 24)) {
8654 if (insn & (1 << 20))
8656 /* Bitfield/Saturate. */
8657 op = (insn >> 21) & 7;
8659 shift = ((insn >> 6) & 3) | ((insn >> 10) & 0x1c);
8661 tmp = tcg_temp_new_i32();
8662 tcg_gen_movi_i32(tmp, 0);
8664 tmp = load_reg(s, rn);
8667 case 2: /* Signed bitfield extract. */
8669 if (shift + imm > 32)
8672 gen_sbfx(tmp, shift, imm);
8674 case 6: /* Unsigned bitfield extract. */
8676 if (shift + imm > 32)
8679 gen_ubfx(tmp, shift, (1u << imm) - 1);
8681 case 3: /* Bitfield insert/clear. */
8684 imm = imm + 1 - shift;
8686 tmp2 = load_reg(s, rd);
8687 gen_bfi(tmp, tmp2, tmp, shift, (1u << imm) - 1);
8688 tcg_temp_free_i32(tmp2);
8693 default: /* Saturate. */
8696 tcg_gen_sari_i32(tmp, tmp, shift);
8698 tcg_gen_shli_i32(tmp, tmp, shift);
8700 tmp2 = tcg_const_i32(imm);
8703 if ((op & 1) && shift == 0)
8704 gen_helper_usat16(tmp, tmp, tmp2);
8706 gen_helper_usat(tmp, tmp, tmp2);
8709 if ((op & 1) && shift == 0)
8710 gen_helper_ssat16(tmp, tmp, tmp2);
8712 gen_helper_ssat(tmp, tmp, tmp2);
8714 tcg_temp_free_i32(tmp2);
8717 store_reg(s, rd, tmp);
8719 imm = ((insn & 0x04000000) >> 15)
8720 | ((insn & 0x7000) >> 4) | (insn & 0xff);
8721 if (insn & (1 << 22)) {
8722 /* 16-bit immediate. */
8723 imm |= (insn >> 4) & 0xf000;
8724 if (insn & (1 << 23)) {
8726 tmp = load_reg(s, rd);
8727 tcg_gen_ext16u_i32(tmp, tmp);
8728 tcg_gen_ori_i32(tmp, tmp, imm << 16);
8731 tmp = tcg_temp_new_i32();
8732 tcg_gen_movi_i32(tmp, imm);
8735 /* Add/sub 12-bit immediate. */
8737 offset = s->pc & ~(uint32_t)3;
8738 if (insn & (1 << 23))
8742 tmp = tcg_temp_new_i32();
8743 tcg_gen_movi_i32(tmp, offset);
8745 tmp = load_reg(s, rn);
8746 if (insn & (1 << 23))
8747 tcg_gen_subi_i32(tmp, tmp, imm);
8749 tcg_gen_addi_i32(tmp, tmp, imm);
8752 store_reg(s, rd, tmp);
8755 int shifter_out = 0;
8756 /* modified 12-bit immediate. */
8757 shift = ((insn & 0x04000000) >> 23) | ((insn & 0x7000) >> 12);
8758 imm = (insn & 0xff);
8761 /* Nothing to do. */
8763 case 1: /* 00XY00XY */
8766 case 2: /* XY00XY00 */
8770 case 3: /* XYXYXYXY */
8774 default: /* Rotated constant. */
8775 shift = (shift << 1) | (imm >> 7);
8777 imm = imm << (32 - shift);
8781 tmp2 = tcg_temp_new_i32();
8782 tcg_gen_movi_i32(tmp2, imm);
8783 rn = (insn >> 16) & 0xf;
8785 tmp = tcg_temp_new_i32();
8786 tcg_gen_movi_i32(tmp, 0);
8788 tmp = load_reg(s, rn);
8790 op = (insn >> 21) & 0xf;
8791 if (gen_thumb2_data_op(s, op, (insn & (1 << 20)) != 0,
8792 shifter_out, tmp, tmp2))
8794 tcg_temp_free_i32(tmp2);
8795 rd = (insn >> 8) & 0xf;
8797 store_reg(s, rd, tmp);
8799 tcg_temp_free_i32(tmp);
8804 case 12: /* Load/store single data item. */
8809 if ((insn & 0x01100000) == 0x01000000) {
8810 if (disas_neon_ls_insn(env, s, insn))
8814 op = ((insn >> 21) & 3) | ((insn >> 22) & 4);
8816 if (!(insn & (1 << 20))) {
8820 /* Byte or halfword load space with dest == r15 : memory hints.
8821 * Catch them early so we don't emit pointless addressing code.
8822 * This space is a mix of:
8823 * PLD/PLDW/PLI, which we implement as NOPs (note that unlike
8824 * the ARM encodings, PLDW space doesn't UNDEF for non-v7MP
8826 * unallocated hints, which must be treated as NOPs
8827 * UNPREDICTABLE space, which we NOP or UNDEF depending on
8828 * which is easiest for the decoding logic
8829 * Some space which must UNDEF
8831 int op1 = (insn >> 23) & 3;
8832 int op2 = (insn >> 6) & 0x3f;
8837 /* UNPREDICTABLE or unallocated hint */
8841 return 0; /* PLD* or unallocated hint */
8843 if ((op2 == 0) || ((op2 & 0x3c) == 0x30)) {
8844 return 0; /* PLD* or unallocated hint */
8846 /* UNDEF space, or an UNPREDICTABLE */
8852 addr = tcg_temp_new_i32();
8854 /* s->pc has already been incremented by 4. */
8855 imm = s->pc & 0xfffffffc;
8856 if (insn & (1 << 23))
8857 imm += insn & 0xfff;
8859 imm -= insn & 0xfff;
8860 tcg_gen_movi_i32(addr, imm);
8862 addr = load_reg(s, rn);
8863 if (insn & (1 << 23)) {
8864 /* Positive offset. */
8866 tcg_gen_addi_i32(addr, addr, imm);
8869 switch ((insn >> 8) & 0xf) {
8870 case 0x0: /* Shifted Register. */
8871 shift = (insn >> 4) & 0xf;
8873 tcg_temp_free_i32(addr);
8876 tmp = load_reg(s, rm);
8878 tcg_gen_shli_i32(tmp, tmp, shift);
8879 tcg_gen_add_i32(addr, addr, tmp);
8880 tcg_temp_free_i32(tmp);
8882 case 0xc: /* Negative offset. */
8883 tcg_gen_addi_i32(addr, addr, -imm);
8885 case 0xe: /* User privilege. */
8886 tcg_gen_addi_i32(addr, addr, imm);
8889 case 0x9: /* Post-decrement. */
8892 case 0xb: /* Post-increment. */
8896 case 0xd: /* Pre-decrement. */
8899 case 0xf: /* Pre-increment. */
8900 tcg_gen_addi_i32(addr, addr, imm);
8904 tcg_temp_free_i32(addr);
8909 if (insn & (1 << 20)) {
8912 case 0: tmp = gen_ld8u(addr, user); break;
8913 case 4: tmp = gen_ld8s(addr, user); break;
8914 case 1: tmp = gen_ld16u(addr, user); break;
8915 case 5: tmp = gen_ld16s(addr, user); break;
8916 case 2: tmp = gen_ld32(addr, user); break;
8918 tcg_temp_free_i32(addr);
8924 store_reg(s, rs, tmp);
8928 tmp = load_reg(s, rs);
8930 case 0: gen_st8(tmp, addr, user); break;
8931 case 1: gen_st16(tmp, addr, user); break;
8932 case 2: gen_st32(tmp, addr, user); break;
8934 tcg_temp_free_i32(addr);
8939 tcg_gen_addi_i32(addr, addr, imm);
8941 store_reg(s, rn, addr);
8943 tcg_temp_free_i32(addr);
8955 static void disas_thumb_insn(CPUState *env, DisasContext *s)
8957 uint32_t val, insn, op, rm, rn, rd, shift, cond;
8964 if (s->condexec_mask) {
8965 cond = s->condexec_cond;
8966 if (cond != 0x0e) { /* Skip conditional when condition is AL. */
8967 s->condlabel = gen_new_label();
8968 gen_test_cc(cond ^ 1, s->condlabel);
8973 insn = lduw_code(s->pc);
8976 switch (insn >> 12) {
8980 op = (insn >> 11) & 3;
8983 rn = (insn >> 3) & 7;
8984 tmp = load_reg(s, rn);
8985 if (insn & (1 << 10)) {
8987 tmp2 = tcg_temp_new_i32();
8988 tcg_gen_movi_i32(tmp2, (insn >> 6) & 7);
8991 rm = (insn >> 6) & 7;
8992 tmp2 = load_reg(s, rm);
8994 if (insn & (1 << 9)) {
8995 if (s->condexec_mask)
8996 tcg_gen_sub_i32(tmp, tmp, tmp2);
8998 gen_helper_sub_cc(tmp, tmp, tmp2);
9000 if (s->condexec_mask)
9001 tcg_gen_add_i32(tmp, tmp, tmp2);
9003 gen_helper_add_cc(tmp, tmp, tmp2);
9005 tcg_temp_free_i32(tmp2);
9006 store_reg(s, rd, tmp);
9008 /* shift immediate */
9009 rm = (insn >> 3) & 7;
9010 shift = (insn >> 6) & 0x1f;
9011 tmp = load_reg(s, rm);
9012 gen_arm_shift_im(tmp, op, shift, s->condexec_mask == 0);
9013 if (!s->condexec_mask)
9015 store_reg(s, rd, tmp);
9019 /* arithmetic large immediate */
9020 op = (insn >> 11) & 3;
9021 rd = (insn >> 8) & 0x7;
9022 if (op == 0) { /* mov */
9023 tmp = tcg_temp_new_i32();
9024 tcg_gen_movi_i32(tmp, insn & 0xff);
9025 if (!s->condexec_mask)
9027 store_reg(s, rd, tmp);
9029 tmp = load_reg(s, rd);
9030 tmp2 = tcg_temp_new_i32();
9031 tcg_gen_movi_i32(tmp2, insn & 0xff);
9034 gen_helper_sub_cc(tmp, tmp, tmp2);
9035 tcg_temp_free_i32(tmp);
9036 tcg_temp_free_i32(tmp2);
9039 if (s->condexec_mask)
9040 tcg_gen_add_i32(tmp, tmp, tmp2);
9042 gen_helper_add_cc(tmp, tmp, tmp2);
9043 tcg_temp_free_i32(tmp2);
9044 store_reg(s, rd, tmp);
9047 if (s->condexec_mask)
9048 tcg_gen_sub_i32(tmp, tmp, tmp2);
9050 gen_helper_sub_cc(tmp, tmp, tmp2);
9051 tcg_temp_free_i32(tmp2);
9052 store_reg(s, rd, tmp);
9058 if (insn & (1 << 11)) {
9059 rd = (insn >> 8) & 7;
9060 /* load pc-relative. Bit 1 of PC is ignored. */
9061 val = s->pc + 2 + ((insn & 0xff) * 4);
9062 val &= ~(uint32_t)2;
9063 addr = tcg_temp_new_i32();
9064 tcg_gen_movi_i32(addr, val);
9065 tmp = gen_ld32(addr, IS_USER(s));
9066 tcg_temp_free_i32(addr);
9067 store_reg(s, rd, tmp);
9070 if (insn & (1 << 10)) {
9071 /* data processing extended or blx */
9072 rd = (insn & 7) | ((insn >> 4) & 8);
9073 rm = (insn >> 3) & 0xf;
9074 op = (insn >> 8) & 3;
9077 tmp = load_reg(s, rd);
9078 tmp2 = load_reg(s, rm);
9079 tcg_gen_add_i32(tmp, tmp, tmp2);
9080 tcg_temp_free_i32(tmp2);
9081 store_reg(s, rd, tmp);
9084 tmp = load_reg(s, rd);
9085 tmp2 = load_reg(s, rm);
9086 gen_helper_sub_cc(tmp, tmp, tmp2);
9087 tcg_temp_free_i32(tmp2);
9088 tcg_temp_free_i32(tmp);
9090 case 2: /* mov/cpy */
9091 tmp = load_reg(s, rm);
9092 store_reg(s, rd, tmp);
9094 case 3:/* branch [and link] exchange thumb register */
9095 tmp = load_reg(s, rm);
9096 if (insn & (1 << 7)) {
9098 val = (uint32_t)s->pc | 1;
9099 tmp2 = tcg_temp_new_i32();
9100 tcg_gen_movi_i32(tmp2, val);
9101 store_reg(s, 14, tmp2);
9103 /* already thumb, no need to check */
9110 /* data processing register */
9112 rm = (insn >> 3) & 7;
9113 op = (insn >> 6) & 0xf;
9114 if (op == 2 || op == 3 || op == 4 || op == 7) {
9115 /* the shift/rotate ops want the operands backwards */
9124 if (op == 9) { /* neg */
9125 tmp = tcg_temp_new_i32();
9126 tcg_gen_movi_i32(tmp, 0);
9127 } else if (op != 0xf) { /* mvn doesn't read its first operand */
9128 tmp = load_reg(s, rd);
9133 tmp2 = load_reg(s, rm);
9136 tcg_gen_and_i32(tmp, tmp, tmp2);
9137 if (!s->condexec_mask)
9141 tcg_gen_xor_i32(tmp, tmp, tmp2);
9142 if (!s->condexec_mask)
9146 if (s->condexec_mask) {
9147 gen_helper_shl(tmp2, tmp2, tmp);
9149 gen_helper_shl_cc(tmp2, tmp2, tmp);
9154 if (s->condexec_mask) {
9155 gen_helper_shr(tmp2, tmp2, tmp);
9157 gen_helper_shr_cc(tmp2, tmp2, tmp);
9162 if (s->condexec_mask) {
9163 gen_helper_sar(tmp2, tmp2, tmp);
9165 gen_helper_sar_cc(tmp2, tmp2, tmp);
9170 if (s->condexec_mask)
9173 gen_helper_adc_cc(tmp, tmp, tmp2);
9176 if (s->condexec_mask)
9177 gen_sub_carry(tmp, tmp, tmp2);
9179 gen_helper_sbc_cc(tmp, tmp, tmp2);
9182 if (s->condexec_mask) {
9183 tcg_gen_andi_i32(tmp, tmp, 0x1f);
9184 tcg_gen_rotr_i32(tmp2, tmp2, tmp);
9186 gen_helper_ror_cc(tmp2, tmp2, tmp);
9191 tcg_gen_and_i32(tmp, tmp, tmp2);
9196 if (s->condexec_mask)
9197 tcg_gen_neg_i32(tmp, tmp2);
9199 gen_helper_sub_cc(tmp, tmp, tmp2);
9202 gen_helper_sub_cc(tmp, tmp, tmp2);
9206 gen_helper_add_cc(tmp, tmp, tmp2);
9210 tcg_gen_or_i32(tmp, tmp, tmp2);
9211 if (!s->condexec_mask)
9215 tcg_gen_mul_i32(tmp, tmp, tmp2);
9216 if (!s->condexec_mask)
9220 tcg_gen_andc_i32(tmp, tmp, tmp2);
9221 if (!s->condexec_mask)
9225 tcg_gen_not_i32(tmp2, tmp2);
9226 if (!s->condexec_mask)
9234 store_reg(s, rm, tmp2);
9236 tcg_temp_free_i32(tmp);
9238 store_reg(s, rd, tmp);
9239 tcg_temp_free_i32(tmp2);
9242 tcg_temp_free_i32(tmp);
9243 tcg_temp_free_i32(tmp2);
9248 /* load/store register offset. */
9250 rn = (insn >> 3) & 7;
9251 rm = (insn >> 6) & 7;
9252 op = (insn >> 9) & 7;
9253 addr = load_reg(s, rn);
9254 tmp = load_reg(s, rm);
9255 tcg_gen_add_i32(addr, addr, tmp);
9256 tcg_temp_free_i32(tmp);
9258 if (op < 3) /* store */
9259 tmp = load_reg(s, rd);
9263 gen_st32(tmp, addr, IS_USER(s));
9266 gen_st16(tmp, addr, IS_USER(s));
9269 gen_st8(tmp, addr, IS_USER(s));
9272 tmp = gen_ld8s(addr, IS_USER(s));
9275 tmp = gen_ld32(addr, IS_USER(s));
9278 tmp = gen_ld16u(addr, IS_USER(s));
9281 tmp = gen_ld8u(addr, IS_USER(s));
9284 tmp = gen_ld16s(addr, IS_USER(s));
9287 if (op >= 3) /* load */
9288 store_reg(s, rd, tmp);
9289 tcg_temp_free_i32(addr);
9293 /* load/store word immediate offset */
9295 rn = (insn >> 3) & 7;
9296 addr = load_reg(s, rn);
9297 val = (insn >> 4) & 0x7c;
9298 tcg_gen_addi_i32(addr, addr, val);
9300 if (insn & (1 << 11)) {
9302 tmp = gen_ld32(addr, IS_USER(s));
9303 store_reg(s, rd, tmp);
9306 tmp = load_reg(s, rd);
9307 gen_st32(tmp, addr, IS_USER(s));
9309 tcg_temp_free_i32(addr);
9313 /* load/store byte immediate offset */
9315 rn = (insn >> 3) & 7;
9316 addr = load_reg(s, rn);
9317 val = (insn >> 6) & 0x1f;
9318 tcg_gen_addi_i32(addr, addr, val);
9320 if (insn & (1 << 11)) {
9322 tmp = gen_ld8u(addr, IS_USER(s));
9323 store_reg(s, rd, tmp);
9326 tmp = load_reg(s, rd);
9327 gen_st8(tmp, addr, IS_USER(s));
9329 tcg_temp_free_i32(addr);
9333 /* load/store halfword immediate offset */
9335 rn = (insn >> 3) & 7;
9336 addr = load_reg(s, rn);
9337 val = (insn >> 5) & 0x3e;
9338 tcg_gen_addi_i32(addr, addr, val);
9340 if (insn & (1 << 11)) {
9342 tmp = gen_ld16u(addr, IS_USER(s));
9343 store_reg(s, rd, tmp);
9346 tmp = load_reg(s, rd);
9347 gen_st16(tmp, addr, IS_USER(s));
9349 tcg_temp_free_i32(addr);
9353 /* load/store from stack */
9354 rd = (insn >> 8) & 7;
9355 addr = load_reg(s, 13);
9356 val = (insn & 0xff) * 4;
9357 tcg_gen_addi_i32(addr, addr, val);
9359 if (insn & (1 << 11)) {
9361 tmp = gen_ld32(addr, IS_USER(s));
9362 store_reg(s, rd, tmp);
9365 tmp = load_reg(s, rd);
9366 gen_st32(tmp, addr, IS_USER(s));
9368 tcg_temp_free_i32(addr);
9372 /* add to high reg */
9373 rd = (insn >> 8) & 7;
9374 if (insn & (1 << 11)) {
9376 tmp = load_reg(s, 13);
9378 /* PC. bit 1 is ignored. */
9379 tmp = tcg_temp_new_i32();
9380 tcg_gen_movi_i32(tmp, (s->pc + 2) & ~(uint32_t)2);
9382 val = (insn & 0xff) * 4;
9383 tcg_gen_addi_i32(tmp, tmp, val);
9384 store_reg(s, rd, tmp);
9389 op = (insn >> 8) & 0xf;
9392 /* adjust stack pointer */
9393 tmp = load_reg(s, 13);
9394 val = (insn & 0x7f) * 4;
9395 if (insn & (1 << 7))
9396 val = -(int32_t)val;
9397 tcg_gen_addi_i32(tmp, tmp, val);
9398 store_reg(s, 13, tmp);
9401 case 2: /* sign/zero extend. */
9404 rm = (insn >> 3) & 7;
9405 tmp = load_reg(s, rm);
9406 switch ((insn >> 6) & 3) {
9407 case 0: gen_sxth(tmp); break;
9408 case 1: gen_sxtb(tmp); break;
9409 case 2: gen_uxth(tmp); break;
9410 case 3: gen_uxtb(tmp); break;
9412 store_reg(s, rd, tmp);
9414 case 4: case 5: case 0xc: case 0xd:
9416 addr = load_reg(s, 13);
9417 if (insn & (1 << 8))
9421 for (i = 0; i < 8; i++) {
9422 if (insn & (1 << i))
9425 if ((insn & (1 << 11)) == 0) {
9426 tcg_gen_addi_i32(addr, addr, -offset);
9428 for (i = 0; i < 8; i++) {
9429 if (insn & (1 << i)) {
9430 if (insn & (1 << 11)) {
9432 tmp = gen_ld32(addr, IS_USER(s));
9433 store_reg(s, i, tmp);
9436 tmp = load_reg(s, i);
9437 gen_st32(tmp, addr, IS_USER(s));
9439 /* advance to the next address. */
9440 tcg_gen_addi_i32(addr, addr, 4);
9444 if (insn & (1 << 8)) {
9445 if (insn & (1 << 11)) {
9447 tmp = gen_ld32(addr, IS_USER(s));
9448 /* don't set the pc until the rest of the instruction
9452 tmp = load_reg(s, 14);
9453 gen_st32(tmp, addr, IS_USER(s));
9455 tcg_gen_addi_i32(addr, addr, 4);
9457 if ((insn & (1 << 11)) == 0) {
9458 tcg_gen_addi_i32(addr, addr, -offset);
9460 /* write back the new stack pointer */
9461 store_reg(s, 13, addr);
9462 /* set the new PC value */
9463 if ((insn & 0x0900) == 0x0900) {
9464 store_reg_from_load(env, s, 15, tmp);
9468 case 1: case 3: case 9: case 11: /* czb */
9470 tmp = load_reg(s, rm);
9471 s->condlabel = gen_new_label();
9473 if (insn & (1 << 11))
9474 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, s->condlabel);
9476 tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, s->condlabel);
9477 tcg_temp_free_i32(tmp);
9478 offset = ((insn & 0xf8) >> 2) | (insn & 0x200) >> 3;
9479 val = (uint32_t)s->pc + 2;
9484 case 15: /* IT, nop-hint. */
9485 if ((insn & 0xf) == 0) {
9486 gen_nop_hint(s, (insn >> 4) & 0xf);
9490 s->condexec_cond = (insn >> 4) & 0xe;
9491 s->condexec_mask = insn & 0x1f;
9492 /* No actual code generated for this insn, just setup state. */
9495 case 0xe: /* bkpt */
9497 gen_exception_insn(s, 2, EXCP_BKPT);
9502 rn = (insn >> 3) & 0x7;
9504 tmp = load_reg(s, rn);
9505 switch ((insn >> 6) & 3) {
9506 case 0: tcg_gen_bswap32_i32(tmp, tmp); break;
9507 case 1: gen_rev16(tmp); break;
9508 case 3: gen_revsh(tmp); break;
9509 default: goto illegal_op;
9511 store_reg(s, rd, tmp);
9519 tmp = tcg_const_i32((insn & (1 << 4)) != 0);
9522 addr = tcg_const_i32(16);
9523 gen_helper_v7m_msr(cpu_env, addr, tmp);
9524 tcg_temp_free_i32(addr);
9528 addr = tcg_const_i32(17);
9529 gen_helper_v7m_msr(cpu_env, addr, tmp);
9530 tcg_temp_free_i32(addr);
9532 tcg_temp_free_i32(tmp);
9535 if (insn & (1 << 4))
9536 shift = CPSR_A | CPSR_I | CPSR_F;
9539 gen_set_psr_im(s, ((insn & 7) << 6), 0, shift);
9550 /* load/store multiple */
9552 TCGV_UNUSED(loaded_var);
9553 rn = (insn >> 8) & 0x7;
9554 addr = load_reg(s, rn);
9555 for (i = 0; i < 8; i++) {
9556 if (insn & (1 << i)) {
9557 if (insn & (1 << 11)) {
9559 tmp = gen_ld32(addr, IS_USER(s));
9563 store_reg(s, i, tmp);
9567 tmp = load_reg(s, i);
9568 gen_st32(tmp, addr, IS_USER(s));
9570 /* advance to the next address */
9571 tcg_gen_addi_i32(addr, addr, 4);
9574 if ((insn & (1 << rn)) == 0) {
9575 /* base reg not in list: base register writeback */
9576 store_reg(s, rn, addr);
9578 /* base reg in list: if load, complete it now */
9579 if (insn & (1 << 11)) {
9580 store_reg(s, rn, loaded_var);
9582 tcg_temp_free_i32(addr);
9587 /* conditional branch or swi */
9588 cond = (insn >> 8) & 0xf;
9594 gen_set_pc_im(s->pc);
9595 s->is_jmp = DISAS_SWI;
9598 /* generate a conditional jump to next instruction */
9599 s->condlabel = gen_new_label();
9600 gen_test_cc(cond ^ 1, s->condlabel);
9603 /* jump to the offset */
9604 val = (uint32_t)s->pc + 2;
9605 offset = ((int32_t)insn << 24) >> 24;
9611 if (insn & (1 << 11)) {
9612 if (disas_thumb2_insn(env, s, insn))
9616 /* unconditional branch */
9617 val = (uint32_t)s->pc;
9618 offset = ((int32_t)insn << 21) >> 21;
9619 val += (offset << 1) + 2;
9624 if (disas_thumb2_insn(env, s, insn))
9630 gen_exception_insn(s, 4, EXCP_UDEF);
9634 gen_exception_insn(s, 2, EXCP_UDEF);
9637 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
9638 basic block 'tb'. If search_pc is TRUE, also generate PC
9639 information for each intermediate instruction. */
9640 static inline void gen_intermediate_code_internal(CPUState *env,
9641 TranslationBlock *tb,
9644 DisasContext dc1, *dc = &dc1;
9646 uint16_t *gen_opc_end;
9648 target_ulong pc_start;
9649 uint32_t next_page_start;
9653 /* generate intermediate code */
9658 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
9660 dc->is_jmp = DISAS_NEXT;
9662 dc->singlestep_enabled = env->singlestep_enabled;
9664 dc->thumb = ARM_TBFLAG_THUMB(tb->flags);
9665 dc->condexec_mask = (ARM_TBFLAG_CONDEXEC(tb->flags) & 0xf) << 1;
9666 dc->condexec_cond = ARM_TBFLAG_CONDEXEC(tb->flags) >> 4;
9667 #if !defined(CONFIG_USER_ONLY)
9668 dc->user = (ARM_TBFLAG_PRIV(tb->flags) == 0);
9670 dc->vfp_enabled = ARM_TBFLAG_VFPEN(tb->flags);
9671 dc->vec_len = ARM_TBFLAG_VECLEN(tb->flags);
9672 dc->vec_stride = ARM_TBFLAG_VECSTRIDE(tb->flags);
9673 cpu_F0s = tcg_temp_new_i32();
9674 cpu_F1s = tcg_temp_new_i32();
9675 cpu_F0d = tcg_temp_new_i64();
9676 cpu_F1d = tcg_temp_new_i64();
9679 /* FIXME: cpu_M0 can probably be the same as cpu_V0. */
9680 cpu_M0 = tcg_temp_new_i64();
9681 next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
9684 max_insns = tb->cflags & CF_COUNT_MASK;
9686 max_insns = CF_COUNT_MASK;
9690 tcg_clear_temp_count();
9692 /* A note on handling of the condexec (IT) bits:
9694 * We want to avoid the overhead of having to write the updated condexec
9695 * bits back to the CPUState for every instruction in an IT block. So:
9696 * (1) if the condexec bits are not already zero then we write
9697 * zero back into the CPUState now. This avoids complications trying
9698 * to do it at the end of the block. (For example if we don't do this
9699 * it's hard to identify whether we can safely skip writing condexec
9700 * at the end of the TB, which we definitely want to do for the case
9701 * where a TB doesn't do anything with the IT state at all.)
9702 * (2) if we are going to leave the TB then we call gen_set_condexec()
9703 * which will write the correct value into CPUState if zero is wrong.
9704 * This is done both for leaving the TB at the end, and for leaving
9705 * it because of an exception we know will happen, which is done in
9706 * gen_exception_insn(). The latter is necessary because we need to
9707 * leave the TB with the PC/IT state just prior to execution of the
9708 * instruction which caused the exception.
9709 * (3) if we leave the TB unexpectedly (eg a data abort on a load)
9710 * then the CPUState will be wrong and we need to reset it.
9711 * This is handled in the same way as restoration of the
9712 * PC in these situations: we will be called again with search_pc=1
9713 * and generate a mapping of the condexec bits for each PC in
9714 * gen_opc_condexec_bits[]. restore_state_to_opc() then uses
9715 * this to restore the condexec bits.
9717 * Note that there are no instructions which can read the condexec
9718 * bits, and none which can write non-static values to them, so
9719 * we don't need to care about whether CPUState is correct in the
9723 /* Reset the conditional execution bits immediately. This avoids
9724 complications trying to do it at the end of the block. */
9725 if (dc->condexec_mask || dc->condexec_cond)
9727 TCGv tmp = tcg_temp_new_i32();
9728 tcg_gen_movi_i32(tmp, 0);
9729 store_cpu_field(tmp, condexec_bits);
9732 #ifdef CONFIG_USER_ONLY
9733 /* Intercept jump to the magic kernel page. */
9734 if (dc->pc >= 0xffff0000) {
9735 /* We always get here via a jump, so know we are not in a
9736 conditional execution block. */
9737 gen_exception(EXCP_KERNEL_TRAP);
9738 dc->is_jmp = DISAS_UPDATE;
9742 if (dc->pc >= 0xfffffff0 && IS_M(env)) {
9743 /* We always get here via a jump, so know we are not in a
9744 conditional execution block. */
9745 gen_exception(EXCP_EXCEPTION_EXIT);
9746 dc->is_jmp = DISAS_UPDATE;
9751 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
9752 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
9753 if (bp->pc == dc->pc) {
9754 gen_exception_insn(dc, 0, EXCP_DEBUG);
9755 /* Advance PC so that clearing the breakpoint will
9756 invalidate this TB. */
9758 goto done_generating;
9764 j = gen_opc_ptr - gen_opc_buf;
9768 gen_opc_instr_start[lj++] = 0;
9770 gen_opc_pc[lj] = dc->pc;
9771 gen_opc_condexec_bits[lj] = (dc->condexec_cond << 4) | (dc->condexec_mask >> 1);
9772 gen_opc_instr_start[lj] = 1;
9773 gen_opc_icount[lj] = num_insns;
9776 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
9779 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
9780 tcg_gen_debug_insn_start(dc->pc);
9784 disas_thumb_insn(env, dc);
9785 if (dc->condexec_mask) {
9786 dc->condexec_cond = (dc->condexec_cond & 0xe)
9787 | ((dc->condexec_mask >> 4) & 1);
9788 dc->condexec_mask = (dc->condexec_mask << 1) & 0x1f;
9789 if (dc->condexec_mask == 0) {
9790 dc->condexec_cond = 0;
9794 disas_arm_insn(env, dc);
9797 if (dc->condjmp && !dc->is_jmp) {
9798 gen_set_label(dc->condlabel);
9802 if (tcg_check_temp_count()) {
9803 fprintf(stderr, "TCG temporary leak before %08x\n", dc->pc);
9806 /* Translation stops when a conditional branch is encountered.
9807 * Otherwise the subsequent code could get translated several times.
9808 * Also stop translation when a page boundary is reached. This
9809 * ensures prefetch aborts occur at the right place. */
9811 } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end &&
9812 !env->singlestep_enabled &&
9814 dc->pc < next_page_start &&
9815 num_insns < max_insns);
9817 if (tb->cflags & CF_LAST_IO) {
9819 /* FIXME: This can theoretically happen with self-modifying
9821 cpu_abort(env, "IO on conditional branch instruction");
9826 /* At this stage dc->condjmp will only be set when the skipped
9827 instruction was a conditional branch or trap, and the PC has
9828 already been written. */
9829 if (unlikely(env->singlestep_enabled)) {
9830 /* Make sure the pc is updated, and raise a debug exception. */
9832 gen_set_condexec(dc);
9833 if (dc->is_jmp == DISAS_SWI) {
9834 gen_exception(EXCP_SWI);
9836 gen_exception(EXCP_DEBUG);
9838 gen_set_label(dc->condlabel);
9840 if (dc->condjmp || !dc->is_jmp) {
9841 gen_set_pc_im(dc->pc);
9844 gen_set_condexec(dc);
9845 if (dc->is_jmp == DISAS_SWI && !dc->condjmp) {
9846 gen_exception(EXCP_SWI);
9848 /* FIXME: Single stepping a WFI insn will not halt
9850 gen_exception(EXCP_DEBUG);
9853 /* While branches must always occur at the end of an IT block,
9854 there are a few other things that can cause us to terminate
9855 the TB in the middel of an IT block:
9856 - Exception generating instructions (bkpt, swi, undefined).
9858 - Hardware watchpoints.
9859 Hardware breakpoints have already been handled and skip this code.
9861 gen_set_condexec(dc);
9862 switch(dc->is_jmp) {
9864 gen_goto_tb(dc, 1, dc->pc);
9869 /* indicate that the hash table must be used to find the next TB */
9873 /* nothing more to generate */
9879 gen_exception(EXCP_SWI);
9883 gen_set_label(dc->condlabel);
9884 gen_set_condexec(dc);
9885 gen_goto_tb(dc, 1, dc->pc);
9891 gen_icount_end(tb, num_insns);
9892 *gen_opc_ptr = INDEX_op_end;
9895 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
9896 qemu_log("----------------\n");
9897 qemu_log("IN: %s\n", lookup_symbol(pc_start));
9898 log_target_disas(pc_start, dc->pc - pc_start, dc->thumb);
9903 j = gen_opc_ptr - gen_opc_buf;
9906 gen_opc_instr_start[lj++] = 0;
9908 tb->size = dc->pc - pc_start;
9909 tb->icount = num_insns;
9913 void gen_intermediate_code(CPUState *env, TranslationBlock *tb)
9915 gen_intermediate_code_internal(env, tb, 0);
9918 void gen_intermediate_code_pc(CPUState *env, TranslationBlock *tb)
9920 gen_intermediate_code_internal(env, tb, 1);
9923 static const char *cpu_mode_names[16] = {
9924 "usr", "fiq", "irq", "svc", "???", "???", "???", "abt",
9925 "???", "???", "???", "und", "???", "???", "???", "sys"
9928 void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
9938 /* ??? This assumes float64 and double have the same layout.
9939 Oh well, it's only debug dumps. */
9948 cpu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
9950 cpu_fprintf(f, "\n");
9952 cpu_fprintf(f, " ");
9954 psr = cpsr_read(env);
9955 cpu_fprintf(f, "PSR=%08x %c%c%c%c %c %s%d\n",
9957 psr & (1 << 31) ? 'N' : '-',
9958 psr & (1 << 30) ? 'Z' : '-',
9959 psr & (1 << 29) ? 'C' : '-',
9960 psr & (1 << 28) ? 'V' : '-',
9961 psr & CPSR_T ? 'T' : 'A',
9962 cpu_mode_names[psr & 0xf], (psr & 0x10) ? 32 : 26);
9965 for (i = 0; i < 16; i++) {
9966 d.d = env->vfp.regs[i];
9970 cpu_fprintf(f, "s%02d=%08x(%8g) s%02d=%08x(%8g) d%02d=%08x%08x(%8g)\n",
9971 i * 2, (int)s0.i, s0.s,
9972 i * 2 + 1, (int)s1.i, s1.s,
9973 i, (int)(uint32_t)d.l.upper, (int)(uint32_t)d.l.lower,
9976 cpu_fprintf(f, "FPSCR: %08x\n", (int)env->vfp.xregs[ARM_VFP_FPSCR]);
9980 void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
9982 env->regs[15] = gen_opc_pc[pc_pos];
9983 env->condexec_bits = gen_opc_condexec_bits[pc_pos];