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_5J 0
38 #define ENABLE_ARCH_6 arm_feature(env, ARM_FEATURE_V6)
39 #define ENABLE_ARCH_6K arm_feature(env, ARM_FEATURE_V6K)
40 #define ENABLE_ARCH_6T2 arm_feature(env, ARM_FEATURE_THUMB2)
41 #define ENABLE_ARCH_7 arm_feature(env, ARM_FEATURE_V7)
43 #define ARCH(x) do { if (!ENABLE_ARCH_##x) goto illegal_op; } while(0)
45 /* internal defines */
46 typedef struct DisasContext
{
49 /* Nonzero if this instruction has been conditionally skipped. */
51 /* The label that will be jumped to when the instruction is skipped. */
53 /* Thumb-2 condtional execution bits. */
56 struct TranslationBlock
*tb
;
57 int singlestep_enabled
;
59 #if !defined(CONFIG_USER_ONLY)
67 static uint32_t gen_opc_condexec_bits
[OPC_BUF_SIZE
];
69 #if defined(CONFIG_USER_ONLY)
72 #define IS_USER(s) (s->user)
75 /* These instructions trap after executing, so defer them until after the
76 conditional executions state has been updated. */
80 static TCGv_ptr cpu_env
;
81 /* We reuse the same 64-bit temporaries for efficiency. */
82 static TCGv_i64 cpu_V0
, cpu_V1
, cpu_M0
;
83 static TCGv_i32 cpu_R
[16];
84 static TCGv_i32 cpu_exclusive_addr
;
85 static TCGv_i32 cpu_exclusive_val
;
86 static TCGv_i32 cpu_exclusive_high
;
87 #ifdef CONFIG_USER_ONLY
88 static TCGv_i32 cpu_exclusive_test
;
89 static TCGv_i32 cpu_exclusive_info
;
92 /* FIXME: These should be removed. */
93 static TCGv cpu_F0s
, cpu_F1s
;
94 static TCGv_i64 cpu_F0d
, cpu_F1d
;
96 #include "gen-icount.h"
98 static const char *regnames
[] =
99 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
100 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" };
102 /* initialize TCG globals. */
103 void arm_translate_init(void)
107 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
109 for (i
= 0; i
< 16; i
++) {
110 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
111 offsetof(CPUState
, regs
[i
]),
114 cpu_exclusive_addr
= tcg_global_mem_new_i32(TCG_AREG0
,
115 offsetof(CPUState
, exclusive_addr
), "exclusive_addr");
116 cpu_exclusive_val
= tcg_global_mem_new_i32(TCG_AREG0
,
117 offsetof(CPUState
, exclusive_val
), "exclusive_val");
118 cpu_exclusive_high
= tcg_global_mem_new_i32(TCG_AREG0
,
119 offsetof(CPUState
, exclusive_high
), "exclusive_high");
120 #ifdef CONFIG_USER_ONLY
121 cpu_exclusive_test
= tcg_global_mem_new_i32(TCG_AREG0
,
122 offsetof(CPUState
, exclusive_test
), "exclusive_test");
123 cpu_exclusive_info
= tcg_global_mem_new_i32(TCG_AREG0
,
124 offsetof(CPUState
, exclusive_info
), "exclusive_info");
131 static int num_temps
;
133 /* Allocate a temporary variable. */
134 static TCGv_i32
new_tmp(void)
137 return tcg_temp_new_i32();
140 /* Release a temporary variable. */
141 static void dead_tmp(TCGv tmp
)
147 static inline TCGv
load_cpu_offset(int offset
)
149 TCGv tmp
= new_tmp();
150 tcg_gen_ld_i32(tmp
, cpu_env
, offset
);
154 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUState, name))
156 static inline void store_cpu_offset(TCGv var
, int offset
)
158 tcg_gen_st_i32(var
, cpu_env
, offset
);
162 #define store_cpu_field(var, name) \
163 store_cpu_offset(var, offsetof(CPUState, name))
165 /* Set a variable to the value of a CPU register. */
166 static void load_reg_var(DisasContext
*s
, TCGv var
, int reg
)
170 /* normaly, since we updated PC, we need only to add one insn */
172 addr
= (long)s
->pc
+ 2;
174 addr
= (long)s
->pc
+ 4;
175 tcg_gen_movi_i32(var
, addr
);
177 tcg_gen_mov_i32(var
, cpu_R
[reg
]);
181 /* Create a new temporary and set it to the value of a CPU register. */
182 static inline TCGv
load_reg(DisasContext
*s
, int reg
)
184 TCGv tmp
= new_tmp();
185 load_reg_var(s
, tmp
, reg
);
189 /* Set a CPU register. The source must be a temporary and will be
191 static void store_reg(DisasContext
*s
, int reg
, TCGv var
)
194 tcg_gen_andi_i32(var
, var
, ~1);
195 s
->is_jmp
= DISAS_JUMP
;
197 tcg_gen_mov_i32(cpu_R
[reg
], var
);
201 /* Value extensions. */
202 #define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
203 #define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
204 #define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
205 #define gen_sxth(var) tcg_gen_ext16s_i32(var, var)
207 #define gen_sxtb16(var) gen_helper_sxtb16(var, var)
208 #define gen_uxtb16(var) gen_helper_uxtb16(var, var)
211 static inline void gen_set_cpsr(TCGv var
, uint32_t mask
)
213 TCGv tmp_mask
= tcg_const_i32(mask
);
214 gen_helper_cpsr_write(var
, tmp_mask
);
215 tcg_temp_free_i32(tmp_mask
);
217 /* Set NZCV flags from the high 4 bits of var. */
218 #define gen_set_nzcv(var) gen_set_cpsr(var, CPSR_NZCV)
220 static void gen_exception(int excp
)
222 TCGv tmp
= new_tmp();
223 tcg_gen_movi_i32(tmp
, excp
);
224 gen_helper_exception(tmp
);
228 static void gen_smul_dual(TCGv a
, TCGv b
)
230 TCGv tmp1
= new_tmp();
231 TCGv tmp2
= new_tmp();
232 tcg_gen_ext16s_i32(tmp1
, a
);
233 tcg_gen_ext16s_i32(tmp2
, b
);
234 tcg_gen_mul_i32(tmp1
, tmp1
, tmp2
);
236 tcg_gen_sari_i32(a
, a
, 16);
237 tcg_gen_sari_i32(b
, b
, 16);
238 tcg_gen_mul_i32(b
, b
, a
);
239 tcg_gen_mov_i32(a
, tmp1
);
243 /* Byteswap each halfword. */
244 static void gen_rev16(TCGv var
)
246 TCGv tmp
= new_tmp();
247 tcg_gen_shri_i32(tmp
, var
, 8);
248 tcg_gen_andi_i32(tmp
, tmp
, 0x00ff00ff);
249 tcg_gen_shli_i32(var
, var
, 8);
250 tcg_gen_andi_i32(var
, var
, 0xff00ff00);
251 tcg_gen_or_i32(var
, var
, tmp
);
255 /* Byteswap low halfword and sign extend. */
256 static void gen_revsh(TCGv var
)
258 tcg_gen_ext16u_i32(var
, var
);
259 tcg_gen_bswap16_i32(var
, var
);
260 tcg_gen_ext16s_i32(var
, var
);
263 /* Unsigned bitfield extract. */
264 static void gen_ubfx(TCGv var
, int shift
, uint32_t mask
)
267 tcg_gen_shri_i32(var
, var
, shift
);
268 tcg_gen_andi_i32(var
, var
, mask
);
271 /* Signed bitfield extract. */
272 static void gen_sbfx(TCGv var
, int shift
, int width
)
277 tcg_gen_sari_i32(var
, var
, shift
);
278 if (shift
+ width
< 32) {
279 signbit
= 1u << (width
- 1);
280 tcg_gen_andi_i32(var
, var
, (1u << width
) - 1);
281 tcg_gen_xori_i32(var
, var
, signbit
);
282 tcg_gen_subi_i32(var
, var
, signbit
);
286 /* Bitfield insertion. Insert val into base. Clobbers base and val. */
287 static void gen_bfi(TCGv dest
, TCGv base
, TCGv val
, int shift
, uint32_t mask
)
289 tcg_gen_andi_i32(val
, val
, mask
);
290 tcg_gen_shli_i32(val
, val
, shift
);
291 tcg_gen_andi_i32(base
, base
, ~(mask
<< shift
));
292 tcg_gen_or_i32(dest
, base
, val
);
295 /* Return (b << 32) + a. Mark inputs as dead */
296 static TCGv_i64
gen_addq_msw(TCGv_i64 a
, TCGv b
)
298 TCGv_i64 tmp64
= tcg_temp_new_i64();
300 tcg_gen_extu_i32_i64(tmp64
, b
);
302 tcg_gen_shli_i64(tmp64
, tmp64
, 32);
303 tcg_gen_add_i64(a
, tmp64
, a
);
305 tcg_temp_free_i64(tmp64
);
309 /* Return (b << 32) - a. Mark inputs as dead. */
310 static TCGv_i64
gen_subq_msw(TCGv_i64 a
, TCGv b
)
312 TCGv_i64 tmp64
= tcg_temp_new_i64();
314 tcg_gen_extu_i32_i64(tmp64
, b
);
316 tcg_gen_shli_i64(tmp64
, tmp64
, 32);
317 tcg_gen_sub_i64(a
, tmp64
, a
);
319 tcg_temp_free_i64(tmp64
);
323 /* FIXME: Most targets have native widening multiplication.
324 It would be good to use that instead of a full wide multiply. */
325 /* 32x32->64 multiply. Marks inputs as dead. */
326 static TCGv_i64
gen_mulu_i64_i32(TCGv a
, TCGv b
)
328 TCGv_i64 tmp1
= tcg_temp_new_i64();
329 TCGv_i64 tmp2
= tcg_temp_new_i64();
331 tcg_gen_extu_i32_i64(tmp1
, a
);
333 tcg_gen_extu_i32_i64(tmp2
, b
);
335 tcg_gen_mul_i64(tmp1
, tmp1
, tmp2
);
336 tcg_temp_free_i64(tmp2
);
340 static TCGv_i64
gen_muls_i64_i32(TCGv a
, TCGv b
)
342 TCGv_i64 tmp1
= tcg_temp_new_i64();
343 TCGv_i64 tmp2
= tcg_temp_new_i64();
345 tcg_gen_ext_i32_i64(tmp1
, a
);
347 tcg_gen_ext_i32_i64(tmp2
, b
);
349 tcg_gen_mul_i64(tmp1
, tmp1
, tmp2
);
350 tcg_temp_free_i64(tmp2
);
354 /* Swap low and high halfwords. */
355 static void gen_swap_half(TCGv var
)
357 TCGv tmp
= new_tmp();
358 tcg_gen_shri_i32(tmp
, var
, 16);
359 tcg_gen_shli_i32(var
, var
, 16);
360 tcg_gen_or_i32(var
, var
, tmp
);
364 /* Dual 16-bit add. Result placed in t0 and t1 is marked as dead.
365 tmp = (t0 ^ t1) & 0x8000;
368 t0 = (t0 + t1) ^ tmp;
371 static void gen_add16(TCGv t0
, TCGv t1
)
373 TCGv tmp
= new_tmp();
374 tcg_gen_xor_i32(tmp
, t0
, t1
);
375 tcg_gen_andi_i32(tmp
, tmp
, 0x8000);
376 tcg_gen_andi_i32(t0
, t0
, ~0x8000);
377 tcg_gen_andi_i32(t1
, t1
, ~0x8000);
378 tcg_gen_add_i32(t0
, t0
, t1
);
379 tcg_gen_xor_i32(t0
, t0
, tmp
);
384 #define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, CF))
386 /* Set CF to the top bit of var. */
387 static void gen_set_CF_bit31(TCGv var
)
389 TCGv tmp
= new_tmp();
390 tcg_gen_shri_i32(tmp
, var
, 31);
395 /* Set N and Z flags from var. */
396 static inline void gen_logic_CC(TCGv var
)
398 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, NF
));
399 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, ZF
));
403 static void gen_adc(TCGv t0
, TCGv t1
)
406 tcg_gen_add_i32(t0
, t0
, t1
);
407 tmp
= load_cpu_field(CF
);
408 tcg_gen_add_i32(t0
, t0
, tmp
);
412 /* dest = T0 + T1 + CF. */
413 static void gen_add_carry(TCGv dest
, TCGv t0
, TCGv t1
)
416 tcg_gen_add_i32(dest
, t0
, t1
);
417 tmp
= load_cpu_field(CF
);
418 tcg_gen_add_i32(dest
, dest
, tmp
);
422 /* dest = T0 - T1 + CF - 1. */
423 static void gen_sub_carry(TCGv dest
, TCGv t0
, TCGv t1
)
426 tcg_gen_sub_i32(dest
, t0
, t1
);
427 tmp
= load_cpu_field(CF
);
428 tcg_gen_add_i32(dest
, dest
, tmp
);
429 tcg_gen_subi_i32(dest
, dest
, 1);
433 /* FIXME: Implement this natively. */
434 #define tcg_gen_abs_i32(t0, t1) gen_helper_abs(t0, t1)
436 static void shifter_out_im(TCGv var
, int shift
)
438 TCGv tmp
= new_tmp();
440 tcg_gen_andi_i32(tmp
, var
, 1);
442 tcg_gen_shri_i32(tmp
, var
, shift
);
444 tcg_gen_andi_i32(tmp
, tmp
, 1);
450 /* Shift by immediate. Includes special handling for shift == 0. */
451 static inline void gen_arm_shift_im(TCGv var
, int shiftop
, int shift
, int flags
)
457 shifter_out_im(var
, 32 - shift
);
458 tcg_gen_shli_i32(var
, var
, shift
);
464 tcg_gen_shri_i32(var
, var
, 31);
467 tcg_gen_movi_i32(var
, 0);
470 shifter_out_im(var
, shift
- 1);
471 tcg_gen_shri_i32(var
, var
, shift
);
478 shifter_out_im(var
, shift
- 1);
481 tcg_gen_sari_i32(var
, var
, shift
);
483 case 3: /* ROR/RRX */
486 shifter_out_im(var
, shift
- 1);
487 tcg_gen_rotri_i32(var
, var
, shift
); break;
489 TCGv tmp
= load_cpu_field(CF
);
491 shifter_out_im(var
, 0);
492 tcg_gen_shri_i32(var
, var
, 1);
493 tcg_gen_shli_i32(tmp
, tmp
, 31);
494 tcg_gen_or_i32(var
, var
, tmp
);
500 static inline void gen_arm_shift_reg(TCGv var
, int shiftop
,
501 TCGv shift
, int flags
)
505 case 0: gen_helper_shl_cc(var
, var
, shift
); break;
506 case 1: gen_helper_shr_cc(var
, var
, shift
); break;
507 case 2: gen_helper_sar_cc(var
, var
, shift
); break;
508 case 3: gen_helper_ror_cc(var
, var
, shift
); break;
512 case 0: gen_helper_shl(var
, var
, shift
); break;
513 case 1: gen_helper_shr(var
, var
, shift
); break;
514 case 2: gen_helper_sar(var
, var
, shift
); break;
515 case 3: tcg_gen_andi_i32(shift
, shift
, 0x1f);
516 tcg_gen_rotr_i32(var
, var
, shift
); break;
522 #define PAS_OP(pfx) \
524 case 0: gen_pas_helper(glue(pfx,add16)); break; \
525 case 1: gen_pas_helper(glue(pfx,addsubx)); break; \
526 case 2: gen_pas_helper(glue(pfx,subaddx)); break; \
527 case 3: gen_pas_helper(glue(pfx,sub16)); break; \
528 case 4: gen_pas_helper(glue(pfx,add8)); break; \
529 case 7: gen_pas_helper(glue(pfx,sub8)); break; \
531 static void gen_arm_parallel_addsub(int op1
, int op2
, TCGv a
, TCGv b
)
536 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
538 tmp
= tcg_temp_new_ptr();
539 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
541 tcg_temp_free_ptr(tmp
);
544 tmp
= tcg_temp_new_ptr();
545 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
547 tcg_temp_free_ptr(tmp
);
549 #undef gen_pas_helper
550 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b)
563 #undef gen_pas_helper
568 /* For unknown reasons Arm and Thumb-2 use arbitrarily different encodings. */
569 #define PAS_OP(pfx) \
571 case 0: gen_pas_helper(glue(pfx,add8)); break; \
572 case 1: gen_pas_helper(glue(pfx,add16)); break; \
573 case 2: gen_pas_helper(glue(pfx,addsubx)); break; \
574 case 4: gen_pas_helper(glue(pfx,sub8)); break; \
575 case 5: gen_pas_helper(glue(pfx,sub16)); break; \
576 case 6: gen_pas_helper(glue(pfx,subaddx)); break; \
578 static void gen_thumb2_parallel_addsub(int op1
, int op2
, TCGv a
, TCGv b
)
583 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
585 tmp
= tcg_temp_new_ptr();
586 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
588 tcg_temp_free_ptr(tmp
);
591 tmp
= tcg_temp_new_ptr();
592 tcg_gen_addi_ptr(tmp
, cpu_env
, offsetof(CPUState
, GE
));
594 tcg_temp_free_ptr(tmp
);
596 #undef gen_pas_helper
597 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b)
610 #undef gen_pas_helper
615 static void gen_test_cc(int cc
, int label
)
623 tmp
= load_cpu_field(ZF
);
624 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
627 tmp
= load_cpu_field(ZF
);
628 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
631 tmp
= load_cpu_field(CF
);
632 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
635 tmp
= load_cpu_field(CF
);
636 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
639 tmp
= load_cpu_field(NF
);
640 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
643 tmp
= load_cpu_field(NF
);
644 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
647 tmp
= load_cpu_field(VF
);
648 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
651 tmp
= load_cpu_field(VF
);
652 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
654 case 8: /* hi: C && !Z */
655 inv
= gen_new_label();
656 tmp
= load_cpu_field(CF
);
657 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
659 tmp
= load_cpu_field(ZF
);
660 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, label
);
663 case 9: /* ls: !C || Z */
664 tmp
= load_cpu_field(CF
);
665 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
667 tmp
= load_cpu_field(ZF
);
668 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
670 case 10: /* ge: N == V -> N ^ V == 0 */
671 tmp
= load_cpu_field(VF
);
672 tmp2
= load_cpu_field(NF
);
673 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
675 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
677 case 11: /* lt: N != V -> N ^ V != 0 */
678 tmp
= load_cpu_field(VF
);
679 tmp2
= load_cpu_field(NF
);
680 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
682 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
684 case 12: /* gt: !Z && N == V */
685 inv
= gen_new_label();
686 tmp
= load_cpu_field(ZF
);
687 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, inv
);
689 tmp
= load_cpu_field(VF
);
690 tmp2
= load_cpu_field(NF
);
691 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
693 tcg_gen_brcondi_i32(TCG_COND_GE
, tmp
, 0, label
);
696 case 13: /* le: Z || N != V */
697 tmp
= load_cpu_field(ZF
);
698 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
700 tmp
= load_cpu_field(VF
);
701 tmp2
= load_cpu_field(NF
);
702 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
704 tcg_gen_brcondi_i32(TCG_COND_LT
, tmp
, 0, label
);
707 fprintf(stderr
, "Bad condition code 0x%x\n", cc
);
713 static const uint8_t table_logic_cc
[16] = {
732 /* Set PC and Thumb state from an immediate address. */
733 static inline void gen_bx_im(DisasContext
*s
, uint32_t addr
)
737 s
->is_jmp
= DISAS_UPDATE
;
738 if (s
->thumb
!= (addr
& 1)) {
740 tcg_gen_movi_i32(tmp
, addr
& 1);
741 tcg_gen_st_i32(tmp
, cpu_env
, offsetof(CPUState
, thumb
));
744 tcg_gen_movi_i32(cpu_R
[15], addr
& ~1);
747 /* Set PC and Thumb state from var. var is marked as dead. */
748 static inline void gen_bx(DisasContext
*s
, TCGv var
)
750 s
->is_jmp
= DISAS_UPDATE
;
751 tcg_gen_andi_i32(cpu_R
[15], var
, ~1);
752 tcg_gen_andi_i32(var
, var
, 1);
753 store_cpu_field(var
, thumb
);
756 /* Variant of store_reg which uses branch&exchange logic when storing
757 to r15 in ARM architecture v7 and above. The source must be a temporary
758 and will be marked as dead. */
759 static inline void store_reg_bx(CPUState
*env
, DisasContext
*s
,
762 if (reg
== 15 && ENABLE_ARCH_7
) {
765 store_reg(s
, reg
, var
);
769 static inline TCGv
gen_ld8s(TCGv addr
, int index
)
771 TCGv tmp
= new_tmp();
772 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
775 static inline TCGv
gen_ld8u(TCGv addr
, int index
)
777 TCGv tmp
= new_tmp();
778 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
781 static inline TCGv
gen_ld16s(TCGv addr
, int index
)
783 TCGv tmp
= new_tmp();
784 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
787 static inline TCGv
gen_ld16u(TCGv addr
, int index
)
789 TCGv tmp
= new_tmp();
790 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
793 static inline TCGv
gen_ld32(TCGv addr
, int index
)
795 TCGv tmp
= new_tmp();
796 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
799 static inline TCGv_i64
gen_ld64(TCGv addr
, int index
)
801 TCGv_i64 tmp
= tcg_temp_new_i64();
802 tcg_gen_qemu_ld64(tmp
, addr
, index
);
805 static inline void gen_st8(TCGv val
, TCGv addr
, int index
)
807 tcg_gen_qemu_st8(val
, addr
, index
);
810 static inline void gen_st16(TCGv val
, TCGv addr
, int index
)
812 tcg_gen_qemu_st16(val
, addr
, index
);
815 static inline void gen_st32(TCGv val
, TCGv addr
, int index
)
817 tcg_gen_qemu_st32(val
, addr
, index
);
820 static inline void gen_st64(TCGv_i64 val
, TCGv addr
, int index
)
822 tcg_gen_qemu_st64(val
, addr
, index
);
823 tcg_temp_free_i64(val
);
826 static inline void gen_set_pc_im(uint32_t val
)
828 tcg_gen_movi_i32(cpu_R
[15], val
);
831 /* Force a TB lookup after an instruction that changes the CPU state. */
832 static inline void gen_lookup_tb(DisasContext
*s
)
834 tcg_gen_movi_i32(cpu_R
[15], s
->pc
& ~1);
835 s
->is_jmp
= DISAS_UPDATE
;
838 static inline void gen_add_data_offset(DisasContext
*s
, unsigned int insn
,
841 int val
, rm
, shift
, shiftop
;
844 if (!(insn
& (1 << 25))) {
847 if (!(insn
& (1 << 23)))
850 tcg_gen_addi_i32(var
, var
, val
);
854 shift
= (insn
>> 7) & 0x1f;
855 shiftop
= (insn
>> 5) & 3;
856 offset
= load_reg(s
, rm
);
857 gen_arm_shift_im(offset
, shiftop
, shift
, 0);
858 if (!(insn
& (1 << 23)))
859 tcg_gen_sub_i32(var
, var
, offset
);
861 tcg_gen_add_i32(var
, var
, offset
);
866 static inline void gen_add_datah_offset(DisasContext
*s
, unsigned int insn
,
872 if (insn
& (1 << 22)) {
874 val
= (insn
& 0xf) | ((insn
>> 4) & 0xf0);
875 if (!(insn
& (1 << 23)))
879 tcg_gen_addi_i32(var
, var
, val
);
883 tcg_gen_addi_i32(var
, var
, extra
);
885 offset
= load_reg(s
, rm
);
886 if (!(insn
& (1 << 23)))
887 tcg_gen_sub_i32(var
, var
, offset
);
889 tcg_gen_add_i32(var
, var
, offset
);
894 #define VFP_OP2(name) \
895 static inline void gen_vfp_##name(int dp) \
898 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, cpu_F1d, cpu_env); \
900 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, cpu_F1s, cpu_env); \
910 static inline void gen_vfp_abs(int dp
)
913 gen_helper_vfp_absd(cpu_F0d
, cpu_F0d
);
915 gen_helper_vfp_abss(cpu_F0s
, cpu_F0s
);
918 static inline void gen_vfp_neg(int dp
)
921 gen_helper_vfp_negd(cpu_F0d
, cpu_F0d
);
923 gen_helper_vfp_negs(cpu_F0s
, cpu_F0s
);
926 static inline void gen_vfp_sqrt(int dp
)
929 gen_helper_vfp_sqrtd(cpu_F0d
, cpu_F0d
, cpu_env
);
931 gen_helper_vfp_sqrts(cpu_F0s
, cpu_F0s
, cpu_env
);
934 static inline void gen_vfp_cmp(int dp
)
937 gen_helper_vfp_cmpd(cpu_F0d
, cpu_F1d
, cpu_env
);
939 gen_helper_vfp_cmps(cpu_F0s
, cpu_F1s
, cpu_env
);
942 static inline void gen_vfp_cmpe(int dp
)
945 gen_helper_vfp_cmped(cpu_F0d
, cpu_F1d
, cpu_env
);
947 gen_helper_vfp_cmpes(cpu_F0s
, cpu_F1s
, cpu_env
);
950 static inline void gen_vfp_F1_ld0(int dp
)
953 tcg_gen_movi_i64(cpu_F1d
, 0);
955 tcg_gen_movi_i32(cpu_F1s
, 0);
958 static inline void gen_vfp_uito(int dp
)
961 gen_helper_vfp_uitod(cpu_F0d
, cpu_F0s
, cpu_env
);
963 gen_helper_vfp_uitos(cpu_F0s
, cpu_F0s
, cpu_env
);
966 static inline void gen_vfp_sito(int dp
)
969 gen_helper_vfp_sitod(cpu_F0d
, cpu_F0s
, cpu_env
);
971 gen_helper_vfp_sitos(cpu_F0s
, cpu_F0s
, cpu_env
);
974 static inline void gen_vfp_toui(int dp
)
977 gen_helper_vfp_touid(cpu_F0s
, cpu_F0d
, cpu_env
);
979 gen_helper_vfp_touis(cpu_F0s
, cpu_F0s
, cpu_env
);
982 static inline void gen_vfp_touiz(int dp
)
985 gen_helper_vfp_touizd(cpu_F0s
, cpu_F0d
, cpu_env
);
987 gen_helper_vfp_touizs(cpu_F0s
, cpu_F0s
, cpu_env
);
990 static inline void gen_vfp_tosi(int dp
)
993 gen_helper_vfp_tosid(cpu_F0s
, cpu_F0d
, cpu_env
);
995 gen_helper_vfp_tosis(cpu_F0s
, cpu_F0s
, cpu_env
);
998 static inline void gen_vfp_tosiz(int dp
)
1001 gen_helper_vfp_tosizd(cpu_F0s
, cpu_F0d
, cpu_env
);
1003 gen_helper_vfp_tosizs(cpu_F0s
, cpu_F0s
, cpu_env
);
1006 #define VFP_GEN_FIX(name) \
1007 static inline void gen_vfp_##name(int dp, int shift) \
1009 TCGv tmp_shift = tcg_const_i32(shift); \
1011 gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, tmp_shift, cpu_env);\
1013 gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, tmp_shift, cpu_env);\
1014 tcg_temp_free_i32(tmp_shift); \
1026 static inline void gen_vfp_ld(DisasContext
*s
, int dp
, TCGv addr
)
1029 tcg_gen_qemu_ld64(cpu_F0d
, addr
, IS_USER(s
));
1031 tcg_gen_qemu_ld32u(cpu_F0s
, addr
, IS_USER(s
));
1034 static inline void gen_vfp_st(DisasContext
*s
, int dp
, TCGv addr
)
1037 tcg_gen_qemu_st64(cpu_F0d
, addr
, IS_USER(s
));
1039 tcg_gen_qemu_st32(cpu_F0s
, addr
, IS_USER(s
));
1043 vfp_reg_offset (int dp
, int reg
)
1046 return offsetof(CPUARMState
, vfp
.regs
[reg
]);
1048 return offsetof(CPUARMState
, vfp
.regs
[reg
>> 1])
1049 + offsetof(CPU_DoubleU
, l
.upper
);
1051 return offsetof(CPUARMState
, vfp
.regs
[reg
>> 1])
1052 + offsetof(CPU_DoubleU
, l
.lower
);
1056 /* Return the offset of a 32-bit piece of a NEON register.
1057 zero is the least significant end of the register. */
1059 neon_reg_offset (int reg
, int n
)
1063 return vfp_reg_offset(0, sreg
);
1066 static TCGv
neon_load_reg(int reg
, int pass
)
1068 TCGv tmp
= new_tmp();
1069 tcg_gen_ld_i32(tmp
, cpu_env
, neon_reg_offset(reg
, pass
));
1073 static void neon_store_reg(int reg
, int pass
, TCGv var
)
1075 tcg_gen_st_i32(var
, cpu_env
, neon_reg_offset(reg
, pass
));
1079 static inline void neon_load_reg64(TCGv_i64 var
, int reg
)
1081 tcg_gen_ld_i64(var
, cpu_env
, vfp_reg_offset(1, reg
));
1084 static inline void neon_store_reg64(TCGv_i64 var
, int reg
)
1086 tcg_gen_st_i64(var
, cpu_env
, vfp_reg_offset(1, reg
));
1089 #define tcg_gen_ld_f32 tcg_gen_ld_i32
1090 #define tcg_gen_ld_f64 tcg_gen_ld_i64
1091 #define tcg_gen_st_f32 tcg_gen_st_i32
1092 #define tcg_gen_st_f64 tcg_gen_st_i64
1094 static inline void gen_mov_F0_vreg(int dp
, int reg
)
1097 tcg_gen_ld_f64(cpu_F0d
, cpu_env
, vfp_reg_offset(dp
, reg
));
1099 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, vfp_reg_offset(dp
, reg
));
1102 static inline void gen_mov_F1_vreg(int dp
, int reg
)
1105 tcg_gen_ld_f64(cpu_F1d
, cpu_env
, vfp_reg_offset(dp
, reg
));
1107 tcg_gen_ld_f32(cpu_F1s
, cpu_env
, vfp_reg_offset(dp
, reg
));
1110 static inline void gen_mov_vreg_F0(int dp
, int reg
)
1113 tcg_gen_st_f64(cpu_F0d
, cpu_env
, vfp_reg_offset(dp
, reg
));
1115 tcg_gen_st_f32(cpu_F0s
, cpu_env
, vfp_reg_offset(dp
, reg
));
1118 #define ARM_CP_RW_BIT (1 << 20)
1120 static inline void iwmmxt_load_reg(TCGv_i64 var
, int reg
)
1122 tcg_gen_ld_i64(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.regs
[reg
]));
1125 static inline void iwmmxt_store_reg(TCGv_i64 var
, int reg
)
1127 tcg_gen_st_i64(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.regs
[reg
]));
1130 static inline TCGv
iwmmxt_load_creg(int reg
)
1132 TCGv var
= new_tmp();
1133 tcg_gen_ld_i32(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.cregs
[reg
]));
1137 static inline void iwmmxt_store_creg(int reg
, TCGv var
)
1139 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUState
, iwmmxt
.cregs
[reg
]));
1143 static inline void gen_op_iwmmxt_movq_wRn_M0(int rn
)
1145 iwmmxt_store_reg(cpu_M0
, rn
);
1148 static inline void gen_op_iwmmxt_movq_M0_wRn(int rn
)
1150 iwmmxt_load_reg(cpu_M0
, rn
);
1153 static inline void gen_op_iwmmxt_orq_M0_wRn(int rn
)
1155 iwmmxt_load_reg(cpu_V1
, rn
);
1156 tcg_gen_or_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1159 static inline void gen_op_iwmmxt_andq_M0_wRn(int rn
)
1161 iwmmxt_load_reg(cpu_V1
, rn
);
1162 tcg_gen_and_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1165 static inline void gen_op_iwmmxt_xorq_M0_wRn(int rn
)
1167 iwmmxt_load_reg(cpu_V1
, rn
);
1168 tcg_gen_xor_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1171 #define IWMMXT_OP(name) \
1172 static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
1174 iwmmxt_load_reg(cpu_V1, rn); \
1175 gen_helper_iwmmxt_##name(cpu_M0, cpu_M0, cpu_V1); \
1178 #define IWMMXT_OP_ENV(name) \
1179 static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
1181 iwmmxt_load_reg(cpu_V1, rn); \
1182 gen_helper_iwmmxt_##name(cpu_M0, cpu_env, cpu_M0, cpu_V1); \
1185 #define IWMMXT_OP_ENV_SIZE(name) \
1186 IWMMXT_OP_ENV(name##b) \
1187 IWMMXT_OP_ENV(name##w) \
1188 IWMMXT_OP_ENV(name##l)
1190 #define IWMMXT_OP_ENV1(name) \
1191 static inline void gen_op_iwmmxt_##name##_M0(void) \
1193 gen_helper_iwmmxt_##name(cpu_M0, cpu_env, cpu_M0); \
1207 IWMMXT_OP_ENV_SIZE(unpackl
)
1208 IWMMXT_OP_ENV_SIZE(unpackh
)
1210 IWMMXT_OP_ENV1(unpacklub
)
1211 IWMMXT_OP_ENV1(unpackluw
)
1212 IWMMXT_OP_ENV1(unpacklul
)
1213 IWMMXT_OP_ENV1(unpackhub
)
1214 IWMMXT_OP_ENV1(unpackhuw
)
1215 IWMMXT_OP_ENV1(unpackhul
)
1216 IWMMXT_OP_ENV1(unpacklsb
)
1217 IWMMXT_OP_ENV1(unpacklsw
)
1218 IWMMXT_OP_ENV1(unpacklsl
)
1219 IWMMXT_OP_ENV1(unpackhsb
)
1220 IWMMXT_OP_ENV1(unpackhsw
)
1221 IWMMXT_OP_ENV1(unpackhsl
)
1223 IWMMXT_OP_ENV_SIZE(cmpeq
)
1224 IWMMXT_OP_ENV_SIZE(cmpgtu
)
1225 IWMMXT_OP_ENV_SIZE(cmpgts
)
1227 IWMMXT_OP_ENV_SIZE(mins
)
1228 IWMMXT_OP_ENV_SIZE(minu
)
1229 IWMMXT_OP_ENV_SIZE(maxs
)
1230 IWMMXT_OP_ENV_SIZE(maxu
)
1232 IWMMXT_OP_ENV_SIZE(subn
)
1233 IWMMXT_OP_ENV_SIZE(addn
)
1234 IWMMXT_OP_ENV_SIZE(subu
)
1235 IWMMXT_OP_ENV_SIZE(addu
)
1236 IWMMXT_OP_ENV_SIZE(subs
)
1237 IWMMXT_OP_ENV_SIZE(adds
)
1239 IWMMXT_OP_ENV(avgb0
)
1240 IWMMXT_OP_ENV(avgb1
)
1241 IWMMXT_OP_ENV(avgw0
)
1242 IWMMXT_OP_ENV(avgw1
)
1246 IWMMXT_OP_ENV(packuw
)
1247 IWMMXT_OP_ENV(packul
)
1248 IWMMXT_OP_ENV(packuq
)
1249 IWMMXT_OP_ENV(packsw
)
1250 IWMMXT_OP_ENV(packsl
)
1251 IWMMXT_OP_ENV(packsq
)
1253 static void gen_op_iwmmxt_set_mup(void)
1256 tmp
= load_cpu_field(iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1257 tcg_gen_ori_i32(tmp
, tmp
, 2);
1258 store_cpu_field(tmp
, iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1261 static void gen_op_iwmmxt_set_cup(void)
1264 tmp
= load_cpu_field(iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1265 tcg_gen_ori_i32(tmp
, tmp
, 1);
1266 store_cpu_field(tmp
, iwmmxt
.cregs
[ARM_IWMMXT_wCon
]);
1269 static void gen_op_iwmmxt_setpsr_nz(void)
1271 TCGv tmp
= new_tmp();
1272 gen_helper_iwmmxt_setpsr_nz(tmp
, cpu_M0
);
1273 store_cpu_field(tmp
, iwmmxt
.cregs
[ARM_IWMMXT_wCASF
]);
1276 static inline void gen_op_iwmmxt_addl_M0_wRn(int rn
)
1278 iwmmxt_load_reg(cpu_V1
, rn
);
1279 tcg_gen_ext32u_i64(cpu_V1
, cpu_V1
);
1280 tcg_gen_add_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1283 static inline int gen_iwmmxt_address(DisasContext
*s
, uint32_t insn
, TCGv dest
)
1289 rd
= (insn
>> 16) & 0xf;
1290 tmp
= load_reg(s
, rd
);
1292 offset
= (insn
& 0xff) << ((insn
>> 7) & 2);
1293 if (insn
& (1 << 24)) {
1295 if (insn
& (1 << 23))
1296 tcg_gen_addi_i32(tmp
, tmp
, offset
);
1298 tcg_gen_addi_i32(tmp
, tmp
, -offset
);
1299 tcg_gen_mov_i32(dest
, tmp
);
1300 if (insn
& (1 << 21))
1301 store_reg(s
, rd
, tmp
);
1304 } else if (insn
& (1 << 21)) {
1306 tcg_gen_mov_i32(dest
, tmp
);
1307 if (insn
& (1 << 23))
1308 tcg_gen_addi_i32(tmp
, tmp
, offset
);
1310 tcg_gen_addi_i32(tmp
, tmp
, -offset
);
1311 store_reg(s
, rd
, tmp
);
1312 } else if (!(insn
& (1 << 23)))
1317 static inline int gen_iwmmxt_shift(uint32_t insn
, uint32_t mask
, TCGv dest
)
1319 int rd
= (insn
>> 0) & 0xf;
1322 if (insn
& (1 << 8)) {
1323 if (rd
< ARM_IWMMXT_wCGR0
|| rd
> ARM_IWMMXT_wCGR3
) {
1326 tmp
= iwmmxt_load_creg(rd
);
1330 iwmmxt_load_reg(cpu_V0
, rd
);
1331 tcg_gen_trunc_i64_i32(tmp
, cpu_V0
);
1333 tcg_gen_andi_i32(tmp
, tmp
, mask
);
1334 tcg_gen_mov_i32(dest
, tmp
);
1339 /* Disassemble an iwMMXt instruction. Returns nonzero if an error occured
1340 (ie. an undefined instruction). */
1341 static int disas_iwmmxt_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
1344 int rdhi
, rdlo
, rd0
, rd1
, i
;
1346 TCGv tmp
, tmp2
, tmp3
;
1348 if ((insn
& 0x0e000e00) == 0x0c000000) {
1349 if ((insn
& 0x0fe00ff0) == 0x0c400000) {
1351 rdlo
= (insn
>> 12) & 0xf;
1352 rdhi
= (insn
>> 16) & 0xf;
1353 if (insn
& ARM_CP_RW_BIT
) { /* TMRRC */
1354 iwmmxt_load_reg(cpu_V0
, wrd
);
1355 tcg_gen_trunc_i64_i32(cpu_R
[rdlo
], cpu_V0
);
1356 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
1357 tcg_gen_trunc_i64_i32(cpu_R
[rdhi
], cpu_V0
);
1358 } else { /* TMCRR */
1359 tcg_gen_concat_i32_i64(cpu_V0
, cpu_R
[rdlo
], cpu_R
[rdhi
]);
1360 iwmmxt_store_reg(cpu_V0
, wrd
);
1361 gen_op_iwmmxt_set_mup();
1366 wrd
= (insn
>> 12) & 0xf;
1368 if (gen_iwmmxt_address(s
, insn
, addr
)) {
1372 if (insn
& ARM_CP_RW_BIT
) {
1373 if ((insn
>> 28) == 0xf) { /* WLDRW wCx */
1375 tcg_gen_qemu_ld32u(tmp
, addr
, IS_USER(s
));
1376 iwmmxt_store_creg(wrd
, tmp
);
1379 if (insn
& (1 << 8)) {
1380 if (insn
& (1 << 22)) { /* WLDRD */
1381 tcg_gen_qemu_ld64(cpu_M0
, addr
, IS_USER(s
));
1383 } else { /* WLDRW wRd */
1384 tmp
= gen_ld32(addr
, IS_USER(s
));
1387 if (insn
& (1 << 22)) { /* WLDRH */
1388 tmp
= gen_ld16u(addr
, IS_USER(s
));
1389 } else { /* WLDRB */
1390 tmp
= gen_ld8u(addr
, IS_USER(s
));
1394 tcg_gen_extu_i32_i64(cpu_M0
, tmp
);
1397 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1400 if ((insn
>> 28) == 0xf) { /* WSTRW wCx */
1401 tmp
= iwmmxt_load_creg(wrd
);
1402 gen_st32(tmp
, addr
, IS_USER(s
));
1404 gen_op_iwmmxt_movq_M0_wRn(wrd
);
1406 if (insn
& (1 << 8)) {
1407 if (insn
& (1 << 22)) { /* WSTRD */
1409 tcg_gen_qemu_st64(cpu_M0
, addr
, IS_USER(s
));
1410 } else { /* WSTRW wRd */
1411 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1412 gen_st32(tmp
, addr
, IS_USER(s
));
1415 if (insn
& (1 << 22)) { /* WSTRH */
1416 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1417 gen_st16(tmp
, addr
, IS_USER(s
));
1418 } else { /* WSTRB */
1419 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1420 gen_st8(tmp
, addr
, IS_USER(s
));
1429 if ((insn
& 0x0f000000) != 0x0e000000)
1432 switch (((insn
>> 12) & 0xf00) | ((insn
>> 4) & 0xff)) {
1433 case 0x000: /* WOR */
1434 wrd
= (insn
>> 12) & 0xf;
1435 rd0
= (insn
>> 0) & 0xf;
1436 rd1
= (insn
>> 16) & 0xf;
1437 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1438 gen_op_iwmmxt_orq_M0_wRn(rd1
);
1439 gen_op_iwmmxt_setpsr_nz();
1440 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1441 gen_op_iwmmxt_set_mup();
1442 gen_op_iwmmxt_set_cup();
1444 case 0x011: /* TMCR */
1447 rd
= (insn
>> 12) & 0xf;
1448 wrd
= (insn
>> 16) & 0xf;
1450 case ARM_IWMMXT_wCID
:
1451 case ARM_IWMMXT_wCASF
:
1453 case ARM_IWMMXT_wCon
:
1454 gen_op_iwmmxt_set_cup();
1456 case ARM_IWMMXT_wCSSF
:
1457 tmp
= iwmmxt_load_creg(wrd
);
1458 tmp2
= load_reg(s
, rd
);
1459 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
1461 iwmmxt_store_creg(wrd
, tmp
);
1463 case ARM_IWMMXT_wCGR0
:
1464 case ARM_IWMMXT_wCGR1
:
1465 case ARM_IWMMXT_wCGR2
:
1466 case ARM_IWMMXT_wCGR3
:
1467 gen_op_iwmmxt_set_cup();
1468 tmp
= load_reg(s
, rd
);
1469 iwmmxt_store_creg(wrd
, tmp
);
1475 case 0x100: /* WXOR */
1476 wrd
= (insn
>> 12) & 0xf;
1477 rd0
= (insn
>> 0) & 0xf;
1478 rd1
= (insn
>> 16) & 0xf;
1479 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1480 gen_op_iwmmxt_xorq_M0_wRn(rd1
);
1481 gen_op_iwmmxt_setpsr_nz();
1482 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1483 gen_op_iwmmxt_set_mup();
1484 gen_op_iwmmxt_set_cup();
1486 case 0x111: /* TMRC */
1489 rd
= (insn
>> 12) & 0xf;
1490 wrd
= (insn
>> 16) & 0xf;
1491 tmp
= iwmmxt_load_creg(wrd
);
1492 store_reg(s
, rd
, tmp
);
1494 case 0x300: /* WANDN */
1495 wrd
= (insn
>> 12) & 0xf;
1496 rd0
= (insn
>> 0) & 0xf;
1497 rd1
= (insn
>> 16) & 0xf;
1498 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1499 tcg_gen_neg_i64(cpu_M0
, cpu_M0
);
1500 gen_op_iwmmxt_andq_M0_wRn(rd1
);
1501 gen_op_iwmmxt_setpsr_nz();
1502 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1503 gen_op_iwmmxt_set_mup();
1504 gen_op_iwmmxt_set_cup();
1506 case 0x200: /* WAND */
1507 wrd
= (insn
>> 12) & 0xf;
1508 rd0
= (insn
>> 0) & 0xf;
1509 rd1
= (insn
>> 16) & 0xf;
1510 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1511 gen_op_iwmmxt_andq_M0_wRn(rd1
);
1512 gen_op_iwmmxt_setpsr_nz();
1513 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1514 gen_op_iwmmxt_set_mup();
1515 gen_op_iwmmxt_set_cup();
1517 case 0x810: case 0xa10: /* WMADD */
1518 wrd
= (insn
>> 12) & 0xf;
1519 rd0
= (insn
>> 0) & 0xf;
1520 rd1
= (insn
>> 16) & 0xf;
1521 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1522 if (insn
& (1 << 21))
1523 gen_op_iwmmxt_maddsq_M0_wRn(rd1
);
1525 gen_op_iwmmxt_madduq_M0_wRn(rd1
);
1526 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1527 gen_op_iwmmxt_set_mup();
1529 case 0x10e: case 0x50e: case 0x90e: case 0xd0e: /* WUNPCKIL */
1530 wrd
= (insn
>> 12) & 0xf;
1531 rd0
= (insn
>> 16) & 0xf;
1532 rd1
= (insn
>> 0) & 0xf;
1533 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1534 switch ((insn
>> 22) & 3) {
1536 gen_op_iwmmxt_unpacklb_M0_wRn(rd1
);
1539 gen_op_iwmmxt_unpacklw_M0_wRn(rd1
);
1542 gen_op_iwmmxt_unpackll_M0_wRn(rd1
);
1547 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1548 gen_op_iwmmxt_set_mup();
1549 gen_op_iwmmxt_set_cup();
1551 case 0x10c: case 0x50c: case 0x90c: case 0xd0c: /* WUNPCKIH */
1552 wrd
= (insn
>> 12) & 0xf;
1553 rd0
= (insn
>> 16) & 0xf;
1554 rd1
= (insn
>> 0) & 0xf;
1555 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1556 switch ((insn
>> 22) & 3) {
1558 gen_op_iwmmxt_unpackhb_M0_wRn(rd1
);
1561 gen_op_iwmmxt_unpackhw_M0_wRn(rd1
);
1564 gen_op_iwmmxt_unpackhl_M0_wRn(rd1
);
1569 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1570 gen_op_iwmmxt_set_mup();
1571 gen_op_iwmmxt_set_cup();
1573 case 0x012: case 0x112: case 0x412: case 0x512: /* WSAD */
1574 wrd
= (insn
>> 12) & 0xf;
1575 rd0
= (insn
>> 16) & 0xf;
1576 rd1
= (insn
>> 0) & 0xf;
1577 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1578 if (insn
& (1 << 22))
1579 gen_op_iwmmxt_sadw_M0_wRn(rd1
);
1581 gen_op_iwmmxt_sadb_M0_wRn(rd1
);
1582 if (!(insn
& (1 << 20)))
1583 gen_op_iwmmxt_addl_M0_wRn(wrd
);
1584 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1585 gen_op_iwmmxt_set_mup();
1587 case 0x010: case 0x110: case 0x210: case 0x310: /* WMUL */
1588 wrd
= (insn
>> 12) & 0xf;
1589 rd0
= (insn
>> 16) & 0xf;
1590 rd1
= (insn
>> 0) & 0xf;
1591 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1592 if (insn
& (1 << 21)) {
1593 if (insn
& (1 << 20))
1594 gen_op_iwmmxt_mulshw_M0_wRn(rd1
);
1596 gen_op_iwmmxt_mulslw_M0_wRn(rd1
);
1598 if (insn
& (1 << 20))
1599 gen_op_iwmmxt_muluhw_M0_wRn(rd1
);
1601 gen_op_iwmmxt_mululw_M0_wRn(rd1
);
1603 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1604 gen_op_iwmmxt_set_mup();
1606 case 0x410: case 0x510: case 0x610: case 0x710: /* WMAC */
1607 wrd
= (insn
>> 12) & 0xf;
1608 rd0
= (insn
>> 16) & 0xf;
1609 rd1
= (insn
>> 0) & 0xf;
1610 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1611 if (insn
& (1 << 21))
1612 gen_op_iwmmxt_macsw_M0_wRn(rd1
);
1614 gen_op_iwmmxt_macuw_M0_wRn(rd1
);
1615 if (!(insn
& (1 << 20))) {
1616 iwmmxt_load_reg(cpu_V1
, wrd
);
1617 tcg_gen_add_i64(cpu_M0
, cpu_M0
, cpu_V1
);
1619 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1620 gen_op_iwmmxt_set_mup();
1622 case 0x006: case 0x406: case 0x806: case 0xc06: /* WCMPEQ */
1623 wrd
= (insn
>> 12) & 0xf;
1624 rd0
= (insn
>> 16) & 0xf;
1625 rd1
= (insn
>> 0) & 0xf;
1626 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1627 switch ((insn
>> 22) & 3) {
1629 gen_op_iwmmxt_cmpeqb_M0_wRn(rd1
);
1632 gen_op_iwmmxt_cmpeqw_M0_wRn(rd1
);
1635 gen_op_iwmmxt_cmpeql_M0_wRn(rd1
);
1640 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1641 gen_op_iwmmxt_set_mup();
1642 gen_op_iwmmxt_set_cup();
1644 case 0x800: case 0x900: case 0xc00: case 0xd00: /* WAVG2 */
1645 wrd
= (insn
>> 12) & 0xf;
1646 rd0
= (insn
>> 16) & 0xf;
1647 rd1
= (insn
>> 0) & 0xf;
1648 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1649 if (insn
& (1 << 22)) {
1650 if (insn
& (1 << 20))
1651 gen_op_iwmmxt_avgw1_M0_wRn(rd1
);
1653 gen_op_iwmmxt_avgw0_M0_wRn(rd1
);
1655 if (insn
& (1 << 20))
1656 gen_op_iwmmxt_avgb1_M0_wRn(rd1
);
1658 gen_op_iwmmxt_avgb0_M0_wRn(rd1
);
1660 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1661 gen_op_iwmmxt_set_mup();
1662 gen_op_iwmmxt_set_cup();
1664 case 0x802: case 0x902: case 0xa02: case 0xb02: /* WALIGNR */
1665 wrd
= (insn
>> 12) & 0xf;
1666 rd0
= (insn
>> 16) & 0xf;
1667 rd1
= (insn
>> 0) & 0xf;
1668 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1669 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCGR0
+ ((insn
>> 20) & 3));
1670 tcg_gen_andi_i32(tmp
, tmp
, 7);
1671 iwmmxt_load_reg(cpu_V1
, rd1
);
1672 gen_helper_iwmmxt_align(cpu_M0
, cpu_M0
, cpu_V1
, tmp
);
1674 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1675 gen_op_iwmmxt_set_mup();
1677 case 0x601: case 0x605: case 0x609: case 0x60d: /* TINSR */
1678 if (((insn
>> 6) & 3) == 3)
1680 rd
= (insn
>> 12) & 0xf;
1681 wrd
= (insn
>> 16) & 0xf;
1682 tmp
= load_reg(s
, rd
);
1683 gen_op_iwmmxt_movq_M0_wRn(wrd
);
1684 switch ((insn
>> 6) & 3) {
1686 tmp2
= tcg_const_i32(0xff);
1687 tmp3
= tcg_const_i32((insn
& 7) << 3);
1690 tmp2
= tcg_const_i32(0xffff);
1691 tmp3
= tcg_const_i32((insn
& 3) << 4);
1694 tmp2
= tcg_const_i32(0xffffffff);
1695 tmp3
= tcg_const_i32((insn
& 1) << 5);
1701 gen_helper_iwmmxt_insr(cpu_M0
, cpu_M0
, tmp
, tmp2
, tmp3
);
1702 tcg_temp_free(tmp3
);
1703 tcg_temp_free(tmp2
);
1705 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1706 gen_op_iwmmxt_set_mup();
1708 case 0x107: case 0x507: case 0x907: case 0xd07: /* TEXTRM */
1709 rd
= (insn
>> 12) & 0xf;
1710 wrd
= (insn
>> 16) & 0xf;
1711 if (rd
== 15 || ((insn
>> 22) & 3) == 3)
1713 gen_op_iwmmxt_movq_M0_wRn(wrd
);
1715 switch ((insn
>> 22) & 3) {
1717 tcg_gen_shri_i64(cpu_M0
, cpu_M0
, (insn
& 7) << 3);
1718 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1720 tcg_gen_ext8s_i32(tmp
, tmp
);
1722 tcg_gen_andi_i32(tmp
, tmp
, 0xff);
1726 tcg_gen_shri_i64(cpu_M0
, cpu_M0
, (insn
& 3) << 4);
1727 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1729 tcg_gen_ext16s_i32(tmp
, tmp
);
1731 tcg_gen_andi_i32(tmp
, tmp
, 0xffff);
1735 tcg_gen_shri_i64(cpu_M0
, cpu_M0
, (insn
& 1) << 5);
1736 tcg_gen_trunc_i64_i32(tmp
, cpu_M0
);
1739 store_reg(s
, rd
, tmp
);
1741 case 0x117: case 0x517: case 0x917: case 0xd17: /* TEXTRC */
1742 if ((insn
& 0x000ff008) != 0x0003f000 || ((insn
>> 22) & 3) == 3)
1744 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCASF
);
1745 switch ((insn
>> 22) & 3) {
1747 tcg_gen_shri_i32(tmp
, tmp
, ((insn
& 7) << 2) + 0);
1750 tcg_gen_shri_i32(tmp
, tmp
, ((insn
& 3) << 3) + 4);
1753 tcg_gen_shri_i32(tmp
, tmp
, ((insn
& 1) << 4) + 12);
1756 tcg_gen_shli_i32(tmp
, tmp
, 28);
1760 case 0x401: case 0x405: case 0x409: case 0x40d: /* TBCST */
1761 if (((insn
>> 6) & 3) == 3)
1763 rd
= (insn
>> 12) & 0xf;
1764 wrd
= (insn
>> 16) & 0xf;
1765 tmp
= load_reg(s
, rd
);
1766 switch ((insn
>> 6) & 3) {
1768 gen_helper_iwmmxt_bcstb(cpu_M0
, tmp
);
1771 gen_helper_iwmmxt_bcstw(cpu_M0
, tmp
);
1774 gen_helper_iwmmxt_bcstl(cpu_M0
, tmp
);
1778 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1779 gen_op_iwmmxt_set_mup();
1781 case 0x113: case 0x513: case 0x913: case 0xd13: /* TANDC */
1782 if ((insn
& 0x000ff00f) != 0x0003f000 || ((insn
>> 22) & 3) == 3)
1784 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCASF
);
1786 tcg_gen_mov_i32(tmp2
, tmp
);
1787 switch ((insn
>> 22) & 3) {
1789 for (i
= 0; i
< 7; i
++) {
1790 tcg_gen_shli_i32(tmp2
, tmp2
, 4);
1791 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1795 for (i
= 0; i
< 3; i
++) {
1796 tcg_gen_shli_i32(tmp2
, tmp2
, 8);
1797 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1801 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
1802 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
1809 case 0x01c: case 0x41c: case 0x81c: case 0xc1c: /* WACC */
1810 wrd
= (insn
>> 12) & 0xf;
1811 rd0
= (insn
>> 16) & 0xf;
1812 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1813 switch ((insn
>> 22) & 3) {
1815 gen_helper_iwmmxt_addcb(cpu_M0
, cpu_M0
);
1818 gen_helper_iwmmxt_addcw(cpu_M0
, cpu_M0
);
1821 gen_helper_iwmmxt_addcl(cpu_M0
, cpu_M0
);
1826 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1827 gen_op_iwmmxt_set_mup();
1829 case 0x115: case 0x515: case 0x915: case 0xd15: /* TORC */
1830 if ((insn
& 0x000ff00f) != 0x0003f000 || ((insn
>> 22) & 3) == 3)
1832 tmp
= iwmmxt_load_creg(ARM_IWMMXT_wCASF
);
1834 tcg_gen_mov_i32(tmp2
, tmp
);
1835 switch ((insn
>> 22) & 3) {
1837 for (i
= 0; i
< 7; i
++) {
1838 tcg_gen_shli_i32(tmp2
, tmp2
, 4);
1839 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1843 for (i
= 0; i
< 3; i
++) {
1844 tcg_gen_shli_i32(tmp2
, tmp2
, 8);
1845 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1849 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
1850 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1857 case 0x103: case 0x503: case 0x903: case 0xd03: /* TMOVMSK */
1858 rd
= (insn
>> 12) & 0xf;
1859 rd0
= (insn
>> 16) & 0xf;
1860 if ((insn
& 0xf) != 0 || ((insn
>> 22) & 3) == 3)
1862 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1864 switch ((insn
>> 22) & 3) {
1866 gen_helper_iwmmxt_msbb(tmp
, cpu_M0
);
1869 gen_helper_iwmmxt_msbw(tmp
, cpu_M0
);
1872 gen_helper_iwmmxt_msbl(tmp
, cpu_M0
);
1875 store_reg(s
, rd
, tmp
);
1877 case 0x106: case 0x306: case 0x506: case 0x706: /* WCMPGT */
1878 case 0x906: case 0xb06: case 0xd06: case 0xf06:
1879 wrd
= (insn
>> 12) & 0xf;
1880 rd0
= (insn
>> 16) & 0xf;
1881 rd1
= (insn
>> 0) & 0xf;
1882 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1883 switch ((insn
>> 22) & 3) {
1885 if (insn
& (1 << 21))
1886 gen_op_iwmmxt_cmpgtsb_M0_wRn(rd1
);
1888 gen_op_iwmmxt_cmpgtub_M0_wRn(rd1
);
1891 if (insn
& (1 << 21))
1892 gen_op_iwmmxt_cmpgtsw_M0_wRn(rd1
);
1894 gen_op_iwmmxt_cmpgtuw_M0_wRn(rd1
);
1897 if (insn
& (1 << 21))
1898 gen_op_iwmmxt_cmpgtsl_M0_wRn(rd1
);
1900 gen_op_iwmmxt_cmpgtul_M0_wRn(rd1
);
1905 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1906 gen_op_iwmmxt_set_mup();
1907 gen_op_iwmmxt_set_cup();
1909 case 0x00e: case 0x20e: case 0x40e: case 0x60e: /* WUNPCKEL */
1910 case 0x80e: case 0xa0e: case 0xc0e: case 0xe0e:
1911 wrd
= (insn
>> 12) & 0xf;
1912 rd0
= (insn
>> 16) & 0xf;
1913 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1914 switch ((insn
>> 22) & 3) {
1916 if (insn
& (1 << 21))
1917 gen_op_iwmmxt_unpacklsb_M0();
1919 gen_op_iwmmxt_unpacklub_M0();
1922 if (insn
& (1 << 21))
1923 gen_op_iwmmxt_unpacklsw_M0();
1925 gen_op_iwmmxt_unpackluw_M0();
1928 if (insn
& (1 << 21))
1929 gen_op_iwmmxt_unpacklsl_M0();
1931 gen_op_iwmmxt_unpacklul_M0();
1936 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1937 gen_op_iwmmxt_set_mup();
1938 gen_op_iwmmxt_set_cup();
1940 case 0x00c: case 0x20c: case 0x40c: case 0x60c: /* WUNPCKEH */
1941 case 0x80c: case 0xa0c: case 0xc0c: case 0xe0c:
1942 wrd
= (insn
>> 12) & 0xf;
1943 rd0
= (insn
>> 16) & 0xf;
1944 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1945 switch ((insn
>> 22) & 3) {
1947 if (insn
& (1 << 21))
1948 gen_op_iwmmxt_unpackhsb_M0();
1950 gen_op_iwmmxt_unpackhub_M0();
1953 if (insn
& (1 << 21))
1954 gen_op_iwmmxt_unpackhsw_M0();
1956 gen_op_iwmmxt_unpackhuw_M0();
1959 if (insn
& (1 << 21))
1960 gen_op_iwmmxt_unpackhsl_M0();
1962 gen_op_iwmmxt_unpackhul_M0();
1967 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1968 gen_op_iwmmxt_set_mup();
1969 gen_op_iwmmxt_set_cup();
1971 case 0x204: case 0x604: case 0xa04: case 0xe04: /* WSRL */
1972 case 0x214: case 0x614: case 0xa14: case 0xe14:
1973 if (((insn
>> 22) & 3) == 0)
1975 wrd
= (insn
>> 12) & 0xf;
1976 rd0
= (insn
>> 16) & 0xf;
1977 gen_op_iwmmxt_movq_M0_wRn(rd0
);
1979 if (gen_iwmmxt_shift(insn
, 0xff, tmp
)) {
1983 switch ((insn
>> 22) & 3) {
1985 gen_helper_iwmmxt_srlw(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
1988 gen_helper_iwmmxt_srll(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
1991 gen_helper_iwmmxt_srlq(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
1995 gen_op_iwmmxt_movq_wRn_M0(wrd
);
1996 gen_op_iwmmxt_set_mup();
1997 gen_op_iwmmxt_set_cup();
1999 case 0x004: case 0x404: case 0x804: case 0xc04: /* WSRA */
2000 case 0x014: case 0x414: case 0x814: case 0xc14:
2001 if (((insn
>> 22) & 3) == 0)
2003 wrd
= (insn
>> 12) & 0xf;
2004 rd0
= (insn
>> 16) & 0xf;
2005 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2007 if (gen_iwmmxt_shift(insn
, 0xff, tmp
)) {
2011 switch ((insn
>> 22) & 3) {
2013 gen_helper_iwmmxt_sraw(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2016 gen_helper_iwmmxt_sral(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2019 gen_helper_iwmmxt_sraq(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2023 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2024 gen_op_iwmmxt_set_mup();
2025 gen_op_iwmmxt_set_cup();
2027 case 0x104: case 0x504: case 0x904: case 0xd04: /* WSLL */
2028 case 0x114: case 0x514: case 0x914: case 0xd14:
2029 if (((insn
>> 22) & 3) == 0)
2031 wrd
= (insn
>> 12) & 0xf;
2032 rd0
= (insn
>> 16) & 0xf;
2033 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2035 if (gen_iwmmxt_shift(insn
, 0xff, tmp
)) {
2039 switch ((insn
>> 22) & 3) {
2041 gen_helper_iwmmxt_sllw(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2044 gen_helper_iwmmxt_slll(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2047 gen_helper_iwmmxt_sllq(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2051 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2052 gen_op_iwmmxt_set_mup();
2053 gen_op_iwmmxt_set_cup();
2055 case 0x304: case 0x704: case 0xb04: case 0xf04: /* WROR */
2056 case 0x314: case 0x714: case 0xb14: case 0xf14:
2057 if (((insn
>> 22) & 3) == 0)
2059 wrd
= (insn
>> 12) & 0xf;
2060 rd0
= (insn
>> 16) & 0xf;
2061 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2063 switch ((insn
>> 22) & 3) {
2065 if (gen_iwmmxt_shift(insn
, 0xf, tmp
)) {
2069 gen_helper_iwmmxt_rorw(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2072 if (gen_iwmmxt_shift(insn
, 0x1f, tmp
)) {
2076 gen_helper_iwmmxt_rorl(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2079 if (gen_iwmmxt_shift(insn
, 0x3f, tmp
)) {
2083 gen_helper_iwmmxt_rorq(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2087 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2088 gen_op_iwmmxt_set_mup();
2089 gen_op_iwmmxt_set_cup();
2091 case 0x116: case 0x316: case 0x516: case 0x716: /* WMIN */
2092 case 0x916: case 0xb16: case 0xd16: case 0xf16:
2093 wrd
= (insn
>> 12) & 0xf;
2094 rd0
= (insn
>> 16) & 0xf;
2095 rd1
= (insn
>> 0) & 0xf;
2096 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2097 switch ((insn
>> 22) & 3) {
2099 if (insn
& (1 << 21))
2100 gen_op_iwmmxt_minsb_M0_wRn(rd1
);
2102 gen_op_iwmmxt_minub_M0_wRn(rd1
);
2105 if (insn
& (1 << 21))
2106 gen_op_iwmmxt_minsw_M0_wRn(rd1
);
2108 gen_op_iwmmxt_minuw_M0_wRn(rd1
);
2111 if (insn
& (1 << 21))
2112 gen_op_iwmmxt_minsl_M0_wRn(rd1
);
2114 gen_op_iwmmxt_minul_M0_wRn(rd1
);
2119 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2120 gen_op_iwmmxt_set_mup();
2122 case 0x016: case 0x216: case 0x416: case 0x616: /* WMAX */
2123 case 0x816: case 0xa16: case 0xc16: case 0xe16:
2124 wrd
= (insn
>> 12) & 0xf;
2125 rd0
= (insn
>> 16) & 0xf;
2126 rd1
= (insn
>> 0) & 0xf;
2127 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2128 switch ((insn
>> 22) & 3) {
2130 if (insn
& (1 << 21))
2131 gen_op_iwmmxt_maxsb_M0_wRn(rd1
);
2133 gen_op_iwmmxt_maxub_M0_wRn(rd1
);
2136 if (insn
& (1 << 21))
2137 gen_op_iwmmxt_maxsw_M0_wRn(rd1
);
2139 gen_op_iwmmxt_maxuw_M0_wRn(rd1
);
2142 if (insn
& (1 << 21))
2143 gen_op_iwmmxt_maxsl_M0_wRn(rd1
);
2145 gen_op_iwmmxt_maxul_M0_wRn(rd1
);
2150 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2151 gen_op_iwmmxt_set_mup();
2153 case 0x002: case 0x102: case 0x202: case 0x302: /* WALIGNI */
2154 case 0x402: case 0x502: case 0x602: case 0x702:
2155 wrd
= (insn
>> 12) & 0xf;
2156 rd0
= (insn
>> 16) & 0xf;
2157 rd1
= (insn
>> 0) & 0xf;
2158 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2159 tmp
= tcg_const_i32((insn
>> 20) & 3);
2160 iwmmxt_load_reg(cpu_V1
, rd1
);
2161 gen_helper_iwmmxt_align(cpu_M0
, cpu_M0
, cpu_V1
, tmp
);
2163 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2164 gen_op_iwmmxt_set_mup();
2166 case 0x01a: case 0x11a: case 0x21a: case 0x31a: /* WSUB */
2167 case 0x41a: case 0x51a: case 0x61a: case 0x71a:
2168 case 0x81a: case 0x91a: case 0xa1a: case 0xb1a:
2169 case 0xc1a: case 0xd1a: case 0xe1a: case 0xf1a:
2170 wrd
= (insn
>> 12) & 0xf;
2171 rd0
= (insn
>> 16) & 0xf;
2172 rd1
= (insn
>> 0) & 0xf;
2173 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2174 switch ((insn
>> 20) & 0xf) {
2176 gen_op_iwmmxt_subnb_M0_wRn(rd1
);
2179 gen_op_iwmmxt_subub_M0_wRn(rd1
);
2182 gen_op_iwmmxt_subsb_M0_wRn(rd1
);
2185 gen_op_iwmmxt_subnw_M0_wRn(rd1
);
2188 gen_op_iwmmxt_subuw_M0_wRn(rd1
);
2191 gen_op_iwmmxt_subsw_M0_wRn(rd1
);
2194 gen_op_iwmmxt_subnl_M0_wRn(rd1
);
2197 gen_op_iwmmxt_subul_M0_wRn(rd1
);
2200 gen_op_iwmmxt_subsl_M0_wRn(rd1
);
2205 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2206 gen_op_iwmmxt_set_mup();
2207 gen_op_iwmmxt_set_cup();
2209 case 0x01e: case 0x11e: case 0x21e: case 0x31e: /* WSHUFH */
2210 case 0x41e: case 0x51e: case 0x61e: case 0x71e:
2211 case 0x81e: case 0x91e: case 0xa1e: case 0xb1e:
2212 case 0xc1e: case 0xd1e: case 0xe1e: case 0xf1e:
2213 wrd
= (insn
>> 12) & 0xf;
2214 rd0
= (insn
>> 16) & 0xf;
2215 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2216 tmp
= tcg_const_i32(((insn
>> 16) & 0xf0) | (insn
& 0x0f));
2217 gen_helper_iwmmxt_shufh(cpu_M0
, cpu_env
, cpu_M0
, tmp
);
2219 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2220 gen_op_iwmmxt_set_mup();
2221 gen_op_iwmmxt_set_cup();
2223 case 0x018: case 0x118: case 0x218: case 0x318: /* WADD */
2224 case 0x418: case 0x518: case 0x618: case 0x718:
2225 case 0x818: case 0x918: case 0xa18: case 0xb18:
2226 case 0xc18: case 0xd18: case 0xe18: case 0xf18:
2227 wrd
= (insn
>> 12) & 0xf;
2228 rd0
= (insn
>> 16) & 0xf;
2229 rd1
= (insn
>> 0) & 0xf;
2230 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2231 switch ((insn
>> 20) & 0xf) {
2233 gen_op_iwmmxt_addnb_M0_wRn(rd1
);
2236 gen_op_iwmmxt_addub_M0_wRn(rd1
);
2239 gen_op_iwmmxt_addsb_M0_wRn(rd1
);
2242 gen_op_iwmmxt_addnw_M0_wRn(rd1
);
2245 gen_op_iwmmxt_adduw_M0_wRn(rd1
);
2248 gen_op_iwmmxt_addsw_M0_wRn(rd1
);
2251 gen_op_iwmmxt_addnl_M0_wRn(rd1
);
2254 gen_op_iwmmxt_addul_M0_wRn(rd1
);
2257 gen_op_iwmmxt_addsl_M0_wRn(rd1
);
2262 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2263 gen_op_iwmmxt_set_mup();
2264 gen_op_iwmmxt_set_cup();
2266 case 0x008: case 0x108: case 0x208: case 0x308: /* WPACK */
2267 case 0x408: case 0x508: case 0x608: case 0x708:
2268 case 0x808: case 0x908: case 0xa08: case 0xb08:
2269 case 0xc08: case 0xd08: case 0xe08: case 0xf08:
2270 if (!(insn
& (1 << 20)) || ((insn
>> 22) & 3) == 0)
2272 wrd
= (insn
>> 12) & 0xf;
2273 rd0
= (insn
>> 16) & 0xf;
2274 rd1
= (insn
>> 0) & 0xf;
2275 gen_op_iwmmxt_movq_M0_wRn(rd0
);
2276 switch ((insn
>> 22) & 3) {
2278 if (insn
& (1 << 21))
2279 gen_op_iwmmxt_packsw_M0_wRn(rd1
);
2281 gen_op_iwmmxt_packuw_M0_wRn(rd1
);
2284 if (insn
& (1 << 21))
2285 gen_op_iwmmxt_packsl_M0_wRn(rd1
);
2287 gen_op_iwmmxt_packul_M0_wRn(rd1
);
2290 if (insn
& (1 << 21))
2291 gen_op_iwmmxt_packsq_M0_wRn(rd1
);
2293 gen_op_iwmmxt_packuq_M0_wRn(rd1
);
2296 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2297 gen_op_iwmmxt_set_mup();
2298 gen_op_iwmmxt_set_cup();
2300 case 0x201: case 0x203: case 0x205: case 0x207:
2301 case 0x209: case 0x20b: case 0x20d: case 0x20f:
2302 case 0x211: case 0x213: case 0x215: case 0x217:
2303 case 0x219: case 0x21b: case 0x21d: case 0x21f:
2304 wrd
= (insn
>> 5) & 0xf;
2305 rd0
= (insn
>> 12) & 0xf;
2306 rd1
= (insn
>> 0) & 0xf;
2307 if (rd0
== 0xf || rd1
== 0xf)
2309 gen_op_iwmmxt_movq_M0_wRn(wrd
);
2310 tmp
= load_reg(s
, rd0
);
2311 tmp2
= load_reg(s
, rd1
);
2312 switch ((insn
>> 16) & 0xf) {
2313 case 0x0: /* TMIA */
2314 gen_helper_iwmmxt_muladdsl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2316 case 0x8: /* TMIAPH */
2317 gen_helper_iwmmxt_muladdsw(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2319 case 0xc: case 0xd: case 0xe: case 0xf: /* TMIAxy */
2320 if (insn
& (1 << 16))
2321 tcg_gen_shri_i32(tmp
, tmp
, 16);
2322 if (insn
& (1 << 17))
2323 tcg_gen_shri_i32(tmp2
, tmp2
, 16);
2324 gen_helper_iwmmxt_muladdswl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2333 gen_op_iwmmxt_movq_wRn_M0(wrd
);
2334 gen_op_iwmmxt_set_mup();
2343 /* Disassemble an XScale DSP instruction. Returns nonzero if an error occured
2344 (ie. an undefined instruction). */
2345 static int disas_dsp_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
2347 int acc
, rd0
, rd1
, rdhi
, rdlo
;
2350 if ((insn
& 0x0ff00f10) == 0x0e200010) {
2351 /* Multiply with Internal Accumulate Format */
2352 rd0
= (insn
>> 12) & 0xf;
2354 acc
= (insn
>> 5) & 7;
2359 tmp
= load_reg(s
, rd0
);
2360 tmp2
= load_reg(s
, rd1
);
2361 switch ((insn
>> 16) & 0xf) {
2363 gen_helper_iwmmxt_muladdsl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2365 case 0x8: /* MIAPH */
2366 gen_helper_iwmmxt_muladdsw(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2368 case 0xc: /* MIABB */
2369 case 0xd: /* MIABT */
2370 case 0xe: /* MIATB */
2371 case 0xf: /* MIATT */
2372 if (insn
& (1 << 16))
2373 tcg_gen_shri_i32(tmp
, tmp
, 16);
2374 if (insn
& (1 << 17))
2375 tcg_gen_shri_i32(tmp2
, tmp2
, 16);
2376 gen_helper_iwmmxt_muladdswl(cpu_M0
, cpu_M0
, tmp
, tmp2
);
2384 gen_op_iwmmxt_movq_wRn_M0(acc
);
2388 if ((insn
& 0x0fe00ff8) == 0x0c400000) {
2389 /* Internal Accumulator Access Format */
2390 rdhi
= (insn
>> 16) & 0xf;
2391 rdlo
= (insn
>> 12) & 0xf;
2397 if (insn
& ARM_CP_RW_BIT
) { /* MRA */
2398 iwmmxt_load_reg(cpu_V0
, acc
);
2399 tcg_gen_trunc_i64_i32(cpu_R
[rdlo
], cpu_V0
);
2400 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
2401 tcg_gen_trunc_i64_i32(cpu_R
[rdhi
], cpu_V0
);
2402 tcg_gen_andi_i32(cpu_R
[rdhi
], cpu_R
[rdhi
], (1 << (40 - 32)) - 1);
2404 tcg_gen_concat_i32_i64(cpu_V0
, cpu_R
[rdlo
], cpu_R
[rdhi
]);
2405 iwmmxt_store_reg(cpu_V0
, acc
);
2413 /* Disassemble system coprocessor instruction. Return nonzero if
2414 instruction is not defined. */
2415 static int disas_cp_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
2418 uint32_t rd
= (insn
>> 12) & 0xf;
2419 uint32_t cp
= (insn
>> 8) & 0xf;
2424 if (insn
& ARM_CP_RW_BIT
) {
2425 if (!env
->cp
[cp
].cp_read
)
2427 gen_set_pc_im(s
->pc
);
2429 tmp2
= tcg_const_i32(insn
);
2430 gen_helper_get_cp(tmp
, cpu_env
, tmp2
);
2431 tcg_temp_free(tmp2
);
2432 store_reg(s
, rd
, tmp
);
2434 if (!env
->cp
[cp
].cp_write
)
2436 gen_set_pc_im(s
->pc
);
2437 tmp
= load_reg(s
, rd
);
2438 tmp2
= tcg_const_i32(insn
);
2439 gen_helper_set_cp(cpu_env
, tmp2
, tmp
);
2440 tcg_temp_free(tmp2
);
2446 static int cp15_user_ok(uint32_t insn
)
2448 int cpn
= (insn
>> 16) & 0xf;
2449 int cpm
= insn
& 0xf;
2450 int op
= ((insn
>> 5) & 7) | ((insn
>> 18) & 0x38);
2452 if (cpn
== 13 && cpm
== 0) {
2454 if (op
== 2 || (op
== 3 && (insn
& ARM_CP_RW_BIT
)))
2458 /* ISB, DSB, DMB. */
2459 if ((cpm
== 5 && op
== 4)
2460 || (cpm
== 10 && (op
== 4 || op
== 5)))
2466 static int cp15_tls_load_store(CPUState
*env
, DisasContext
*s
, uint32_t insn
, uint32_t rd
)
2469 int cpn
= (insn
>> 16) & 0xf;
2470 int cpm
= insn
& 0xf;
2471 int op
= ((insn
>> 5) & 7) | ((insn
>> 18) & 0x38);
2473 if (!arm_feature(env
, ARM_FEATURE_V6K
))
2476 if (!(cpn
== 13 && cpm
== 0))
2479 if (insn
& ARM_CP_RW_BIT
) {
2482 tmp
= load_cpu_field(cp15
.c13_tls1
);
2485 tmp
= load_cpu_field(cp15
.c13_tls2
);
2488 tmp
= load_cpu_field(cp15
.c13_tls3
);
2493 store_reg(s
, rd
, tmp
);
2496 tmp
= load_reg(s
, rd
);
2499 store_cpu_field(tmp
, cp15
.c13_tls1
);
2502 store_cpu_field(tmp
, cp15
.c13_tls2
);
2505 store_cpu_field(tmp
, cp15
.c13_tls3
);
2515 /* Disassemble system coprocessor (cp15) instruction. Return nonzero if
2516 instruction is not defined. */
2517 static int disas_cp15_insn(CPUState
*env
, DisasContext
*s
, uint32_t insn
)
2522 /* M profile cores use memory mapped registers instead of cp15. */
2523 if (arm_feature(env
, ARM_FEATURE_M
))
2526 if ((insn
& (1 << 25)) == 0) {
2527 if (insn
& (1 << 20)) {
2531 /* mcrr. Used for block cache operations, so implement as no-op. */
2534 if ((insn
& (1 << 4)) == 0) {
2538 if (IS_USER(s
) && !cp15_user_ok(insn
)) {
2541 if ((insn
& 0x0fff0fff) == 0x0e070f90
2542 || (insn
& 0x0fff0fff) == 0x0e070f58) {
2543 /* Wait for interrupt. */
2544 gen_set_pc_im(s
->pc
);
2545 s
->is_jmp
= DISAS_WFI
;
2548 rd
= (insn
>> 12) & 0xf;
2550 if (cp15_tls_load_store(env
, s
, insn
, rd
))
2553 tmp2
= tcg_const_i32(insn
);
2554 if (insn
& ARM_CP_RW_BIT
) {
2556 gen_helper_get_cp15(tmp
, cpu_env
, tmp2
);
2557 /* If the destination register is r15 then sets condition codes. */
2559 store_reg(s
, rd
, tmp
);
2563 tmp
= load_reg(s
, rd
);
2564 gen_helper_set_cp15(cpu_env
, tmp2
, tmp
);
2566 /* Normally we would always end the TB here, but Linux
2567 * arch/arm/mach-pxa/sleep.S expects two instructions following
2568 * an MMU enable to execute from cache. Imitate this behaviour. */
2569 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) ||
2570 (insn
& 0x0fff0fff) != 0x0e010f10)
2573 tcg_temp_free_i32(tmp2
);
2577 #define VFP_REG_SHR(x, n) (((n) > 0) ? (x) >> (n) : (x) << -(n))
2578 #define VFP_SREG(insn, bigbit, smallbit) \
2579 ((VFP_REG_SHR(insn, bigbit - 1) & 0x1e) | (((insn) >> (smallbit)) & 1))
2580 #define VFP_DREG(reg, insn, bigbit, smallbit) do { \
2581 if (arm_feature(env, ARM_FEATURE_VFP3)) { \
2582 reg = (((insn) >> (bigbit)) & 0x0f) \
2583 | (((insn) >> ((smallbit) - 4)) & 0x10); \
2585 if (insn & (1 << (smallbit))) \
2587 reg = ((insn) >> (bigbit)) & 0x0f; \
2590 #define VFP_SREG_D(insn) VFP_SREG(insn, 12, 22)
2591 #define VFP_DREG_D(reg, insn) VFP_DREG(reg, insn, 12, 22)
2592 #define VFP_SREG_N(insn) VFP_SREG(insn, 16, 7)
2593 #define VFP_DREG_N(reg, insn) VFP_DREG(reg, insn, 16, 7)
2594 #define VFP_SREG_M(insn) VFP_SREG(insn, 0, 5)
2595 #define VFP_DREG_M(reg, insn) VFP_DREG(reg, insn, 0, 5)
2597 /* Move between integer and VFP cores. */
2598 static TCGv
gen_vfp_mrs(void)
2600 TCGv tmp
= new_tmp();
2601 tcg_gen_mov_i32(tmp
, cpu_F0s
);
2605 static void gen_vfp_msr(TCGv tmp
)
2607 tcg_gen_mov_i32(cpu_F0s
, tmp
);
2611 static void gen_neon_dup_u8(TCGv var
, int shift
)
2613 TCGv tmp
= new_tmp();
2615 tcg_gen_shri_i32(var
, var
, shift
);
2616 tcg_gen_ext8u_i32(var
, var
);
2617 tcg_gen_shli_i32(tmp
, var
, 8);
2618 tcg_gen_or_i32(var
, var
, tmp
);
2619 tcg_gen_shli_i32(tmp
, var
, 16);
2620 tcg_gen_or_i32(var
, var
, tmp
);
2624 static void gen_neon_dup_low16(TCGv var
)
2626 TCGv tmp
= new_tmp();
2627 tcg_gen_ext16u_i32(var
, var
);
2628 tcg_gen_shli_i32(tmp
, var
, 16);
2629 tcg_gen_or_i32(var
, var
, tmp
);
2633 static void gen_neon_dup_high16(TCGv var
)
2635 TCGv tmp
= new_tmp();
2636 tcg_gen_andi_i32(var
, var
, 0xffff0000);
2637 tcg_gen_shri_i32(tmp
, var
, 16);
2638 tcg_gen_or_i32(var
, var
, tmp
);
2642 /* Disassemble a VFP instruction. Returns nonzero if an error occured
2643 (ie. an undefined instruction). */
2644 static int disas_vfp_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
2646 uint32_t rd
, rn
, rm
, op
, i
, n
, offset
, delta_d
, delta_m
, bank_mask
;
2652 if (!arm_feature(env
, ARM_FEATURE_VFP
))
2655 if (!s
->vfp_enabled
) {
2656 /* VFP disabled. Only allow fmxr/fmrx to/from some control regs. */
2657 if ((insn
& 0x0fe00fff) != 0x0ee00a10)
2659 rn
= (insn
>> 16) & 0xf;
2660 if (rn
!= ARM_VFP_FPSID
&& rn
!= ARM_VFP_FPEXC
2661 && rn
!= ARM_VFP_MVFR1
&& rn
!= ARM_VFP_MVFR0
)
2664 dp
= ((insn
& 0xf00) == 0xb00);
2665 switch ((insn
>> 24) & 0xf) {
2667 if (insn
& (1 << 4)) {
2668 /* single register transfer */
2669 rd
= (insn
>> 12) & 0xf;
2674 VFP_DREG_N(rn
, insn
);
2677 if (insn
& 0x00c00060
2678 && !arm_feature(env
, ARM_FEATURE_NEON
))
2681 pass
= (insn
>> 21) & 1;
2682 if (insn
& (1 << 22)) {
2684 offset
= ((insn
>> 5) & 3) * 8;
2685 } else if (insn
& (1 << 5)) {
2687 offset
= (insn
& (1 << 6)) ? 16 : 0;
2692 if (insn
& ARM_CP_RW_BIT
) {
2694 tmp
= neon_load_reg(rn
, pass
);
2698 tcg_gen_shri_i32(tmp
, tmp
, offset
);
2699 if (insn
& (1 << 23))
2705 if (insn
& (1 << 23)) {
2707 tcg_gen_shri_i32(tmp
, tmp
, 16);
2713 tcg_gen_sari_i32(tmp
, tmp
, 16);
2722 store_reg(s
, rd
, tmp
);
2725 tmp
= load_reg(s
, rd
);
2726 if (insn
& (1 << 23)) {
2729 gen_neon_dup_u8(tmp
, 0);
2730 } else if (size
== 1) {
2731 gen_neon_dup_low16(tmp
);
2733 for (n
= 0; n
<= pass
* 2; n
++) {
2735 tcg_gen_mov_i32(tmp2
, tmp
);
2736 neon_store_reg(rn
, n
, tmp2
);
2738 neon_store_reg(rn
, n
, tmp
);
2743 tmp2
= neon_load_reg(rn
, pass
);
2744 gen_bfi(tmp
, tmp2
, tmp
, offset
, 0xff);
2748 tmp2
= neon_load_reg(rn
, pass
);
2749 gen_bfi(tmp
, tmp2
, tmp
, offset
, 0xffff);
2755 neon_store_reg(rn
, pass
, tmp
);
2759 if ((insn
& 0x6f) != 0x00)
2761 rn
= VFP_SREG_N(insn
);
2762 if (insn
& ARM_CP_RW_BIT
) {
2764 if (insn
& (1 << 21)) {
2765 /* system register */
2770 /* VFP2 allows access to FSID from userspace.
2771 VFP3 restricts all id registers to privileged
2774 && arm_feature(env
, ARM_FEATURE_VFP3
))
2776 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2781 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2783 case ARM_VFP_FPINST
:
2784 case ARM_VFP_FPINST2
:
2785 /* Not present in VFP3. */
2787 || arm_feature(env
, ARM_FEATURE_VFP3
))
2789 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2793 tmp
= load_cpu_field(vfp
.xregs
[ARM_VFP_FPSCR
]);
2794 tcg_gen_andi_i32(tmp
, tmp
, 0xf0000000);
2797 gen_helper_vfp_get_fpscr(tmp
, cpu_env
);
2803 || !arm_feature(env
, ARM_FEATURE_VFP3
))
2805 tmp
= load_cpu_field(vfp
.xregs
[rn
]);
2811 gen_mov_F0_vreg(0, rn
);
2812 tmp
= gen_vfp_mrs();
2815 /* Set the 4 flag bits in the CPSR. */
2819 store_reg(s
, rd
, tmp
);
2823 tmp
= load_reg(s
, rd
);
2824 if (insn
& (1 << 21)) {
2826 /* system register */
2831 /* Writes are ignored. */
2834 gen_helper_vfp_set_fpscr(cpu_env
, tmp
);
2841 /* TODO: VFP subarchitecture support.
2842 * For now, keep the EN bit only */
2843 tcg_gen_andi_i32(tmp
, tmp
, 1 << 30);
2844 store_cpu_field(tmp
, vfp
.xregs
[rn
]);
2847 case ARM_VFP_FPINST
:
2848 case ARM_VFP_FPINST2
:
2849 store_cpu_field(tmp
, vfp
.xregs
[rn
]);
2856 gen_mov_vreg_F0(0, rn
);
2861 /* data processing */
2862 /* The opcode is in bits 23, 21, 20 and 6. */
2863 op
= ((insn
>> 20) & 8) | ((insn
>> 19) & 6) | ((insn
>> 6) & 1);
2867 rn
= ((insn
>> 15) & 0x1e) | ((insn
>> 7) & 1);
2869 /* rn is register number */
2870 VFP_DREG_N(rn
, insn
);
2873 if (op
== 15 && (rn
== 15 || ((rn
& 0x1c) == 0x18))) {
2874 /* Integer or single precision destination. */
2875 rd
= VFP_SREG_D(insn
);
2877 VFP_DREG_D(rd
, insn
);
2880 (((rn
& 0x1c) == 0x10) || ((rn
& 0x14) == 0x14))) {
2881 /* VCVT from int is always from S reg regardless of dp bit.
2882 * VCVT with immediate frac_bits has same format as SREG_M
2884 rm
= VFP_SREG_M(insn
);
2886 VFP_DREG_M(rm
, insn
);
2889 rn
= VFP_SREG_N(insn
);
2890 if (op
== 15 && rn
== 15) {
2891 /* Double precision destination. */
2892 VFP_DREG_D(rd
, insn
);
2894 rd
= VFP_SREG_D(insn
);
2896 /* NB that we implicitly rely on the encoding for the frac_bits
2897 * in VCVT of fixed to float being the same as that of an SREG_M
2899 rm
= VFP_SREG_M(insn
);
2902 veclen
= s
->vec_len
;
2903 if (op
== 15 && rn
> 3)
2906 /* Shut up compiler warnings. */
2917 /* Figure out what type of vector operation this is. */
2918 if ((rd
& bank_mask
) == 0) {
2923 delta_d
= (s
->vec_stride
>> 1) + 1;
2925 delta_d
= s
->vec_stride
+ 1;
2927 if ((rm
& bank_mask
) == 0) {
2928 /* mixed scalar/vector */
2937 /* Load the initial operands. */
2942 /* Integer source */
2943 gen_mov_F0_vreg(0, rm
);
2948 gen_mov_F0_vreg(dp
, rd
);
2949 gen_mov_F1_vreg(dp
, rm
);
2953 /* Compare with zero */
2954 gen_mov_F0_vreg(dp
, rd
);
2965 /* Source and destination the same. */
2966 gen_mov_F0_vreg(dp
, rd
);
2969 /* One source operand. */
2970 gen_mov_F0_vreg(dp
, rm
);
2974 /* Two source operands. */
2975 gen_mov_F0_vreg(dp
, rn
);
2976 gen_mov_F1_vreg(dp
, rm
);
2980 /* Perform the calculation. */
2982 case 0: /* mac: fd + (fn * fm) */
2984 gen_mov_F1_vreg(dp
, rd
);
2987 case 1: /* nmac: fd - (fn * fm) */
2990 gen_mov_F1_vreg(dp
, rd
);
2993 case 2: /* msc: -fd + (fn * fm) */
2995 gen_mov_F1_vreg(dp
, rd
);
2998 case 3: /* nmsc: -fd - (fn * fm) */
3001 gen_mov_F1_vreg(dp
, rd
);
3004 case 4: /* mul: fn * fm */
3007 case 5: /* nmul: -(fn * fm) */
3011 case 6: /* add: fn + fm */
3014 case 7: /* sub: fn - fm */
3017 case 8: /* div: fn / fm */
3020 case 14: /* fconst */
3021 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3024 n
= (insn
<< 12) & 0x80000000;
3025 i
= ((insn
>> 12) & 0x70) | (insn
& 0xf);
3032 tcg_gen_movi_i64(cpu_F0d
, ((uint64_t)n
) << 32);
3039 tcg_gen_movi_i32(cpu_F0s
, n
);
3042 case 15: /* extension space */
3056 case 4: /* vcvtb.f32.f16 */
3057 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3059 tmp
= gen_vfp_mrs();
3060 tcg_gen_ext16u_i32(tmp
, tmp
);
3061 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp
, cpu_env
);
3064 case 5: /* vcvtt.f32.f16 */
3065 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3067 tmp
= gen_vfp_mrs();
3068 tcg_gen_shri_i32(tmp
, tmp
, 16);
3069 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp
, cpu_env
);
3072 case 6: /* vcvtb.f16.f32 */
3073 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3076 gen_helper_vfp_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
3077 gen_mov_F0_vreg(0, rd
);
3078 tmp2
= gen_vfp_mrs();
3079 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffff0000);
3080 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3084 case 7: /* vcvtt.f16.f32 */
3085 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
3088 gen_helper_vfp_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
3089 tcg_gen_shli_i32(tmp
, tmp
, 16);
3090 gen_mov_F0_vreg(0, rd
);
3091 tmp2
= gen_vfp_mrs();
3092 tcg_gen_ext16u_i32(tmp2
, tmp2
);
3093 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3106 case 11: /* cmpez */
3110 case 15: /* single<->double conversion */
3112 gen_helper_vfp_fcvtsd(cpu_F0s
, cpu_F0d
, cpu_env
);
3114 gen_helper_vfp_fcvtds(cpu_F0d
, cpu_F0s
, cpu_env
);
3116 case 16: /* fuito */
3119 case 17: /* fsito */
3122 case 20: /* fshto */
3123 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3125 gen_vfp_shto(dp
, 16 - rm
);
3127 case 21: /* fslto */
3128 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3130 gen_vfp_slto(dp
, 32 - rm
);
3132 case 22: /* fuhto */
3133 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3135 gen_vfp_uhto(dp
, 16 - rm
);
3137 case 23: /* fulto */
3138 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3140 gen_vfp_ulto(dp
, 32 - rm
);
3142 case 24: /* ftoui */
3145 case 25: /* ftouiz */
3148 case 26: /* ftosi */
3151 case 27: /* ftosiz */
3154 case 28: /* ftosh */
3155 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3157 gen_vfp_tosh(dp
, 16 - rm
);
3159 case 29: /* ftosl */
3160 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3162 gen_vfp_tosl(dp
, 32 - rm
);
3164 case 30: /* ftouh */
3165 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3167 gen_vfp_touh(dp
, 16 - rm
);
3169 case 31: /* ftoul */
3170 if (!arm_feature(env
, ARM_FEATURE_VFP3
))
3172 gen_vfp_toul(dp
, 32 - rm
);
3174 default: /* undefined */
3175 printf ("rn:%d\n", rn
);
3179 default: /* undefined */
3180 printf ("op:%d\n", op
);
3184 /* Write back the result. */
3185 if (op
== 15 && (rn
>= 8 && rn
<= 11))
3186 ; /* Comparison, do nothing. */
3187 else if (op
== 15 && dp
&& ((rn
& 0x1c) == 0x18))
3188 /* VCVT double to int: always integer result. */
3189 gen_mov_vreg_F0(0, rd
);
3190 else if (op
== 15 && rn
== 15)
3192 gen_mov_vreg_F0(!dp
, rd
);
3194 gen_mov_vreg_F0(dp
, rd
);
3196 /* break out of the loop if we have finished */
3200 if (op
== 15 && delta_m
== 0) {
3201 /* single source one-many */
3203 rd
= ((rd
+ delta_d
) & (bank_mask
- 1))
3205 gen_mov_vreg_F0(dp
, rd
);
3209 /* Setup the next operands. */
3211 rd
= ((rd
+ delta_d
) & (bank_mask
- 1))
3215 /* One source operand. */
3216 rm
= ((rm
+ delta_m
) & (bank_mask
- 1))
3218 gen_mov_F0_vreg(dp
, rm
);
3220 /* Two source operands. */
3221 rn
= ((rn
+ delta_d
) & (bank_mask
- 1))
3223 gen_mov_F0_vreg(dp
, rn
);
3225 rm
= ((rm
+ delta_m
) & (bank_mask
- 1))
3227 gen_mov_F1_vreg(dp
, rm
);
3235 if (dp
&& (insn
& 0x03e00000) == 0x00400000) {
3236 /* two-register transfer */
3237 rn
= (insn
>> 16) & 0xf;
3238 rd
= (insn
>> 12) & 0xf;
3240 VFP_DREG_M(rm
, insn
);
3242 rm
= VFP_SREG_M(insn
);
3245 if (insn
& ARM_CP_RW_BIT
) {
3248 gen_mov_F0_vreg(0, rm
* 2);
3249 tmp
= gen_vfp_mrs();
3250 store_reg(s
, rd
, tmp
);
3251 gen_mov_F0_vreg(0, rm
* 2 + 1);
3252 tmp
= gen_vfp_mrs();
3253 store_reg(s
, rn
, tmp
);
3255 gen_mov_F0_vreg(0, rm
);
3256 tmp
= gen_vfp_mrs();
3257 store_reg(s
, rn
, tmp
);
3258 gen_mov_F0_vreg(0, rm
+ 1);
3259 tmp
= gen_vfp_mrs();
3260 store_reg(s
, rd
, tmp
);
3265 tmp
= load_reg(s
, rd
);
3267 gen_mov_vreg_F0(0, rm
* 2);
3268 tmp
= load_reg(s
, rn
);
3270 gen_mov_vreg_F0(0, rm
* 2 + 1);
3272 tmp
= load_reg(s
, rn
);
3274 gen_mov_vreg_F0(0, rm
);
3275 tmp
= load_reg(s
, rd
);
3277 gen_mov_vreg_F0(0, rm
+ 1);
3282 rn
= (insn
>> 16) & 0xf;
3284 VFP_DREG_D(rd
, insn
);
3286 rd
= VFP_SREG_D(insn
);
3287 if (s
->thumb
&& rn
== 15) {
3289 tcg_gen_movi_i32(addr
, s
->pc
& ~2);
3291 addr
= load_reg(s
, rn
);
3293 if ((insn
& 0x01200000) == 0x01000000) {
3294 /* Single load/store */
3295 offset
= (insn
& 0xff) << 2;
3296 if ((insn
& (1 << 23)) == 0)
3298 tcg_gen_addi_i32(addr
, addr
, offset
);
3299 if (insn
& (1 << 20)) {
3300 gen_vfp_ld(s
, dp
, addr
);
3301 gen_mov_vreg_F0(dp
, rd
);
3303 gen_mov_F0_vreg(dp
, rd
);
3304 gen_vfp_st(s
, dp
, addr
);
3308 /* load/store multiple */
3310 n
= (insn
>> 1) & 0x7f;
3314 if (insn
& (1 << 24)) /* pre-decrement */
3315 tcg_gen_addi_i32(addr
, addr
, -((insn
& 0xff) << 2));
3321 for (i
= 0; i
< n
; i
++) {
3322 if (insn
& ARM_CP_RW_BIT
) {
3324 gen_vfp_ld(s
, dp
, addr
);
3325 gen_mov_vreg_F0(dp
, rd
+ i
);
3328 gen_mov_F0_vreg(dp
, rd
+ i
);
3329 gen_vfp_st(s
, dp
, addr
);
3331 tcg_gen_addi_i32(addr
, addr
, offset
);
3333 if (insn
& (1 << 21)) {
3335 if (insn
& (1 << 24))
3336 offset
= -offset
* n
;
3337 else if (dp
&& (insn
& 1))
3343 tcg_gen_addi_i32(addr
, addr
, offset
);
3344 store_reg(s
, rn
, addr
);
3352 /* Should never happen. */
3358 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint32_t dest
)
3360 TranslationBlock
*tb
;
3363 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
3365 gen_set_pc_im(dest
);
3366 tcg_gen_exit_tb((long)tb
+ n
);
3368 gen_set_pc_im(dest
);
3373 static inline void gen_jmp (DisasContext
*s
, uint32_t dest
)
3375 if (unlikely(s
->singlestep_enabled
)) {
3376 /* An indirect jump so that we still trigger the debug exception. */
3381 gen_goto_tb(s
, 0, dest
);
3382 s
->is_jmp
= DISAS_TB_JUMP
;
3386 static inline void gen_mulxy(TCGv t0
, TCGv t1
, int x
, int y
)
3389 tcg_gen_sari_i32(t0
, t0
, 16);
3393 tcg_gen_sari_i32(t1
, t1
, 16);
3396 tcg_gen_mul_i32(t0
, t0
, t1
);
3399 /* Return the mask of PSR bits set by a MSR instruction. */
3400 static uint32_t msr_mask(CPUState
*env
, DisasContext
*s
, int flags
, int spsr
) {
3404 if (flags
& (1 << 0))
3406 if (flags
& (1 << 1))
3408 if (flags
& (1 << 2))
3410 if (flags
& (1 << 3))
3413 /* Mask out undefined bits. */
3414 mask
&= ~CPSR_RESERVED
;
3415 if (!arm_feature(env
, ARM_FEATURE_V6
))
3416 mask
&= ~(CPSR_E
| CPSR_GE
);
3417 if (!arm_feature(env
, ARM_FEATURE_THUMB2
))
3419 /* Mask out execution state bits. */
3422 /* Mask out privileged bits. */
3428 /* Returns nonzero if access to the PSR is not permitted. Marks t0 as dead. */
3429 static int gen_set_psr(DisasContext
*s
, uint32_t mask
, int spsr
, TCGv t0
)
3433 /* ??? This is also undefined in system mode. */
3437 tmp
= load_cpu_field(spsr
);
3438 tcg_gen_andi_i32(tmp
, tmp
, ~mask
);
3439 tcg_gen_andi_i32(t0
, t0
, mask
);
3440 tcg_gen_or_i32(tmp
, tmp
, t0
);
3441 store_cpu_field(tmp
, spsr
);
3443 gen_set_cpsr(t0
, mask
);
3450 /* Returns nonzero if access to the PSR is not permitted. */
3451 static int gen_set_psr_im(DisasContext
*s
, uint32_t mask
, int spsr
, uint32_t val
)
3455 tcg_gen_movi_i32(tmp
, val
);
3456 return gen_set_psr(s
, mask
, spsr
, tmp
);
3459 /* Generate an old-style exception return. Marks pc as dead. */
3460 static void gen_exception_return(DisasContext
*s
, TCGv pc
)
3463 store_reg(s
, 15, pc
);
3464 tmp
= load_cpu_field(spsr
);
3465 gen_set_cpsr(tmp
, 0xffffffff);
3467 s
->is_jmp
= DISAS_UPDATE
;
3470 /* Generate a v6 exception return. Marks both values as dead. */
3471 static void gen_rfe(DisasContext
*s
, TCGv pc
, TCGv cpsr
)
3473 gen_set_cpsr(cpsr
, 0xffffffff);
3475 store_reg(s
, 15, pc
);
3476 s
->is_jmp
= DISAS_UPDATE
;
3480 gen_set_condexec (DisasContext
*s
)
3482 if (s
->condexec_mask
) {
3483 uint32_t val
= (s
->condexec_cond
<< 4) | (s
->condexec_mask
>> 1);
3484 TCGv tmp
= new_tmp();
3485 tcg_gen_movi_i32(tmp
, val
);
3486 store_cpu_field(tmp
, condexec_bits
);
3490 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
)
3492 gen_set_condexec(s
);
3493 gen_set_pc_im(s
->pc
- offset
);
3494 gen_exception(excp
);
3495 s
->is_jmp
= DISAS_JUMP
;
3498 static void gen_nop_hint(DisasContext
*s
, int val
)
3502 gen_set_pc_im(s
->pc
);
3503 s
->is_jmp
= DISAS_WFI
;
3507 /* TODO: Implement SEV and WFE. May help SMP performance. */
3513 #define CPU_V001 cpu_V0, cpu_V0, cpu_V1
3515 static inline int gen_neon_add(int size
, TCGv t0
, TCGv t1
)
3518 case 0: gen_helper_neon_add_u8(t0
, t0
, t1
); break;
3519 case 1: gen_helper_neon_add_u16(t0
, t0
, t1
); break;
3520 case 2: tcg_gen_add_i32(t0
, t0
, t1
); break;
3526 static inline void gen_neon_rsb(int size
, TCGv t0
, TCGv t1
)
3529 case 0: gen_helper_neon_sub_u8(t0
, t1
, t0
); break;
3530 case 1: gen_helper_neon_sub_u16(t0
, t1
, t0
); break;
3531 case 2: tcg_gen_sub_i32(t0
, t1
, t0
); break;
3536 /* 32-bit pairwise ops end up the same as the elementwise versions. */
3537 #define gen_helper_neon_pmax_s32 gen_helper_neon_max_s32
3538 #define gen_helper_neon_pmax_u32 gen_helper_neon_max_u32
3539 #define gen_helper_neon_pmin_s32 gen_helper_neon_min_s32
3540 #define gen_helper_neon_pmin_u32 gen_helper_neon_min_u32
3542 #define GEN_NEON_INTEGER_OP_ENV(name) do { \
3543 switch ((size << 1) | u) { \
3545 gen_helper_neon_##name##_s8(tmp, cpu_env, tmp, tmp2); \
3548 gen_helper_neon_##name##_u8(tmp, cpu_env, tmp, tmp2); \
3551 gen_helper_neon_##name##_s16(tmp, cpu_env, tmp, tmp2); \
3554 gen_helper_neon_##name##_u16(tmp, cpu_env, tmp, tmp2); \
3557 gen_helper_neon_##name##_s32(tmp, cpu_env, tmp, tmp2); \
3560 gen_helper_neon_##name##_u32(tmp, cpu_env, tmp, tmp2); \
3562 default: return 1; \
3565 #define GEN_NEON_INTEGER_OP(name) do { \
3566 switch ((size << 1) | u) { \
3568 gen_helper_neon_##name##_s8(tmp, tmp, tmp2); \
3571 gen_helper_neon_##name##_u8(tmp, tmp, tmp2); \
3574 gen_helper_neon_##name##_s16(tmp, tmp, tmp2); \
3577 gen_helper_neon_##name##_u16(tmp, tmp, tmp2); \
3580 gen_helper_neon_##name##_s32(tmp, tmp, tmp2); \
3583 gen_helper_neon_##name##_u32(tmp, tmp, tmp2); \
3585 default: return 1; \
3588 static TCGv
neon_load_scratch(int scratch
)
3590 TCGv tmp
= new_tmp();
3591 tcg_gen_ld_i32(tmp
, cpu_env
, offsetof(CPUARMState
, vfp
.scratch
[scratch
]));
3595 static void neon_store_scratch(int scratch
, TCGv var
)
3597 tcg_gen_st_i32(var
, cpu_env
, offsetof(CPUARMState
, vfp
.scratch
[scratch
]));
3601 static inline TCGv
neon_get_scalar(int size
, int reg
)
3605 tmp
= neon_load_reg(reg
& 7, reg
>> 4);
3607 gen_neon_dup_high16(tmp
);
3609 gen_neon_dup_low16(tmp
);
3612 tmp
= neon_load_reg(reg
& 15, reg
>> 4);
3617 static void gen_neon_unzip_u8(TCGv t0
, TCGv t1
)
3625 tcg_gen_andi_i32(rd
, t0
, 0xff);
3626 tcg_gen_shri_i32(tmp
, t0
, 8);
3627 tcg_gen_andi_i32(tmp
, tmp
, 0xff00);
3628 tcg_gen_or_i32(rd
, rd
, tmp
);
3629 tcg_gen_shli_i32(tmp
, t1
, 16);
3630 tcg_gen_andi_i32(tmp
, tmp
, 0xff0000);
3631 tcg_gen_or_i32(rd
, rd
, tmp
);
3632 tcg_gen_shli_i32(tmp
, t1
, 8);
3633 tcg_gen_andi_i32(tmp
, tmp
, 0xff000000);
3634 tcg_gen_or_i32(rd
, rd
, tmp
);
3636 tcg_gen_shri_i32(rm
, t0
, 8);
3637 tcg_gen_andi_i32(rm
, rm
, 0xff);
3638 tcg_gen_shri_i32(tmp
, t0
, 16);
3639 tcg_gen_andi_i32(tmp
, tmp
, 0xff00);
3640 tcg_gen_or_i32(rm
, rm
, tmp
);
3641 tcg_gen_shli_i32(tmp
, t1
, 8);
3642 tcg_gen_andi_i32(tmp
, tmp
, 0xff0000);
3643 tcg_gen_or_i32(rm
, rm
, tmp
);
3644 tcg_gen_andi_i32(tmp
, t1
, 0xff000000);
3645 tcg_gen_or_i32(t1
, rm
, tmp
);
3646 tcg_gen_mov_i32(t0
, rd
);
3653 static void gen_neon_zip_u8(TCGv t0
, TCGv t1
)
3661 tcg_gen_andi_i32(rd
, t0
, 0xff);
3662 tcg_gen_shli_i32(tmp
, t1
, 8);
3663 tcg_gen_andi_i32(tmp
, tmp
, 0xff00);
3664 tcg_gen_or_i32(rd
, rd
, tmp
);
3665 tcg_gen_shli_i32(tmp
, t0
, 16);
3666 tcg_gen_andi_i32(tmp
, tmp
, 0xff0000);
3667 tcg_gen_or_i32(rd
, rd
, tmp
);
3668 tcg_gen_shli_i32(tmp
, t1
, 24);
3669 tcg_gen_andi_i32(tmp
, tmp
, 0xff000000);
3670 tcg_gen_or_i32(rd
, rd
, tmp
);
3672 tcg_gen_andi_i32(rm
, t1
, 0xff000000);
3673 tcg_gen_shri_i32(tmp
, t0
, 8);
3674 tcg_gen_andi_i32(tmp
, tmp
, 0xff0000);
3675 tcg_gen_or_i32(rm
, rm
, tmp
);
3676 tcg_gen_shri_i32(tmp
, t1
, 8);
3677 tcg_gen_andi_i32(tmp
, tmp
, 0xff00);
3678 tcg_gen_or_i32(rm
, rm
, tmp
);
3679 tcg_gen_shri_i32(tmp
, t0
, 16);
3680 tcg_gen_andi_i32(tmp
, tmp
, 0xff);
3681 tcg_gen_or_i32(t1
, rm
, tmp
);
3682 tcg_gen_mov_i32(t0
, rd
);
3689 static void gen_neon_zip_u16(TCGv t0
, TCGv t1
)
3696 tcg_gen_andi_i32(tmp
, t0
, 0xffff);
3697 tcg_gen_shli_i32(tmp2
, t1
, 16);
3698 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3699 tcg_gen_andi_i32(t1
, t1
, 0xffff0000);
3700 tcg_gen_shri_i32(tmp2
, t0
, 16);
3701 tcg_gen_or_i32(t1
, t1
, tmp2
);
3702 tcg_gen_mov_i32(t0
, tmp
);
3708 static void gen_neon_unzip(int reg
, int q
, int tmp
, int size
)
3713 for (n
= 0; n
< q
+ 1; n
+= 2) {
3714 t0
= neon_load_reg(reg
, n
);
3715 t1
= neon_load_reg(reg
, n
+ 1);
3717 case 0: gen_neon_unzip_u8(t0
, t1
); break;
3718 case 1: gen_neon_zip_u16(t0
, t1
); break; /* zip and unzip are the same. */
3719 case 2: /* no-op */; break;
3722 neon_store_scratch(tmp
+ n
, t0
);
3723 neon_store_scratch(tmp
+ n
+ 1, t1
);
3727 static void gen_neon_trn_u8(TCGv t0
, TCGv t1
)
3734 tcg_gen_shli_i32(rd
, t0
, 8);
3735 tcg_gen_andi_i32(rd
, rd
, 0xff00ff00);
3736 tcg_gen_andi_i32(tmp
, t1
, 0x00ff00ff);
3737 tcg_gen_or_i32(rd
, rd
, tmp
);
3739 tcg_gen_shri_i32(t1
, t1
, 8);
3740 tcg_gen_andi_i32(t1
, t1
, 0x00ff00ff);
3741 tcg_gen_andi_i32(tmp
, t0
, 0xff00ff00);
3742 tcg_gen_or_i32(t1
, t1
, tmp
);
3743 tcg_gen_mov_i32(t0
, rd
);
3749 static void gen_neon_trn_u16(TCGv t0
, TCGv t1
)
3756 tcg_gen_shli_i32(rd
, t0
, 16);
3757 tcg_gen_andi_i32(tmp
, t1
, 0xffff);
3758 tcg_gen_or_i32(rd
, rd
, tmp
);
3759 tcg_gen_shri_i32(t1
, t1
, 16);
3760 tcg_gen_andi_i32(tmp
, t0
, 0xffff0000);
3761 tcg_gen_or_i32(t1
, t1
, tmp
);
3762 tcg_gen_mov_i32(t0
, rd
);
3773 } neon_ls_element_type
[11] = {
3787 /* Translate a NEON load/store element instruction. Return nonzero if the
3788 instruction is invalid. */
3789 static int disas_neon_ls_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
3808 if (!s
->vfp_enabled
)
3810 VFP_DREG_D(rd
, insn
);
3811 rn
= (insn
>> 16) & 0xf;
3813 load
= (insn
& (1 << 21)) != 0;
3815 if ((insn
& (1 << 23)) == 0) {
3816 /* Load store all elements. */
3817 op
= (insn
>> 8) & 0xf;
3818 size
= (insn
>> 6) & 3;
3821 nregs
= neon_ls_element_type
[op
].nregs
;
3822 interleave
= neon_ls_element_type
[op
].interleave
;
3823 spacing
= neon_ls_element_type
[op
].spacing
;
3824 if (size
== 3 && (interleave
| spacing
) != 1)
3826 load_reg_var(s
, addr
, rn
);
3827 stride
= (1 << size
) * interleave
;
3828 for (reg
= 0; reg
< nregs
; reg
++) {
3829 if (interleave
> 2 || (interleave
== 2 && nregs
== 2)) {
3830 load_reg_var(s
, addr
, rn
);
3831 tcg_gen_addi_i32(addr
, addr
, (1 << size
) * reg
);
3832 } else if (interleave
== 2 && nregs
== 4 && reg
== 2) {
3833 load_reg_var(s
, addr
, rn
);
3834 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
3838 tmp64
= gen_ld64(addr
, IS_USER(s
));
3839 neon_store_reg64(tmp64
, rd
);
3840 tcg_temp_free_i64(tmp64
);
3842 tmp64
= tcg_temp_new_i64();
3843 neon_load_reg64(tmp64
, rd
);
3844 gen_st64(tmp64
, addr
, IS_USER(s
));
3846 tcg_gen_addi_i32(addr
, addr
, stride
);
3848 for (pass
= 0; pass
< 2; pass
++) {
3851 tmp
= gen_ld32(addr
, IS_USER(s
));
3852 neon_store_reg(rd
, pass
, tmp
);
3854 tmp
= neon_load_reg(rd
, pass
);
3855 gen_st32(tmp
, addr
, IS_USER(s
));
3857 tcg_gen_addi_i32(addr
, addr
, stride
);
3858 } else if (size
== 1) {
3860 tmp
= gen_ld16u(addr
, IS_USER(s
));
3861 tcg_gen_addi_i32(addr
, addr
, stride
);
3862 tmp2
= gen_ld16u(addr
, IS_USER(s
));
3863 tcg_gen_addi_i32(addr
, addr
, stride
);
3864 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
3865 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
3867 neon_store_reg(rd
, pass
, tmp
);
3869 tmp
= neon_load_reg(rd
, pass
);
3871 tcg_gen_shri_i32(tmp2
, tmp
, 16);
3872 gen_st16(tmp
, addr
, IS_USER(s
));
3873 tcg_gen_addi_i32(addr
, addr
, stride
);
3874 gen_st16(tmp2
, addr
, IS_USER(s
));
3875 tcg_gen_addi_i32(addr
, addr
, stride
);
3877 } else /* size == 0 */ {
3880 for (n
= 0; n
< 4; n
++) {
3881 tmp
= gen_ld8u(addr
, IS_USER(s
));
3882 tcg_gen_addi_i32(addr
, addr
, stride
);
3886 tcg_gen_shli_i32(tmp
, tmp
, n
* 8);
3887 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
3891 neon_store_reg(rd
, pass
, tmp2
);
3893 tmp2
= neon_load_reg(rd
, pass
);
3894 for (n
= 0; n
< 4; n
++) {
3897 tcg_gen_mov_i32(tmp
, tmp2
);
3899 tcg_gen_shri_i32(tmp
, tmp2
, n
* 8);
3901 gen_st8(tmp
, addr
, IS_USER(s
));
3902 tcg_gen_addi_i32(addr
, addr
, stride
);
3913 size
= (insn
>> 10) & 3;
3915 /* Load single element to all lanes. */
3918 size
= (insn
>> 6) & 3;
3919 nregs
= ((insn
>> 8) & 3) + 1;
3920 stride
= (insn
& (1 << 5)) ? 2 : 1;
3921 load_reg_var(s
, addr
, rn
);
3922 for (reg
= 0; reg
< nregs
; reg
++) {
3925 tmp
= gen_ld8u(addr
, IS_USER(s
));
3926 gen_neon_dup_u8(tmp
, 0);
3929 tmp
= gen_ld16u(addr
, IS_USER(s
));
3930 gen_neon_dup_low16(tmp
);
3933 tmp
= gen_ld32(addr
, IS_USER(s
));
3937 default: /* Avoid compiler warnings. */
3940 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
3942 tcg_gen_mov_i32(tmp2
, tmp
);
3943 neon_store_reg(rd
, 0, tmp2
);
3944 neon_store_reg(rd
, 1, tmp
);
3947 stride
= (1 << size
) * nregs
;
3949 /* Single element. */
3950 pass
= (insn
>> 7) & 1;
3953 shift
= ((insn
>> 5) & 3) * 8;
3957 shift
= ((insn
>> 6) & 1) * 16;
3958 stride
= (insn
& (1 << 5)) ? 2 : 1;
3962 stride
= (insn
& (1 << 6)) ? 2 : 1;
3967 nregs
= ((insn
>> 8) & 3) + 1;
3968 load_reg_var(s
, addr
, rn
);
3969 for (reg
= 0; reg
< nregs
; reg
++) {
3973 tmp
= gen_ld8u(addr
, IS_USER(s
));
3976 tmp
= gen_ld16u(addr
, IS_USER(s
));
3979 tmp
= gen_ld32(addr
, IS_USER(s
));
3981 default: /* Avoid compiler warnings. */
3985 tmp2
= neon_load_reg(rd
, pass
);
3986 gen_bfi(tmp
, tmp2
, tmp
, shift
, size
? 0xffff : 0xff);
3989 neon_store_reg(rd
, pass
, tmp
);
3990 } else { /* Store */
3991 tmp
= neon_load_reg(rd
, pass
);
3993 tcg_gen_shri_i32(tmp
, tmp
, shift
);
3996 gen_st8(tmp
, addr
, IS_USER(s
));
3999 gen_st16(tmp
, addr
, IS_USER(s
));
4002 gen_st32(tmp
, addr
, IS_USER(s
));
4007 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
4009 stride
= nregs
* (1 << size
);
4016 base
= load_reg(s
, rn
);
4018 tcg_gen_addi_i32(base
, base
, stride
);
4021 index
= load_reg(s
, rm
);
4022 tcg_gen_add_i32(base
, base
, index
);
4025 store_reg(s
, rn
, base
);
4030 /* Bitwise select. dest = c ? t : f. Clobbers T and F. */
4031 static void gen_neon_bsl(TCGv dest
, TCGv t
, TCGv f
, TCGv c
)
4033 tcg_gen_and_i32(t
, t
, c
);
4034 tcg_gen_andc_i32(f
, f
, c
);
4035 tcg_gen_or_i32(dest
, t
, f
);
4038 static inline void gen_neon_narrow(int size
, TCGv dest
, TCGv_i64 src
)
4041 case 0: gen_helper_neon_narrow_u8(dest
, src
); break;
4042 case 1: gen_helper_neon_narrow_u16(dest
, src
); break;
4043 case 2: tcg_gen_trunc_i64_i32(dest
, src
); break;
4048 static inline void gen_neon_narrow_sats(int size
, TCGv dest
, TCGv_i64 src
)
4051 case 0: gen_helper_neon_narrow_sat_s8(dest
, cpu_env
, src
); break;
4052 case 1: gen_helper_neon_narrow_sat_s16(dest
, cpu_env
, src
); break;
4053 case 2: gen_helper_neon_narrow_sat_s32(dest
, cpu_env
, src
); break;
4058 static inline void gen_neon_narrow_satu(int size
, TCGv dest
, TCGv_i64 src
)
4061 case 0: gen_helper_neon_narrow_sat_u8(dest
, cpu_env
, src
); break;
4062 case 1: gen_helper_neon_narrow_sat_u16(dest
, cpu_env
, src
); break;
4063 case 2: gen_helper_neon_narrow_sat_u32(dest
, cpu_env
, src
); break;
4068 static inline void gen_neon_shift_narrow(int size
, TCGv var
, TCGv shift
,
4074 case 1: gen_helper_neon_rshl_u16(var
, var
, shift
); break;
4075 case 2: gen_helper_neon_rshl_u32(var
, var
, shift
); break;
4080 case 1: gen_helper_neon_rshl_s16(var
, var
, shift
); break;
4081 case 2: gen_helper_neon_rshl_s32(var
, var
, shift
); break;
4088 case 1: gen_helper_neon_rshl_u16(var
, var
, shift
); break;
4089 case 2: gen_helper_neon_rshl_u32(var
, var
, shift
); break;
4094 case 1: gen_helper_neon_shl_s16(var
, var
, shift
); break;
4095 case 2: gen_helper_neon_shl_s32(var
, var
, shift
); break;
4102 static inline void gen_neon_widen(TCGv_i64 dest
, TCGv src
, int size
, int u
)
4106 case 0: gen_helper_neon_widen_u8(dest
, src
); break;
4107 case 1: gen_helper_neon_widen_u16(dest
, src
); break;
4108 case 2: tcg_gen_extu_i32_i64(dest
, src
); break;
4113 case 0: gen_helper_neon_widen_s8(dest
, src
); break;
4114 case 1: gen_helper_neon_widen_s16(dest
, src
); break;
4115 case 2: tcg_gen_ext_i32_i64(dest
, src
); break;
4122 static inline void gen_neon_addl(int size
)
4125 case 0: gen_helper_neon_addl_u16(CPU_V001
); break;
4126 case 1: gen_helper_neon_addl_u32(CPU_V001
); break;
4127 case 2: tcg_gen_add_i64(CPU_V001
); break;
4132 static inline void gen_neon_subl(int size
)
4135 case 0: gen_helper_neon_subl_u16(CPU_V001
); break;
4136 case 1: gen_helper_neon_subl_u32(CPU_V001
); break;
4137 case 2: tcg_gen_sub_i64(CPU_V001
); break;
4142 static inline void gen_neon_negl(TCGv_i64 var
, int size
)
4145 case 0: gen_helper_neon_negl_u16(var
, var
); break;
4146 case 1: gen_helper_neon_negl_u32(var
, var
); break;
4147 case 2: gen_helper_neon_negl_u64(var
, var
); break;
4152 static inline void gen_neon_addl_saturate(TCGv_i64 op0
, TCGv_i64 op1
, int size
)
4155 case 1: gen_helper_neon_addl_saturate_s32(op0
, cpu_env
, op0
, op1
); break;
4156 case 2: gen_helper_neon_addl_saturate_s64(op0
, cpu_env
, op0
, op1
); break;
4161 static inline void gen_neon_mull(TCGv_i64 dest
, TCGv a
, TCGv b
, int size
, int u
)
4165 switch ((size
<< 1) | u
) {
4166 case 0: gen_helper_neon_mull_s8(dest
, a
, b
); break;
4167 case 1: gen_helper_neon_mull_u8(dest
, a
, b
); break;
4168 case 2: gen_helper_neon_mull_s16(dest
, a
, b
); break;
4169 case 3: gen_helper_neon_mull_u16(dest
, a
, b
); break;
4171 tmp
= gen_muls_i64_i32(a
, b
);
4172 tcg_gen_mov_i64(dest
, tmp
);
4175 tmp
= gen_mulu_i64_i32(a
, b
);
4176 tcg_gen_mov_i64(dest
, tmp
);
4181 /* gen_helper_neon_mull_[su]{8|16} do not free their parameters.
4182 Don't forget to clean them now. */
4189 /* Translate a NEON data processing instruction. Return nonzero if the
4190 instruction is invalid.
4191 We process data in a mixture of 32-bit and 64-bit chunks.
4192 Mostly we use 32-bit chunks so we can use normal scalar instructions. */
4194 static int disas_neon_data_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
4207 TCGv tmp
, tmp2
, tmp3
, tmp4
, tmp5
;
4210 if (!s
->vfp_enabled
)
4212 q
= (insn
& (1 << 6)) != 0;
4213 u
= (insn
>> 24) & 1;
4214 VFP_DREG_D(rd
, insn
);
4215 VFP_DREG_N(rn
, insn
);
4216 VFP_DREG_M(rm
, insn
);
4217 size
= (insn
>> 20) & 3;
4218 if ((insn
& (1 << 23)) == 0) {
4219 /* Three register same length. */
4220 op
= ((insn
>> 7) & 0x1e) | ((insn
>> 4) & 1);
4221 if (size
== 3 && (op
== 1 || op
== 5 || op
== 8 || op
== 9
4222 || op
== 10 || op
== 11 || op
== 16)) {
4223 /* 64-bit element instructions. */
4224 for (pass
= 0; pass
< (q
? 2 : 1); pass
++) {
4225 neon_load_reg64(cpu_V0
, rn
+ pass
);
4226 neon_load_reg64(cpu_V1
, rm
+ pass
);
4230 gen_helper_neon_qadd_u64(cpu_V0
, cpu_env
,
4233 gen_helper_neon_qadd_s64(cpu_V0
, cpu_env
,
4239 gen_helper_neon_qsub_u64(cpu_V0
, cpu_env
,
4242 gen_helper_neon_qsub_s64(cpu_V0
, cpu_env
,
4248 gen_helper_neon_shl_u64(cpu_V0
, cpu_V1
, cpu_V0
);
4250 gen_helper_neon_shl_s64(cpu_V0
, cpu_V1
, cpu_V0
);
4255 gen_helper_neon_qshl_u64(cpu_V0
, cpu_env
,
4258 gen_helper_neon_qshl_s64(cpu_V0
, cpu_env
,
4262 case 10: /* VRSHL */
4264 gen_helper_neon_rshl_u64(cpu_V0
, cpu_V1
, cpu_V0
);
4266 gen_helper_neon_rshl_s64(cpu_V0
, cpu_V1
, cpu_V0
);
4269 case 11: /* VQRSHL */
4271 gen_helper_neon_qrshl_u64(cpu_V0
, cpu_env
,
4274 gen_helper_neon_qrshl_s64(cpu_V0
, cpu_env
,
4280 tcg_gen_sub_i64(CPU_V001
);
4282 tcg_gen_add_i64(CPU_V001
);
4288 neon_store_reg64(cpu_V0
, rd
+ pass
);
4295 case 10: /* VRSHL */
4296 case 11: /* VQRSHL */
4299 /* Shift instruction operands are reversed. */
4306 case 20: /* VPMAX */
4307 case 21: /* VPMIN */
4308 case 23: /* VPADD */
4311 case 26: /* VPADD (float) */
4312 pairwise
= (u
&& size
< 2);
4314 case 30: /* VPMIN/VPMAX (float) */
4322 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
4331 tmp
= neon_load_reg(rn
, n
);
4332 tmp2
= neon_load_reg(rn
, n
+ 1);
4334 tmp
= neon_load_reg(rm
, n
);
4335 tmp2
= neon_load_reg(rm
, n
+ 1);
4339 tmp
= neon_load_reg(rn
, pass
);
4340 tmp2
= neon_load_reg(rm
, pass
);
4344 GEN_NEON_INTEGER_OP(hadd
);
4347 GEN_NEON_INTEGER_OP_ENV(qadd
);
4349 case 2: /* VRHADD */
4350 GEN_NEON_INTEGER_OP(rhadd
);
4352 case 3: /* Logic ops. */
4353 switch ((u
<< 2) | size
) {
4355 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
4358 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
4361 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
4364 tcg_gen_orc_i32(tmp
, tmp
, tmp2
);
4367 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
4370 tmp3
= neon_load_reg(rd
, pass
);
4371 gen_neon_bsl(tmp
, tmp
, tmp2
, tmp3
);
4375 tmp3
= neon_load_reg(rd
, pass
);
4376 gen_neon_bsl(tmp
, tmp
, tmp3
, tmp2
);
4380 tmp3
= neon_load_reg(rd
, pass
);
4381 gen_neon_bsl(tmp
, tmp3
, tmp
, tmp2
);
4387 GEN_NEON_INTEGER_OP(hsub
);
4390 GEN_NEON_INTEGER_OP_ENV(qsub
);
4393 GEN_NEON_INTEGER_OP(cgt
);
4396 GEN_NEON_INTEGER_OP(cge
);
4399 GEN_NEON_INTEGER_OP(shl
);
4402 GEN_NEON_INTEGER_OP_ENV(qshl
);
4404 case 10: /* VRSHL */
4405 GEN_NEON_INTEGER_OP(rshl
);
4407 case 11: /* VQRSHL */
4408 GEN_NEON_INTEGER_OP_ENV(qrshl
);
4411 GEN_NEON_INTEGER_OP(max
);
4414 GEN_NEON_INTEGER_OP(min
);
4417 GEN_NEON_INTEGER_OP(abd
);
4420 GEN_NEON_INTEGER_OP(abd
);
4422 tmp2
= neon_load_reg(rd
, pass
);
4423 gen_neon_add(size
, tmp
, tmp2
);
4426 if (!u
) { /* VADD */
4427 if (gen_neon_add(size
, tmp
, tmp2
))
4431 case 0: gen_helper_neon_sub_u8(tmp
, tmp
, tmp2
); break;
4432 case 1: gen_helper_neon_sub_u16(tmp
, tmp
, tmp2
); break;
4433 case 2: tcg_gen_sub_i32(tmp
, tmp
, tmp2
); break;
4439 if (!u
) { /* VTST */
4441 case 0: gen_helper_neon_tst_u8(tmp
, tmp
, tmp2
); break;
4442 case 1: gen_helper_neon_tst_u16(tmp
, tmp
, tmp2
); break;
4443 case 2: gen_helper_neon_tst_u32(tmp
, tmp
, tmp2
); break;
4448 case 0: gen_helper_neon_ceq_u8(tmp
, tmp
, tmp2
); break;
4449 case 1: gen_helper_neon_ceq_u16(tmp
, tmp
, tmp2
); break;
4450 case 2: gen_helper_neon_ceq_u32(tmp
, tmp
, tmp2
); break;
4455 case 18: /* Multiply. */
4457 case 0: gen_helper_neon_mul_u8(tmp
, tmp
, tmp2
); break;
4458 case 1: gen_helper_neon_mul_u16(tmp
, tmp
, tmp2
); break;
4459 case 2: tcg_gen_mul_i32(tmp
, tmp
, tmp2
); break;
4463 tmp2
= neon_load_reg(rd
, pass
);
4465 gen_neon_rsb(size
, tmp
, tmp2
);
4467 gen_neon_add(size
, tmp
, tmp2
);
4471 if (u
) { /* polynomial */
4472 gen_helper_neon_mul_p8(tmp
, tmp
, tmp2
);
4473 } else { /* Integer */
4475 case 0: gen_helper_neon_mul_u8(tmp
, tmp
, tmp2
); break;
4476 case 1: gen_helper_neon_mul_u16(tmp
, tmp
, tmp2
); break;
4477 case 2: tcg_gen_mul_i32(tmp
, tmp
, tmp2
); break;
4482 case 20: /* VPMAX */
4483 GEN_NEON_INTEGER_OP(pmax
);
4485 case 21: /* VPMIN */
4486 GEN_NEON_INTEGER_OP(pmin
);
4488 case 22: /* Hultiply high. */
4489 if (!u
) { /* VQDMULH */
4491 case 1: gen_helper_neon_qdmulh_s16(tmp
, cpu_env
, tmp
, tmp2
); break;
4492 case 2: gen_helper_neon_qdmulh_s32(tmp
, cpu_env
, tmp
, tmp2
); break;
4495 } else { /* VQRDHMUL */
4497 case 1: gen_helper_neon_qrdmulh_s16(tmp
, cpu_env
, tmp
, tmp2
); break;
4498 case 2: gen_helper_neon_qrdmulh_s32(tmp
, cpu_env
, tmp
, tmp2
); break;
4503 case 23: /* VPADD */
4507 case 0: gen_helper_neon_padd_u8(tmp
, tmp
, tmp2
); break;
4508 case 1: gen_helper_neon_padd_u16(tmp
, tmp
, tmp2
); break;
4509 case 2: tcg_gen_add_i32(tmp
, tmp
, tmp2
); break;
4513 case 26: /* Floating point arithnetic. */
4514 switch ((u
<< 2) | size
) {
4516 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
4519 gen_helper_neon_sub_f32(tmp
, tmp
, tmp2
);
4522 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
4525 gen_helper_neon_abd_f32(tmp
, tmp
, tmp2
);
4531 case 27: /* Float multiply. */
4532 gen_helper_neon_mul_f32(tmp
, tmp
, tmp2
);
4535 tmp2
= neon_load_reg(rd
, pass
);
4537 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
4539 gen_helper_neon_sub_f32(tmp
, tmp2
, tmp
);
4543 case 28: /* Float compare. */
4545 gen_helper_neon_ceq_f32(tmp
, tmp
, tmp2
);
4548 gen_helper_neon_cge_f32(tmp
, tmp
, tmp2
);
4550 gen_helper_neon_cgt_f32(tmp
, tmp
, tmp2
);
4553 case 29: /* Float compare absolute. */
4557 gen_helper_neon_acge_f32(tmp
, tmp
, tmp2
);
4559 gen_helper_neon_acgt_f32(tmp
, tmp
, tmp2
);
4561 case 30: /* Float min/max. */
4563 gen_helper_neon_max_f32(tmp
, tmp
, tmp2
);
4565 gen_helper_neon_min_f32(tmp
, tmp
, tmp2
);
4569 gen_helper_recps_f32(tmp
, tmp
, tmp2
, cpu_env
);
4571 gen_helper_rsqrts_f32(tmp
, tmp
, tmp2
, cpu_env
);
4578 /* Save the result. For elementwise operations we can put it
4579 straight into the destination register. For pairwise operations
4580 we have to be careful to avoid clobbering the source operands. */
4581 if (pairwise
&& rd
== rm
) {
4582 neon_store_scratch(pass
, tmp
);
4584 neon_store_reg(rd
, pass
, tmp
);
4588 if (pairwise
&& rd
== rm
) {
4589 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
4590 tmp
= neon_load_scratch(pass
);
4591 neon_store_reg(rd
, pass
, tmp
);
4594 /* End of 3 register same size operations. */
4595 } else if (insn
& (1 << 4)) {
4596 if ((insn
& 0x00380080) != 0) {
4597 /* Two registers and shift. */
4598 op
= (insn
>> 8) & 0xf;
4599 if (insn
& (1 << 7)) {
4604 while ((insn
& (1 << (size
+ 19))) == 0)
4607 shift
= (insn
>> 16) & ((1 << (3 + size
)) - 1);
4608 /* To avoid excessive dumplication of ops we implement shift
4609 by immediate using the variable shift operations. */
4611 /* Shift by immediate:
4612 VSHR, VSRA, VRSHR, VRSRA, VSRI, VSHL, VQSHL, VQSHLU. */
4613 /* Right shifts are encoded as N - shift, where N is the
4614 element size in bits. */
4616 shift
= shift
- (1 << (size
+ 3));
4624 imm
= (uint8_t) shift
;
4629 imm
= (uint16_t) shift
;
4640 for (pass
= 0; pass
< count
; pass
++) {
4642 neon_load_reg64(cpu_V0
, rm
+ pass
);
4643 tcg_gen_movi_i64(cpu_V1
, imm
);
4648 gen_helper_neon_shl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4650 gen_helper_neon_shl_s64(cpu_V0
, cpu_V0
, cpu_V1
);
4655 gen_helper_neon_rshl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4657 gen_helper_neon_rshl_s64(cpu_V0
, cpu_V0
, cpu_V1
);
4662 gen_helper_neon_shl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4664 case 5: /* VSHL, VSLI */
4665 gen_helper_neon_shl_u64(cpu_V0
, cpu_V0
, cpu_V1
);
4667 case 6: /* VQSHLU */
4669 gen_helper_neon_qshlu_s64(cpu_V0
, cpu_env
,
4677 gen_helper_neon_qshl_u64(cpu_V0
, cpu_env
,
4680 gen_helper_neon_qshl_s64(cpu_V0
, cpu_env
,
4685 if (op
== 1 || op
== 3) {
4687 neon_load_reg64(cpu_V1
, rd
+ pass
);
4688 tcg_gen_add_i64(cpu_V0
, cpu_V0
, cpu_V1
);
4689 } else if (op
== 4 || (op
== 5 && u
)) {
4691 cpu_abort(env
, "VS[LR]I.64 not implemented");
4693 neon_store_reg64(cpu_V0
, rd
+ pass
);
4694 } else { /* size < 3 */
4695 /* Operands in T0 and T1. */
4696 tmp
= neon_load_reg(rm
, pass
);
4698 tcg_gen_movi_i32(tmp2
, imm
);
4702 GEN_NEON_INTEGER_OP(shl
);
4706 GEN_NEON_INTEGER_OP(rshl
);
4711 GEN_NEON_INTEGER_OP(shl
);
4713 case 5: /* VSHL, VSLI */
4715 case 0: gen_helper_neon_shl_u8(tmp
, tmp
, tmp2
); break;
4716 case 1: gen_helper_neon_shl_u16(tmp
, tmp
, tmp2
); break;
4717 case 2: gen_helper_neon_shl_u32(tmp
, tmp
, tmp2
); break;
4721 case 6: /* VQSHLU */
4727 gen_helper_neon_qshlu_s8(tmp
, cpu_env
,
4731 gen_helper_neon_qshlu_s16(tmp
, cpu_env
,
4735 gen_helper_neon_qshlu_s32(tmp
, cpu_env
,
4743 GEN_NEON_INTEGER_OP_ENV(qshl
);
4748 if (op
== 1 || op
== 3) {
4750 tmp2
= neon_load_reg(rd
, pass
);
4751 gen_neon_add(size
, tmp
, tmp2
);
4753 } else if (op
== 4 || (op
== 5 && u
)) {
4758 mask
= 0xff >> -shift
;
4760 mask
= (uint8_t)(0xff << shift
);
4766 mask
= 0xffff >> -shift
;
4768 mask
= (uint16_t)(0xffff << shift
);
4772 if (shift
< -31 || shift
> 31) {
4776 mask
= 0xffffffffu
>> -shift
;
4778 mask
= 0xffffffffu
<< shift
;
4784 tmp2
= neon_load_reg(rd
, pass
);
4785 tcg_gen_andi_i32(tmp
, tmp
, mask
);
4786 tcg_gen_andi_i32(tmp2
, tmp2
, ~mask
);
4787 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
4790 neon_store_reg(rd
, pass
, tmp
);
4793 } else if (op
< 10) {
4794 /* Shift by immediate and narrow:
4795 VSHRN, VRSHRN, VQSHRN, VQRSHRN. */
4796 shift
= shift
- (1 << (size
+ 3));
4800 imm
= (uint16_t)shift
;
4802 tmp2
= tcg_const_i32(imm
);
4803 TCGV_UNUSED_I64(tmp64
);
4806 imm
= (uint32_t)shift
;
4807 tmp2
= tcg_const_i32(imm
);
4808 TCGV_UNUSED_I64(tmp64
);
4811 tmp64
= tcg_const_i64(shift
);
4818 for (pass
= 0; pass
< 2; pass
++) {
4820 neon_load_reg64(cpu_V0
, rm
+ pass
);
4823 gen_helper_neon_rshl_u64(cpu_V0
, cpu_V0
, tmp64
);
4825 gen_helper_neon_rshl_s64(cpu_V0
, cpu_V0
, tmp64
);
4828 gen_helper_neon_shl_u64(cpu_V0
, cpu_V0
, tmp64
);
4830 gen_helper_neon_shl_s64(cpu_V0
, cpu_V0
, tmp64
);
4833 tmp
= neon_load_reg(rm
+ pass
, 0);
4834 gen_neon_shift_narrow(size
, tmp
, tmp2
, q
, u
);
4835 tmp3
= neon_load_reg(rm
+ pass
, 1);
4836 gen_neon_shift_narrow(size
, tmp3
, tmp2
, q
, u
);
4837 tcg_gen_concat_i32_i64(cpu_V0
, tmp
, tmp3
);
4842 if (op
== 8 && !u
) {
4843 gen_neon_narrow(size
- 1, tmp
, cpu_V0
);
4846 gen_neon_narrow_sats(size
- 1, tmp
, cpu_V0
);
4848 gen_neon_narrow_satu(size
- 1, tmp
, cpu_V0
);
4850 neon_store_reg(rd
, pass
, tmp
);
4853 tcg_temp_free_i64(tmp64
);
4855 tcg_temp_free_i32(tmp2
);
4857 } else if (op
== 10) {
4861 tmp
= neon_load_reg(rm
, 0);
4862 tmp2
= neon_load_reg(rm
, 1);
4863 for (pass
= 0; pass
< 2; pass
++) {
4867 gen_neon_widen(cpu_V0
, tmp
, size
, u
);
4870 /* The shift is less than the width of the source
4871 type, so we can just shift the whole register. */
4872 tcg_gen_shli_i64(cpu_V0
, cpu_V0
, shift
);
4873 if (size
< 2 || !u
) {
4876 imm
= (0xffu
>> (8 - shift
));
4879 imm
= 0xffff >> (16 - shift
);
4881 imm64
= imm
| (((uint64_t)imm
) << 32);
4882 tcg_gen_andi_i64(cpu_V0
, cpu_V0
, imm64
);
4885 neon_store_reg64(cpu_V0
, rd
+ pass
);
4887 } else if (op
>= 14) {
4888 /* VCVT fixed-point. */
4889 /* We have already masked out the must-be-1 top bit of imm6,
4890 * hence this 32-shift where the ARM ARM has 64-imm6.
4893 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
4894 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, pass
));
4897 gen_vfp_ulto(0, shift
);
4899 gen_vfp_slto(0, shift
);
4902 gen_vfp_toul(0, shift
);
4904 gen_vfp_tosl(0, shift
);
4906 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, pass
));
4911 } else { /* (insn & 0x00380080) == 0 */
4914 op
= (insn
>> 8) & 0xf;
4915 /* One register and immediate. */
4916 imm
= (u
<< 7) | ((insn
>> 12) & 0x70) | (insn
& 0xf);
4917 invert
= (insn
& (1 << 5)) != 0;
4935 imm
= (imm
<< 8) | (imm
<< 24);
4938 imm
= (imm
<< 8) | 0xff;
4941 imm
= (imm
<< 16) | 0xffff;
4944 imm
|= (imm
<< 8) | (imm
<< 16) | (imm
<< 24);
4949 imm
= ((imm
& 0x80) << 24) | ((imm
& 0x3f) << 19)
4950 | ((imm
& 0x40) ? (0x1f << 25) : (1 << 30));
4956 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
4957 if (op
& 1 && op
< 12) {
4958 tmp
= neon_load_reg(rd
, pass
);
4960 /* The immediate value has already been inverted, so
4962 tcg_gen_andi_i32(tmp
, tmp
, imm
);
4964 tcg_gen_ori_i32(tmp
, tmp
, imm
);
4969 if (op
== 14 && invert
) {
4972 for (n
= 0; n
< 4; n
++) {
4973 if (imm
& (1 << (n
+ (pass
& 1) * 4)))
4974 val
|= 0xff << (n
* 8);
4976 tcg_gen_movi_i32(tmp
, val
);
4978 tcg_gen_movi_i32(tmp
, imm
);
4981 neon_store_reg(rd
, pass
, tmp
);
4984 } else { /* (insn & 0x00800010 == 0x00800000) */
4986 op
= (insn
>> 8) & 0xf;
4987 if ((insn
& (1 << 6)) == 0) {
4988 /* Three registers of different lengths. */
4992 /* prewiden, src1_wide, src2_wide */
4993 static const int neon_3reg_wide
[16][3] = {
4994 {1, 0, 0}, /* VADDL */
4995 {1, 1, 0}, /* VADDW */
4996 {1, 0, 0}, /* VSUBL */
4997 {1, 1, 0}, /* VSUBW */
4998 {0, 1, 1}, /* VADDHN */
4999 {0, 0, 0}, /* VABAL */
5000 {0, 1, 1}, /* VSUBHN */
5001 {0, 0, 0}, /* VABDL */
5002 {0, 0, 0}, /* VMLAL */
5003 {0, 0, 0}, /* VQDMLAL */
5004 {0, 0, 0}, /* VMLSL */
5005 {0, 0, 0}, /* VQDMLSL */
5006 {0, 0, 0}, /* Integer VMULL */
5007 {0, 0, 0}, /* VQDMULL */
5008 {0, 0, 0} /* Polynomial VMULL */
5011 prewiden
= neon_3reg_wide
[op
][0];
5012 src1_wide
= neon_3reg_wide
[op
][1];
5013 src2_wide
= neon_3reg_wide
[op
][2];
5015 if (size
== 0 && (op
== 9 || op
== 11 || op
== 13))
5018 /* Avoid overlapping operands. Wide source operands are
5019 always aligned so will never overlap with wide
5020 destinations in problematic ways. */
5021 if (rd
== rm
&& !src2_wide
) {
5022 tmp
= neon_load_reg(rm
, 1);
5023 neon_store_scratch(2, tmp
);
5024 } else if (rd
== rn
&& !src1_wide
) {
5025 tmp
= neon_load_reg(rn
, 1);
5026 neon_store_scratch(2, tmp
);
5029 for (pass
= 0; pass
< 2; pass
++) {
5031 neon_load_reg64(cpu_V0
, rn
+ pass
);
5034 if (pass
== 1 && rd
== rn
) {
5035 tmp
= neon_load_scratch(2);
5037 tmp
= neon_load_reg(rn
, pass
);
5040 gen_neon_widen(cpu_V0
, tmp
, size
, u
);
5044 neon_load_reg64(cpu_V1
, rm
+ pass
);
5047 if (pass
== 1 && rd
== rm
) {
5048 tmp2
= neon_load_scratch(2);
5050 tmp2
= neon_load_reg(rm
, pass
);
5053 gen_neon_widen(cpu_V1
, tmp2
, size
, u
);
5057 case 0: case 1: case 4: /* VADDL, VADDW, VADDHN, VRADDHN */
5058 gen_neon_addl(size
);
5060 case 2: case 3: case 6: /* VSUBL, VSUBW, VSUBHN, VRSUBHN */
5061 gen_neon_subl(size
);
5063 case 5: case 7: /* VABAL, VABDL */
5064 switch ((size
<< 1) | u
) {
5066 gen_helper_neon_abdl_s16(cpu_V0
, tmp
, tmp2
);
5069 gen_helper_neon_abdl_u16(cpu_V0
, tmp
, tmp2
);
5072 gen_helper_neon_abdl_s32(cpu_V0
, tmp
, tmp2
);
5075 gen_helper_neon_abdl_u32(cpu_V0
, tmp
, tmp2
);
5078 gen_helper_neon_abdl_s64(cpu_V0
, tmp
, tmp2
);
5081 gen_helper_neon_abdl_u64(cpu_V0
, tmp
, tmp2
);
5088 case 8: case 9: case 10: case 11: case 12: case 13:
5089 /* VMLAL, VQDMLAL, VMLSL, VQDMLSL, VMULL, VQDMULL */
5090 gen_neon_mull(cpu_V0
, tmp
, tmp2
, size
, u
);
5092 case 14: /* Polynomial VMULL */
5093 cpu_abort(env
, "Polynomial VMULL not implemented");
5095 default: /* 15 is RESERVED. */
5098 if (op
== 5 || op
== 13 || (op
>= 8 && op
<= 11)) {
5100 if (op
== 10 || op
== 11) {
5101 gen_neon_negl(cpu_V0
, size
);
5105 neon_load_reg64(cpu_V1
, rd
+ pass
);
5109 case 5: case 8: case 10: /* VABAL, VMLAL, VMLSL */
5110 gen_neon_addl(size
);
5112 case 9: case 11: /* VQDMLAL, VQDMLSL */
5113 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5114 gen_neon_addl_saturate(cpu_V0
, cpu_V1
, size
);
5117 case 13: /* VQDMULL */
5118 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5123 neon_store_reg64(cpu_V0
, rd
+ pass
);
5124 } else if (op
== 4 || op
== 6) {
5125 /* Narrowing operation. */
5130 gen_helper_neon_narrow_high_u8(tmp
, cpu_V0
);
5133 gen_helper_neon_narrow_high_u16(tmp
, cpu_V0
);
5136 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
5137 tcg_gen_trunc_i64_i32(tmp
, cpu_V0
);
5144 gen_helper_neon_narrow_round_high_u8(tmp
, cpu_V0
);
5147 gen_helper_neon_narrow_round_high_u16(tmp
, cpu_V0
);
5150 tcg_gen_addi_i64(cpu_V0
, cpu_V0
, 1u << 31);
5151 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, 32);
5152 tcg_gen_trunc_i64_i32(tmp
, cpu_V0
);
5160 neon_store_reg(rd
, 0, tmp3
);
5161 neon_store_reg(rd
, 1, tmp
);
5164 /* Write back the result. */
5165 neon_store_reg64(cpu_V0
, rd
+ pass
);
5169 /* Two registers and a scalar. */
5171 case 0: /* Integer VMLA scalar */
5172 case 1: /* Float VMLA scalar */
5173 case 4: /* Integer VMLS scalar */
5174 case 5: /* Floating point VMLS scalar */
5175 case 8: /* Integer VMUL scalar */
5176 case 9: /* Floating point VMUL scalar */
5177 case 12: /* VQDMULH scalar */
5178 case 13: /* VQRDMULH scalar */
5179 tmp
= neon_get_scalar(size
, rm
);
5180 neon_store_scratch(0, tmp
);
5181 for (pass
= 0; pass
< (u
? 4 : 2); pass
++) {
5182 tmp
= neon_load_scratch(0);
5183 tmp2
= neon_load_reg(rn
, pass
);
5186 gen_helper_neon_qdmulh_s16(tmp
, cpu_env
, tmp
, tmp2
);
5188 gen_helper_neon_qdmulh_s32(tmp
, cpu_env
, tmp
, tmp2
);
5190 } else if (op
== 13) {
5192 gen_helper_neon_qrdmulh_s16(tmp
, cpu_env
, tmp
, tmp2
);
5194 gen_helper_neon_qrdmulh_s32(tmp
, cpu_env
, tmp
, tmp2
);
5196 } else if (op
& 1) {
5197 gen_helper_neon_mul_f32(tmp
, tmp
, tmp2
);
5200 case 0: gen_helper_neon_mul_u8(tmp
, tmp
, tmp2
); break;
5201 case 1: gen_helper_neon_mul_u16(tmp
, tmp
, tmp2
); break;
5202 case 2: tcg_gen_mul_i32(tmp
, tmp
, tmp2
); break;
5209 tmp2
= neon_load_reg(rd
, pass
);
5212 gen_neon_add(size
, tmp
, tmp2
);
5215 gen_helper_neon_add_f32(tmp
, tmp
, tmp2
);
5218 gen_neon_rsb(size
, tmp
, tmp2
);
5221 gen_helper_neon_sub_f32(tmp
, tmp2
, tmp
);
5228 neon_store_reg(rd
, pass
, tmp
);
5231 case 2: /* VMLAL sclar */
5232 case 3: /* VQDMLAL scalar */
5233 case 6: /* VMLSL scalar */
5234 case 7: /* VQDMLSL scalar */
5235 case 10: /* VMULL scalar */
5236 case 11: /* VQDMULL scalar */
5237 if (size
== 0 && (op
== 3 || op
== 7 || op
== 11))
5240 tmp2
= neon_get_scalar(size
, rm
);
5241 /* We need a copy of tmp2 because gen_neon_mull
5242 * deletes it during pass 0. */
5244 tcg_gen_mov_i32(tmp4
, tmp2
);
5245 tmp3
= neon_load_reg(rn
, 1);
5247 for (pass
= 0; pass
< 2; pass
++) {
5249 tmp
= neon_load_reg(rn
, 0);
5254 gen_neon_mull(cpu_V0
, tmp
, tmp2
, size
, u
);
5255 if (op
== 6 || op
== 7) {
5256 gen_neon_negl(cpu_V0
, size
);
5259 neon_load_reg64(cpu_V1
, rd
+ pass
);
5263 gen_neon_addl(size
);
5266 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5267 gen_neon_addl_saturate(cpu_V0
, cpu_V1
, size
);
5273 gen_neon_addl_saturate(cpu_V0
, cpu_V0
, size
);
5278 neon_store_reg64(cpu_V0
, rd
+ pass
);
5283 default: /* 14 and 15 are RESERVED */
5287 } else { /* size == 3 */
5290 imm
= (insn
>> 8) & 0xf;
5296 neon_load_reg64(cpu_V0
, rn
);
5298 neon_load_reg64(cpu_V1
, rn
+ 1);
5300 } else if (imm
== 8) {
5301 neon_load_reg64(cpu_V0
, rn
+ 1);
5303 neon_load_reg64(cpu_V1
, rm
);
5306 tmp64
= tcg_temp_new_i64();
5308 neon_load_reg64(cpu_V0
, rn
);
5309 neon_load_reg64(tmp64
, rn
+ 1);
5311 neon_load_reg64(cpu_V0
, rn
+ 1);
5312 neon_load_reg64(tmp64
, rm
);
5314 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, (imm
& 7) * 8);
5315 tcg_gen_shli_i64(cpu_V1
, tmp64
, 64 - ((imm
& 7) * 8));
5316 tcg_gen_or_i64(cpu_V0
, cpu_V0
, cpu_V1
);
5318 neon_load_reg64(cpu_V1
, rm
);
5320 neon_load_reg64(cpu_V1
, rm
+ 1);
5323 tcg_gen_shli_i64(cpu_V1
, cpu_V1
, 64 - (imm
* 8));
5324 tcg_gen_shri_i64(tmp64
, tmp64
, imm
* 8);
5325 tcg_gen_or_i64(cpu_V1
, cpu_V1
, tmp64
);
5326 tcg_temp_free_i64(tmp64
);
5329 neon_load_reg64(cpu_V0
, rn
);
5330 tcg_gen_shri_i64(cpu_V0
, cpu_V0
, imm
* 8);
5331 neon_load_reg64(cpu_V1
, rm
);
5332 tcg_gen_shli_i64(cpu_V1
, cpu_V1
, 64 - (imm
* 8));
5333 tcg_gen_or_i64(cpu_V0
, cpu_V0
, cpu_V1
);
5335 neon_store_reg64(cpu_V0
, rd
);
5337 neon_store_reg64(cpu_V1
, rd
+ 1);
5339 } else if ((insn
& (1 << 11)) == 0) {
5340 /* Two register misc. */
5341 op
= ((insn
>> 12) & 0x30) | ((insn
>> 7) & 0xf);
5342 size
= (insn
>> 18) & 3;
5344 case 0: /* VREV64 */
5347 for (pass
= 0; pass
< (q
? 2 : 1); pass
++) {
5348 tmp
= neon_load_reg(rm
, pass
* 2);
5349 tmp2
= neon_load_reg(rm
, pass
* 2 + 1);
5351 case 0: tcg_gen_bswap32_i32(tmp
, tmp
); break;
5352 case 1: gen_swap_half(tmp
); break;
5353 case 2: /* no-op */ break;
5356 neon_store_reg(rd
, pass
* 2 + 1, tmp
);
5358 neon_store_reg(rd
, pass
* 2, tmp2
);
5361 case 0: tcg_gen_bswap32_i32(tmp2
, tmp2
); break;
5362 case 1: gen_swap_half(tmp2
); break;
5365 neon_store_reg(rd
, pass
* 2, tmp2
);
5369 case 4: case 5: /* VPADDL */
5370 case 12: case 13: /* VPADAL */
5373 for (pass
= 0; pass
< q
+ 1; pass
++) {
5374 tmp
= neon_load_reg(rm
, pass
* 2);
5375 gen_neon_widen(cpu_V0
, tmp
, size
, op
& 1);
5376 tmp
= neon_load_reg(rm
, pass
* 2 + 1);
5377 gen_neon_widen(cpu_V1
, tmp
, size
, op
& 1);
5379 case 0: gen_helper_neon_paddl_u16(CPU_V001
); break;
5380 case 1: gen_helper_neon_paddl_u32(CPU_V001
); break;
5381 case 2: tcg_gen_add_i64(CPU_V001
); break;
5386 neon_load_reg64(cpu_V1
, rd
+ pass
);
5387 gen_neon_addl(size
);
5389 neon_store_reg64(cpu_V0
, rd
+ pass
);
5394 for (n
= 0; n
< (q
? 4 : 2); n
+= 2) {
5395 tmp
= neon_load_reg(rm
, n
);
5396 tmp2
= neon_load_reg(rd
, n
+ 1);
5397 neon_store_reg(rm
, n
, tmp2
);
5398 neon_store_reg(rd
, n
+ 1, tmp
);
5406 Rd A3 A2 A1 A0 B2 B0 A2 A0
5407 Rm B3 B2 B1 B0 B3 B1 A3 A1
5411 gen_neon_unzip(rd
, q
, 0, size
);
5412 gen_neon_unzip(rm
, q
, 4, size
);
5414 static int unzip_order_q
[8] =
5415 {0, 2, 4, 6, 1, 3, 5, 7};
5416 for (n
= 0; n
< 8; n
++) {
5417 int reg
= (n
< 4) ? rd
: rm
;
5418 tmp
= neon_load_scratch(unzip_order_q
[n
]);
5419 neon_store_reg(reg
, n
% 4, tmp
);
5422 static int unzip_order
[4] =
5424 for (n
= 0; n
< 4; n
++) {
5425 int reg
= (n
< 2) ? rd
: rm
;
5426 tmp
= neon_load_scratch(unzip_order
[n
]);
5427 neon_store_reg(reg
, n
% 2, tmp
);
5433 Rd A3 A2 A1 A0 B1 A1 B0 A0
5434 Rm B3 B2 B1 B0 B3 A3 B2 A2
5438 count
= (q
? 4 : 2);
5439 for (n
= 0; n
< count
; n
++) {
5440 tmp
= neon_load_reg(rd
, n
);
5441 tmp2
= neon_load_reg(rd
, n
);
5443 case 0: gen_neon_zip_u8(tmp
, tmp2
); break;
5444 case 1: gen_neon_zip_u16(tmp
, tmp2
); break;
5445 case 2: /* no-op */; break;
5448 neon_store_scratch(n
* 2, tmp
);
5449 neon_store_scratch(n
* 2 + 1, tmp2
);
5451 for (n
= 0; n
< count
* 2; n
++) {
5452 int reg
= (n
< count
) ? rd
: rm
;
5453 tmp
= neon_load_scratch(n
);
5454 neon_store_reg(reg
, n
% count
, tmp
);
5457 case 36: case 37: /* VMOVN, VQMOVUN, VQMOVN */
5461 for (pass
= 0; pass
< 2; pass
++) {
5462 neon_load_reg64(cpu_V0
, rm
+ pass
);
5464 if (op
== 36 && q
== 0) {
5465 gen_neon_narrow(size
, tmp
, cpu_V0
);
5467 gen_neon_narrow_satu(size
, tmp
, cpu_V0
);
5469 gen_neon_narrow_sats(size
, tmp
, cpu_V0
);
5474 neon_store_reg(rd
, 0, tmp2
);
5475 neon_store_reg(rd
, 1, tmp
);
5479 case 38: /* VSHLL */
5482 tmp
= neon_load_reg(rm
, 0);
5483 tmp2
= neon_load_reg(rm
, 1);
5484 for (pass
= 0; pass
< 2; pass
++) {
5487 gen_neon_widen(cpu_V0
, tmp
, size
, 1);
5488 tcg_gen_shli_i64(cpu_V0
, cpu_V0
, 8 << size
);
5489 neon_store_reg64(cpu_V0
, rd
+ pass
);
5492 case 44: /* VCVT.F16.F32 */
5493 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
5497 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 0));
5498 gen_helper_vfp_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
5499 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 1));
5500 gen_helper_vfp_fcvt_f32_to_f16(tmp2
, cpu_F0s
, cpu_env
);
5501 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
5502 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
5503 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 2));
5504 gen_helper_vfp_fcvt_f32_to_f16(tmp
, cpu_F0s
, cpu_env
);
5505 tcg_gen_ld_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rm
, 3));
5506 neon_store_reg(rd
, 0, tmp2
);
5508 gen_helper_vfp_fcvt_f32_to_f16(tmp2
, cpu_F0s
, cpu_env
);
5509 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
5510 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
5511 neon_store_reg(rd
, 1, tmp2
);
5514 case 46: /* VCVT.F32.F16 */
5515 if (!arm_feature(env
, ARM_FEATURE_VFP_FP16
))
5518 tmp
= neon_load_reg(rm
, 0);
5519 tmp2
= neon_load_reg(rm
, 1);
5520 tcg_gen_ext16u_i32(tmp3
, tmp
);
5521 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5522 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 0));
5523 tcg_gen_shri_i32(tmp3
, tmp
, 16);
5524 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5525 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 1));
5527 tcg_gen_ext16u_i32(tmp3
, tmp2
);
5528 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5529 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 2));
5530 tcg_gen_shri_i32(tmp3
, tmp2
, 16);
5531 gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s
, tmp3
, cpu_env
);
5532 tcg_gen_st_f32(cpu_F0s
, cpu_env
, neon_reg_offset(rd
, 3));
5538 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
5539 if (op
== 30 || op
== 31 || op
>= 58) {
5540 tcg_gen_ld_f32(cpu_F0s
, cpu_env
,
5541 neon_reg_offset(rm
, pass
));
5544 tmp
= neon_load_reg(rm
, pass
);
5547 case 1: /* VREV32 */
5549 case 0: tcg_gen_bswap32_i32(tmp
, tmp
); break;
5550 case 1: gen_swap_half(tmp
); break;
5554 case 2: /* VREV16 */
5561 case 0: gen_helper_neon_cls_s8(tmp
, tmp
); break;
5562 case 1: gen_helper_neon_cls_s16(tmp
, tmp
); break;
5563 case 2: gen_helper_neon_cls_s32(tmp
, tmp
); break;
5569 case 0: gen_helper_neon_clz_u8(tmp
, tmp
); break;
5570 case 1: gen_helper_neon_clz_u16(tmp
, tmp
); break;
5571 case 2: gen_helper_clz(tmp
, tmp
); break;
5578 gen_helper_neon_cnt_u8(tmp
, tmp
);
5583 tcg_gen_not_i32(tmp
, tmp
);
5585 case 14: /* VQABS */
5587 case 0: gen_helper_neon_qabs_s8(tmp
, cpu_env
, tmp
); break;
5588 case 1: gen_helper_neon_qabs_s16(tmp
, cpu_env
, tmp
); break;
5589 case 2: gen_helper_neon_qabs_s32(tmp
, cpu_env
, tmp
); break;
5593 case 15: /* VQNEG */
5595 case 0: gen_helper_neon_qneg_s8(tmp
, cpu_env
, tmp
); break;
5596 case 1: gen_helper_neon_qneg_s16(tmp
, cpu_env
, tmp
); break;
5597 case 2: gen_helper_neon_qneg_s32(tmp
, cpu_env
, tmp
); break;
5601 case 16: case 19: /* VCGT #0, VCLE #0 */
5602 tmp2
= tcg_const_i32(0);
5604 case 0: gen_helper_neon_cgt_s8(tmp
, tmp
, tmp2
); break;
5605 case 1: gen_helper_neon_cgt_s16(tmp
, tmp
, tmp2
); break;
5606 case 2: gen_helper_neon_cgt_s32(tmp
, tmp
, tmp2
); break;
5609 tcg_temp_free(tmp2
);
5611 tcg_gen_not_i32(tmp
, tmp
);
5613 case 17: case 20: /* VCGE #0, VCLT #0 */
5614 tmp2
= tcg_const_i32(0);
5616 case 0: gen_helper_neon_cge_s8(tmp
, tmp
, tmp2
); break;
5617 case 1: gen_helper_neon_cge_s16(tmp
, tmp
, tmp2
); break;
5618 case 2: gen_helper_neon_cge_s32(tmp
, tmp
, tmp2
); break;
5621 tcg_temp_free(tmp2
);
5623 tcg_gen_not_i32(tmp
, tmp
);
5625 case 18: /* VCEQ #0 */
5626 tmp2
= tcg_const_i32(0);
5628 case 0: gen_helper_neon_ceq_u8(tmp
, tmp
, tmp2
); break;
5629 case 1: gen_helper_neon_ceq_u16(tmp
, tmp
, tmp2
); break;
5630 case 2: gen_helper_neon_ceq_u32(tmp
, tmp
, tmp2
); break;
5633 tcg_temp_free(tmp2
);
5637 case 0: gen_helper_neon_abs_s8(tmp
, tmp
); break;
5638 case 1: gen_helper_neon_abs_s16(tmp
, tmp
); break;
5639 case 2: tcg_gen_abs_i32(tmp
, tmp
); break;
5646 tmp2
= tcg_const_i32(0);
5647 gen_neon_rsb(size
, tmp
, tmp2
);
5648 tcg_temp_free(tmp2
);
5650 case 24: case 27: /* Float VCGT #0, Float VCLE #0 */
5651 tmp2
= tcg_const_i32(0);
5652 gen_helper_neon_cgt_f32(tmp
, tmp
, tmp2
);
5653 tcg_temp_free(tmp2
);
5655 tcg_gen_not_i32(tmp
, tmp
);
5657 case 25: case 28: /* Float VCGE #0, Float VCLT #0 */
5658 tmp2
= tcg_const_i32(0);
5659 gen_helper_neon_cge_f32(tmp
, tmp
, tmp2
);
5660 tcg_temp_free(tmp2
);
5662 tcg_gen_not_i32(tmp
, tmp
);
5664 case 26: /* Float VCEQ #0 */
5665 tmp2
= tcg_const_i32(0);
5666 gen_helper_neon_ceq_f32(tmp
, tmp
, tmp2
);
5667 tcg_temp_free(tmp2
);
5669 case 30: /* Float VABS */
5672 case 31: /* Float VNEG */
5676 tmp2
= neon_load_reg(rd
, pass
);
5677 neon_store_reg(rm
, pass
, tmp2
);
5680 tmp2
= neon_load_reg(rd
, pass
);
5682 case 0: gen_neon_trn_u8(tmp
, tmp2
); break;
5683 case 1: gen_neon_trn_u16(tmp
, tmp2
); break;
5687 neon_store_reg(rm
, pass
, tmp2
);
5689 case 56: /* Integer VRECPE */
5690 gen_helper_recpe_u32(tmp
, tmp
, cpu_env
);
5692 case 57: /* Integer VRSQRTE */
5693 gen_helper_rsqrte_u32(tmp
, tmp
, cpu_env
);
5695 case 58: /* Float VRECPE */
5696 gen_helper_recpe_f32(cpu_F0s
, cpu_F0s
, cpu_env
);
5698 case 59: /* Float VRSQRTE */
5699 gen_helper_rsqrte_f32(cpu_F0s
, cpu_F0s
, cpu_env
);
5701 case 60: /* VCVT.F32.S32 */
5704 case 61: /* VCVT.F32.U32 */
5707 case 62: /* VCVT.S32.F32 */
5710 case 63: /* VCVT.U32.F32 */
5714 /* Reserved: 21, 29, 39-56 */
5717 if (op
== 30 || op
== 31 || op
>= 58) {
5718 tcg_gen_st_f32(cpu_F0s
, cpu_env
,
5719 neon_reg_offset(rd
, pass
));
5721 neon_store_reg(rd
, pass
, tmp
);
5726 } else if ((insn
& (1 << 10)) == 0) {
5728 n
= ((insn
>> 5) & 0x18) + 8;
5729 if (insn
& (1 << 6)) {
5730 tmp
= neon_load_reg(rd
, 0);
5733 tcg_gen_movi_i32(tmp
, 0);
5735 tmp2
= neon_load_reg(rm
, 0);
5736 tmp4
= tcg_const_i32(rn
);
5737 tmp5
= tcg_const_i32(n
);
5738 gen_helper_neon_tbl(tmp2
, tmp2
, tmp
, tmp4
, tmp5
);
5740 if (insn
& (1 << 6)) {
5741 tmp
= neon_load_reg(rd
, 1);
5744 tcg_gen_movi_i32(tmp
, 0);
5746 tmp3
= neon_load_reg(rm
, 1);
5747 gen_helper_neon_tbl(tmp3
, tmp3
, tmp
, tmp4
, tmp5
);
5748 tcg_temp_free_i32(tmp5
);
5749 tcg_temp_free_i32(tmp4
);
5750 neon_store_reg(rd
, 0, tmp2
);
5751 neon_store_reg(rd
, 1, tmp3
);
5753 } else if ((insn
& 0x380) == 0) {
5755 if (insn
& (1 << 19)) {
5756 tmp
= neon_load_reg(rm
, 1);
5758 tmp
= neon_load_reg(rm
, 0);
5760 if (insn
& (1 << 16)) {
5761 gen_neon_dup_u8(tmp
, ((insn
>> 17) & 3) * 8);
5762 } else if (insn
& (1 << 17)) {
5763 if ((insn
>> 18) & 1)
5764 gen_neon_dup_high16(tmp
);
5766 gen_neon_dup_low16(tmp
);
5768 for (pass
= 0; pass
< (q
? 4 : 2); pass
++) {
5770 tcg_gen_mov_i32(tmp2
, tmp
);
5771 neon_store_reg(rd
, pass
, tmp2
);
5782 static int disas_cp14_read(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
5784 int crn
= (insn
>> 16) & 0xf;
5785 int crm
= insn
& 0xf;
5786 int op1
= (insn
>> 21) & 7;
5787 int op2
= (insn
>> 5) & 7;
5788 int rt
= (insn
>> 12) & 0xf;
5791 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
5792 if (op1
== 6 && crn
== 0 && crm
== 0 && op2
== 0) {
5796 tmp
= load_cpu_field(teecr
);
5797 store_reg(s
, rt
, tmp
);
5800 if (op1
== 6 && crn
== 1 && crm
== 0 && op2
== 0) {
5802 if (IS_USER(s
) && (env
->teecr
& 1))
5804 tmp
= load_cpu_field(teehbr
);
5805 store_reg(s
, rt
, tmp
);
5809 fprintf(stderr
, "Unknown cp14 read op1:%d crn:%d crm:%d op2:%d\n",
5810 op1
, crn
, crm
, op2
);
5814 static int disas_cp14_write(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
5816 int crn
= (insn
>> 16) & 0xf;
5817 int crm
= insn
& 0xf;
5818 int op1
= (insn
>> 21) & 7;
5819 int op2
= (insn
>> 5) & 7;
5820 int rt
= (insn
>> 12) & 0xf;
5823 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
5824 if (op1
== 6 && crn
== 0 && crm
== 0 && op2
== 0) {
5828 tmp
= load_reg(s
, rt
);
5829 gen_helper_set_teecr(cpu_env
, tmp
);
5833 if (op1
== 6 && crn
== 1 && crm
== 0 && op2
== 0) {
5835 if (IS_USER(s
) && (env
->teecr
& 1))
5837 tmp
= load_reg(s
, rt
);
5838 store_cpu_field(tmp
, teehbr
);
5842 fprintf(stderr
, "Unknown cp14 write op1:%d crn:%d crm:%d op2:%d\n",
5843 op1
, crn
, crm
, op2
);
5847 static int disas_coproc_insn(CPUState
* env
, DisasContext
*s
, uint32_t insn
)
5851 cpnum
= (insn
>> 8) & 0xf;
5852 if (arm_feature(env
, ARM_FEATURE_XSCALE
)
5853 && ((env
->cp15
.c15_cpar
^ 0x3fff) & (1 << cpnum
)))
5859 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
5860 return disas_iwmmxt_insn(env
, s
, insn
);
5861 } else if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
5862 return disas_dsp_insn(env
, s
, insn
);
5867 return disas_vfp_insn (env
, s
, insn
);
5869 /* Coprocessors 7-15 are architecturally reserved by ARM.
5870 Unfortunately Intel decided to ignore this. */
5871 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
5873 if (insn
& (1 << 20))
5874 return disas_cp14_read(env
, s
, insn
);
5876 return disas_cp14_write(env
, s
, insn
);
5878 return disas_cp15_insn (env
, s
, insn
);
5881 /* Unknown coprocessor. See if the board has hooked it. */
5882 return disas_cp_insn (env
, s
, insn
);
5887 /* Store a 64-bit value to a register pair. Clobbers val. */
5888 static void gen_storeq_reg(DisasContext
*s
, int rlow
, int rhigh
, TCGv_i64 val
)
5892 tcg_gen_trunc_i64_i32(tmp
, val
);
5893 store_reg(s
, rlow
, tmp
);
5895 tcg_gen_shri_i64(val
, val
, 32);
5896 tcg_gen_trunc_i64_i32(tmp
, val
);
5897 store_reg(s
, rhigh
, tmp
);
5900 /* load a 32-bit value from a register and perform a 64-bit accumulate. */
5901 static void gen_addq_lo(DisasContext
*s
, TCGv_i64 val
, int rlow
)
5906 /* Load value and extend to 64 bits. */
5907 tmp
= tcg_temp_new_i64();
5908 tmp2
= load_reg(s
, rlow
);
5909 tcg_gen_extu_i32_i64(tmp
, tmp2
);
5911 tcg_gen_add_i64(val
, val
, tmp
);
5912 tcg_temp_free_i64(tmp
);
5915 /* load and add a 64-bit value from a register pair. */
5916 static void gen_addq(DisasContext
*s
, TCGv_i64 val
, int rlow
, int rhigh
)
5922 /* Load 64-bit value rd:rn. */
5923 tmpl
= load_reg(s
, rlow
);
5924 tmph
= load_reg(s
, rhigh
);
5925 tmp
= tcg_temp_new_i64();
5926 tcg_gen_concat_i32_i64(tmp
, tmpl
, tmph
);
5929 tcg_gen_add_i64(val
, val
, tmp
);
5930 tcg_temp_free_i64(tmp
);
5933 /* Set N and Z flags from a 64-bit value. */
5934 static void gen_logicq_cc(TCGv_i64 val
)
5936 TCGv tmp
= new_tmp();
5937 gen_helper_logicq_cc(tmp
, val
);
5942 /* Load/Store exclusive instructions are implemented by remembering
5943 the value/address loaded, and seeing if these are the same
5944 when the store is performed. This should be is sufficient to implement
5945 the architecturally mandated semantics, and avoids having to monitor
5948 In system emulation mode only one CPU will be running at once, so
5949 this sequence is effectively atomic. In user emulation mode we
5950 throw an exception and handle the atomic operation elsewhere. */
5951 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
5952 TCGv addr
, int size
)
5958 tmp
= gen_ld8u(addr
, IS_USER(s
));
5961 tmp
= gen_ld16u(addr
, IS_USER(s
));
5965 tmp
= gen_ld32(addr
, IS_USER(s
));
5970 tcg_gen_mov_i32(cpu_exclusive_val
, tmp
);
5971 store_reg(s
, rt
, tmp
);
5973 TCGv tmp2
= new_tmp();
5974 tcg_gen_addi_i32(tmp2
, addr
, 4);
5975 tmp
= gen_ld32(tmp2
, IS_USER(s
));
5977 tcg_gen_mov_i32(cpu_exclusive_high
, tmp
);
5978 store_reg(s
, rt2
, tmp
);
5980 tcg_gen_mov_i32(cpu_exclusive_addr
, addr
);
5983 static void gen_clrex(DisasContext
*s
)
5985 tcg_gen_movi_i32(cpu_exclusive_addr
, -1);
5988 #ifdef CONFIG_USER_ONLY
5989 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
5990 TCGv addr
, int size
)
5992 tcg_gen_mov_i32(cpu_exclusive_test
, addr
);
5993 tcg_gen_movi_i32(cpu_exclusive_info
,
5994 size
| (rd
<< 4) | (rt
<< 8) | (rt2
<< 12));
5995 gen_exception_insn(s
, 4, EXCP_STREX
);
5998 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
5999 TCGv addr
, int size
)
6005 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]) {
6011 fail_label
= gen_new_label();
6012 done_label
= gen_new_label();
6013 tcg_gen_brcond_i32(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
6016 tmp
= gen_ld8u(addr
, IS_USER(s
));
6019 tmp
= gen_ld16u(addr
, IS_USER(s
));
6023 tmp
= gen_ld32(addr
, IS_USER(s
));
6028 tcg_gen_brcond_i32(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
6031 TCGv tmp2
= new_tmp();
6032 tcg_gen_addi_i32(tmp2
, addr
, 4);
6033 tmp
= gen_ld32(tmp2
, IS_USER(s
));
6035 tcg_gen_brcond_i32(TCG_COND_NE
, tmp
, cpu_exclusive_high
, fail_label
);
6038 tmp
= load_reg(s
, rt
);
6041 gen_st8(tmp
, addr
, IS_USER(s
));
6044 gen_st16(tmp
, addr
, IS_USER(s
));
6048 gen_st32(tmp
, addr
, IS_USER(s
));
6054 tcg_gen_addi_i32(addr
, addr
, 4);
6055 tmp
= load_reg(s
, rt2
);
6056 gen_st32(tmp
, addr
, IS_USER(s
));
6058 tcg_gen_movi_i32(cpu_R
[rd
], 0);
6059 tcg_gen_br(done_label
);
6060 gen_set_label(fail_label
);
6061 tcg_gen_movi_i32(cpu_R
[rd
], 1);
6062 gen_set_label(done_label
);
6063 tcg_gen_movi_i32(cpu_exclusive_addr
, -1);
6067 static void disas_arm_insn(CPUState
* env
, DisasContext
*s
)
6069 unsigned int cond
, insn
, val
, op1
, i
, shift
, rm
, rs
, rn
, rd
, sh
;
6076 insn
= ldl_code(s
->pc
);
6079 /* M variants do not implement ARM mode. */
6084 /* Unconditional instructions. */
6085 if (((insn
>> 25) & 7) == 1) {
6086 /* NEON Data processing. */
6087 if (!arm_feature(env
, ARM_FEATURE_NEON
))
6090 if (disas_neon_data_insn(env
, s
, insn
))
6094 if ((insn
& 0x0f100000) == 0x04000000) {
6095 /* NEON load/store. */
6096 if (!arm_feature(env
, ARM_FEATURE_NEON
))
6099 if (disas_neon_ls_insn(env
, s
, insn
))
6103 if (((insn
& 0x0f30f000) == 0x0510f000) ||
6104 ((insn
& 0x0f30f010) == 0x0710f000)) {
6105 if ((insn
& (1 << 22)) == 0) {
6107 if (!arm_feature(env
, ARM_FEATURE_V7MP
)) {
6111 /* Otherwise PLD; v5TE+ */
6114 if (((insn
& 0x0f70f000) == 0x0450f000) ||
6115 ((insn
& 0x0f70f010) == 0x0650f000)) {
6117 return; /* PLI; V7 */
6119 if (((insn
& 0x0f700000) == 0x04100000) ||
6120 ((insn
& 0x0f700010) == 0x06100000)) {
6121 if (!arm_feature(env
, ARM_FEATURE_V7MP
)) {
6124 return; /* v7MP: Unallocated memory hint: must NOP */
6127 if ((insn
& 0x0ffffdff) == 0x01010000) {
6130 if (insn
& (1 << 9)) {
6131 /* BE8 mode not implemented. */
6135 } else if ((insn
& 0x0fffff00) == 0x057ff000) {
6136 switch ((insn
>> 4) & 0xf) {
6145 /* We don't emulate caches so these are a no-op. */
6150 } else if ((insn
& 0x0e5fffe0) == 0x084d0500) {
6156 op1
= (insn
& 0x1f);
6158 tmp
= tcg_const_i32(op1
);
6159 gen_helper_get_r13_banked(addr
, cpu_env
, tmp
);
6160 tcg_temp_free_i32(tmp
);
6161 i
= (insn
>> 23) & 3;
6163 case 0: offset
= -4; break; /* DA */
6164 case 1: offset
= 0; break; /* IA */
6165 case 2: offset
= -8; break; /* DB */
6166 case 3: offset
= 4; break; /* IB */
6170 tcg_gen_addi_i32(addr
, addr
, offset
);
6171 tmp
= load_reg(s
, 14);
6172 gen_st32(tmp
, addr
, 0);
6173 tmp
= load_cpu_field(spsr
);
6174 tcg_gen_addi_i32(addr
, addr
, 4);
6175 gen_st32(tmp
, addr
, 0);
6176 if (insn
& (1 << 21)) {
6177 /* Base writeback. */
6179 case 0: offset
= -8; break;
6180 case 1: offset
= 4; break;
6181 case 2: offset
= -4; break;
6182 case 3: offset
= 0; break;
6186 tcg_gen_addi_i32(addr
, addr
, offset
);
6187 tmp
= tcg_const_i32(op1
);
6188 gen_helper_set_r13_banked(cpu_env
, tmp
, addr
);
6189 tcg_temp_free_i32(tmp
);
6195 } else if ((insn
& 0x0e50ffe0) == 0x08100a00) {
6201 rn
= (insn
>> 16) & 0xf;
6202 addr
= load_reg(s
, rn
);
6203 i
= (insn
>> 23) & 3;
6205 case 0: offset
= -4; break; /* DA */
6206 case 1: offset
= 0; break; /* IA */
6207 case 2: offset
= -8; break; /* DB */
6208 case 3: offset
= 4; break; /* IB */
6212 tcg_gen_addi_i32(addr
, addr
, offset
);
6213 /* Load PC into tmp and CPSR into tmp2. */
6214 tmp
= gen_ld32(addr
, 0);
6215 tcg_gen_addi_i32(addr
, addr
, 4);
6216 tmp2
= gen_ld32(addr
, 0);
6217 if (insn
& (1 << 21)) {
6218 /* Base writeback. */
6220 case 0: offset
= -8; break;
6221 case 1: offset
= 4; break;
6222 case 2: offset
= -4; break;
6223 case 3: offset
= 0; break;
6227 tcg_gen_addi_i32(addr
, addr
, offset
);
6228 store_reg(s
, rn
, addr
);
6232 gen_rfe(s
, tmp
, tmp2
);
6234 } else if ((insn
& 0x0e000000) == 0x0a000000) {
6235 /* branch link and change to thumb (blx <offset>) */
6238 val
= (uint32_t)s
->pc
;
6240 tcg_gen_movi_i32(tmp
, val
);
6241 store_reg(s
, 14, tmp
);
6242 /* Sign-extend the 24-bit offset */
6243 offset
= (((int32_t)insn
) << 8) >> 8;
6244 /* offset * 4 + bit24 * 2 + (thumb bit) */
6245 val
+= (offset
<< 2) | ((insn
>> 23) & 2) | 1;
6246 /* pipeline offset */
6250 } else if ((insn
& 0x0e000f00) == 0x0c000100) {
6251 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
6252 /* iWMMXt register transfer. */
6253 if (env
->cp15
.c15_cpar
& (1 << 1))
6254 if (!disas_iwmmxt_insn(env
, s
, insn
))
6257 } else if ((insn
& 0x0fe00000) == 0x0c400000) {
6258 /* Coprocessor double register transfer. */
6259 } else if ((insn
& 0x0f000010) == 0x0e000010) {
6260 /* Additional coprocessor register transfer. */
6261 } else if ((insn
& 0x0ff10020) == 0x01000000) {
6264 /* cps (privileged) */
6268 if (insn
& (1 << 19)) {
6269 if (insn
& (1 << 8))
6271 if (insn
& (1 << 7))
6273 if (insn
& (1 << 6))
6275 if (insn
& (1 << 18))
6278 if (insn
& (1 << 17)) {
6280 val
|= (insn
& 0x1f);
6283 gen_set_psr_im(s
, mask
, 0, val
);
6290 /* if not always execute, we generate a conditional jump to
6292 s
->condlabel
= gen_new_label();
6293 gen_test_cc(cond
^ 1, s
->condlabel
);
6296 if ((insn
& 0x0f900000) == 0x03000000) {
6297 if ((insn
& (1 << 21)) == 0) {
6299 rd
= (insn
>> 12) & 0xf;
6300 val
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
6301 if ((insn
& (1 << 22)) == 0) {
6304 tcg_gen_movi_i32(tmp
, val
);
6307 tmp
= load_reg(s
, rd
);
6308 tcg_gen_ext16u_i32(tmp
, tmp
);
6309 tcg_gen_ori_i32(tmp
, tmp
, val
<< 16);
6311 store_reg(s
, rd
, tmp
);
6313 if (((insn
>> 12) & 0xf) != 0xf)
6315 if (((insn
>> 16) & 0xf) == 0) {
6316 gen_nop_hint(s
, insn
& 0xff);
6318 /* CPSR = immediate */
6320 shift
= ((insn
>> 8) & 0xf) * 2;
6322 val
= (val
>> shift
) | (val
<< (32 - shift
));
6323 i
= ((insn
& (1 << 22)) != 0);
6324 if (gen_set_psr_im(s
, msr_mask(env
, s
, (insn
>> 16) & 0xf, i
), i
, val
))
6328 } else if ((insn
& 0x0f900000) == 0x01000000
6329 && (insn
& 0x00000090) != 0x00000090) {
6330 /* miscellaneous instructions */
6331 op1
= (insn
>> 21) & 3;
6332 sh
= (insn
>> 4) & 0xf;
6335 case 0x0: /* move program status register */
6338 tmp
= load_reg(s
, rm
);
6339 i
= ((op1
& 2) != 0);
6340 if (gen_set_psr(s
, msr_mask(env
, s
, (insn
>> 16) & 0xf, i
), i
, tmp
))
6344 rd
= (insn
>> 12) & 0xf;
6348 tmp
= load_cpu_field(spsr
);
6351 gen_helper_cpsr_read(tmp
);
6353 store_reg(s
, rd
, tmp
);
6358 /* branch/exchange thumb (bx). */
6359 tmp
= load_reg(s
, rm
);
6361 } else if (op1
== 3) {
6363 rd
= (insn
>> 12) & 0xf;
6364 tmp
= load_reg(s
, rm
);
6365 gen_helper_clz(tmp
, tmp
);
6366 store_reg(s
, rd
, tmp
);
6374 /* Trivial implementation equivalent to bx. */
6375 tmp
= load_reg(s
, rm
);
6385 /* branch link/exchange thumb (blx) */
6386 tmp
= load_reg(s
, rm
);
6388 tcg_gen_movi_i32(tmp2
, s
->pc
);
6389 store_reg(s
, 14, tmp2
);
6392 case 0x5: /* saturating add/subtract */
6393 rd
= (insn
>> 12) & 0xf;
6394 rn
= (insn
>> 16) & 0xf;
6395 tmp
= load_reg(s
, rm
);
6396 tmp2
= load_reg(s
, rn
);
6398 gen_helper_double_saturate(tmp2
, tmp2
);
6400 gen_helper_sub_saturate(tmp
, tmp
, tmp2
);
6402 gen_helper_add_saturate(tmp
, tmp
, tmp2
);
6404 store_reg(s
, rd
, tmp
);
6407 /* SMC instruction (op1 == 3)
6408 and undefined instructions (op1 == 0 || op1 == 2)
6414 gen_exception_insn(s
, 4, EXCP_BKPT
);
6416 case 0x8: /* signed multiply */
6420 rs
= (insn
>> 8) & 0xf;
6421 rn
= (insn
>> 12) & 0xf;
6422 rd
= (insn
>> 16) & 0xf;
6424 /* (32 * 16) >> 16 */
6425 tmp
= load_reg(s
, rm
);
6426 tmp2
= load_reg(s
, rs
);
6428 tcg_gen_sari_i32(tmp2
, tmp2
, 16);
6431 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
6432 tcg_gen_shri_i64(tmp64
, tmp64
, 16);
6434 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
6435 tcg_temp_free_i64(tmp64
);
6436 if ((sh
& 2) == 0) {
6437 tmp2
= load_reg(s
, rn
);
6438 gen_helper_add_setq(tmp
, tmp
, tmp2
);
6441 store_reg(s
, rd
, tmp
);
6444 tmp
= load_reg(s
, rm
);
6445 tmp2
= load_reg(s
, rs
);
6446 gen_mulxy(tmp
, tmp2
, sh
& 2, sh
& 4);
6449 tmp64
= tcg_temp_new_i64();
6450 tcg_gen_ext_i32_i64(tmp64
, tmp
);
6452 gen_addq(s
, tmp64
, rn
, rd
);
6453 gen_storeq_reg(s
, rn
, rd
, tmp64
);
6454 tcg_temp_free_i64(tmp64
);
6457 tmp2
= load_reg(s
, rn
);
6458 gen_helper_add_setq(tmp
, tmp
, tmp2
);
6461 store_reg(s
, rd
, tmp
);
6468 } else if (((insn
& 0x0e000000) == 0 &&
6469 (insn
& 0x00000090) != 0x90) ||
6470 ((insn
& 0x0e000000) == (1 << 25))) {
6471 int set_cc
, logic_cc
, shiftop
;
6473 op1
= (insn
>> 21) & 0xf;
6474 set_cc
= (insn
>> 20) & 1;
6475 logic_cc
= table_logic_cc
[op1
] & set_cc
;
6477 /* data processing instruction */
6478 if (insn
& (1 << 25)) {
6479 /* immediate operand */
6481 shift
= ((insn
>> 8) & 0xf) * 2;
6483 val
= (val
>> shift
) | (val
<< (32 - shift
));
6486 tcg_gen_movi_i32(tmp2
, val
);
6487 if (logic_cc
&& shift
) {
6488 gen_set_CF_bit31(tmp2
);
6493 tmp2
= load_reg(s
, rm
);
6494 shiftop
= (insn
>> 5) & 3;
6495 if (!(insn
& (1 << 4))) {
6496 shift
= (insn
>> 7) & 0x1f;
6497 gen_arm_shift_im(tmp2
, shiftop
, shift
, logic_cc
);
6499 rs
= (insn
>> 8) & 0xf;
6500 tmp
= load_reg(s
, rs
);
6501 gen_arm_shift_reg(tmp2
, shiftop
, tmp
, logic_cc
);
6504 if (op1
!= 0x0f && op1
!= 0x0d) {
6505 rn
= (insn
>> 16) & 0xf;
6506 tmp
= load_reg(s
, rn
);
6510 rd
= (insn
>> 12) & 0xf;
6513 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
6517 store_reg_bx(env
, s
, rd
, tmp
);
6520 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
6524 store_reg_bx(env
, s
, rd
, tmp
);
6527 if (set_cc
&& rd
== 15) {
6528 /* SUBS r15, ... is used for exception return. */
6532 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
6533 gen_exception_return(s
, tmp
);
6536 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
6538 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
6540 store_reg_bx(env
, s
, rd
, tmp
);
6545 gen_helper_sub_cc(tmp
, tmp2
, tmp
);
6547 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
6549 store_reg_bx(env
, s
, rd
, tmp
);
6553 gen_helper_add_cc(tmp
, tmp
, tmp2
);
6555 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
6557 store_reg_bx(env
, s
, rd
, tmp
);
6561 gen_helper_adc_cc(tmp
, tmp
, tmp2
);
6563 gen_add_carry(tmp
, tmp
, tmp2
);
6565 store_reg_bx(env
, s
, rd
, tmp
);
6569 gen_helper_sbc_cc(tmp
, tmp
, tmp2
);
6571 gen_sub_carry(tmp
, tmp
, tmp2
);
6573 store_reg_bx(env
, s
, rd
, tmp
);
6577 gen_helper_sbc_cc(tmp
, tmp2
, tmp
);
6579 gen_sub_carry(tmp
, tmp2
, tmp
);
6581 store_reg_bx(env
, s
, rd
, tmp
);
6585 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
6592 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
6599 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
6605 gen_helper_add_cc(tmp
, tmp
, tmp2
);
6610 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
6614 store_reg_bx(env
, s
, rd
, tmp
);
6617 if (logic_cc
&& rd
== 15) {
6618 /* MOVS r15, ... is used for exception return. */
6622 gen_exception_return(s
, tmp2
);
6627 store_reg_bx(env
, s
, rd
, tmp2
);
6631 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
6635 store_reg_bx(env
, s
, rd
, tmp
);
6639 tcg_gen_not_i32(tmp2
, tmp2
);
6643 store_reg_bx(env
, s
, rd
, tmp2
);
6646 if (op1
!= 0x0f && op1
!= 0x0d) {
6650 /* other instructions */
6651 op1
= (insn
>> 24) & 0xf;
6655 /* multiplies, extra load/stores */
6656 sh
= (insn
>> 5) & 3;
6659 rd
= (insn
>> 16) & 0xf;
6660 rn
= (insn
>> 12) & 0xf;
6661 rs
= (insn
>> 8) & 0xf;
6663 op1
= (insn
>> 20) & 0xf;
6665 case 0: case 1: case 2: case 3: case 6:
6667 tmp
= load_reg(s
, rs
);
6668 tmp2
= load_reg(s
, rm
);
6669 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
6671 if (insn
& (1 << 22)) {
6672 /* Subtract (mls) */
6674 tmp2
= load_reg(s
, rn
);
6675 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
6677 } else if (insn
& (1 << 21)) {
6679 tmp2
= load_reg(s
, rn
);
6680 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
6683 if (insn
& (1 << 20))
6685 store_reg(s
, rd
, tmp
);
6688 /* 64 bit mul double accumulate (UMAAL) */
6690 tmp
= load_reg(s
, rs
);
6691 tmp2
= load_reg(s
, rm
);
6692 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
6693 gen_addq_lo(s
, tmp64
, rn
);
6694 gen_addq_lo(s
, tmp64
, rd
);
6695 gen_storeq_reg(s
, rn
, rd
, tmp64
);
6696 tcg_temp_free_i64(tmp64
);
6698 case 8: case 9: case 10: case 11:
6699 case 12: case 13: case 14: case 15:
6700 /* 64 bit mul: UMULL, UMLAL, SMULL, SMLAL. */
6701 tmp
= load_reg(s
, rs
);
6702 tmp2
= load_reg(s
, rm
);
6703 if (insn
& (1 << 22)) {
6704 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
6706 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
6708 if (insn
& (1 << 21)) { /* mult accumulate */
6709 gen_addq(s
, tmp64
, rn
, rd
);
6711 if (insn
& (1 << 20)) {
6712 gen_logicq_cc(tmp64
);
6714 gen_storeq_reg(s
, rn
, rd
, tmp64
);
6715 tcg_temp_free_i64(tmp64
);
6721 rn
= (insn
>> 16) & 0xf;
6722 rd
= (insn
>> 12) & 0xf;
6723 if (insn
& (1 << 23)) {
6724 /* load/store exclusive */
6725 op1
= (insn
>> 21) & 0x3;
6730 addr
= tcg_temp_local_new_i32();
6731 load_reg_var(s
, addr
, rn
);
6732 if (insn
& (1 << 20)) {
6735 gen_load_exclusive(s
, rd
, 15, addr
, 2);
6737 case 1: /* ldrexd */
6738 gen_load_exclusive(s
, rd
, rd
+ 1, addr
, 3);
6740 case 2: /* ldrexb */
6741 gen_load_exclusive(s
, rd
, 15, addr
, 0);
6743 case 3: /* ldrexh */
6744 gen_load_exclusive(s
, rd
, 15, addr
, 1);
6753 gen_store_exclusive(s
, rd
, rm
, 15, addr
, 2);
6755 case 1: /* strexd */
6756 gen_store_exclusive(s
, rd
, rm
, rm
+ 1, addr
, 3);
6758 case 2: /* strexb */
6759 gen_store_exclusive(s
, rd
, rm
, 15, addr
, 0);
6761 case 3: /* strexh */
6762 gen_store_exclusive(s
, rd
, rm
, 15, addr
, 1);
6768 tcg_temp_free(addr
);
6770 /* SWP instruction */
6773 /* ??? This is not really atomic. However we know
6774 we never have multiple CPUs running in parallel,
6775 so it is good enough. */
6776 addr
= load_reg(s
, rn
);
6777 tmp
= load_reg(s
, rm
);
6778 if (insn
& (1 << 22)) {
6779 tmp2
= gen_ld8u(addr
, IS_USER(s
));
6780 gen_st8(tmp
, addr
, IS_USER(s
));
6782 tmp2
= gen_ld32(addr
, IS_USER(s
));
6783 gen_st32(tmp
, addr
, IS_USER(s
));
6786 store_reg(s
, rd
, tmp2
);
6792 /* Misc load/store */
6793 rn
= (insn
>> 16) & 0xf;
6794 rd
= (insn
>> 12) & 0xf;
6795 addr
= load_reg(s
, rn
);
6796 if (insn
& (1 << 24))
6797 gen_add_datah_offset(s
, insn
, 0, addr
);
6799 if (insn
& (1 << 20)) {
6803 tmp
= gen_ld16u(addr
, IS_USER(s
));
6806 tmp
= gen_ld8s(addr
, IS_USER(s
));
6810 tmp
= gen_ld16s(addr
, IS_USER(s
));
6814 } else if (sh
& 2) {
6818 tmp
= load_reg(s
, rd
);
6819 gen_st32(tmp
, addr
, IS_USER(s
));
6820 tcg_gen_addi_i32(addr
, addr
, 4);
6821 tmp
= load_reg(s
, rd
+ 1);
6822 gen_st32(tmp
, addr
, IS_USER(s
));
6826 tmp
= gen_ld32(addr
, IS_USER(s
));
6827 store_reg(s
, rd
, tmp
);
6828 tcg_gen_addi_i32(addr
, addr
, 4);
6829 tmp
= gen_ld32(addr
, IS_USER(s
));
6833 address_offset
= -4;
6836 tmp
= load_reg(s
, rd
);
6837 gen_st16(tmp
, addr
, IS_USER(s
));
6840 /* Perform base writeback before the loaded value to
6841 ensure correct behavior with overlapping index registers.
6842 ldrd with base writeback is is undefined if the
6843 destination and index registers overlap. */
6844 if (!(insn
& (1 << 24))) {
6845 gen_add_datah_offset(s
, insn
, address_offset
, addr
);
6846 store_reg(s
, rn
, addr
);
6847 } else if (insn
& (1 << 21)) {
6849 tcg_gen_addi_i32(addr
, addr
, address_offset
);
6850 store_reg(s
, rn
, addr
);
6855 /* Complete the load. */
6856 store_reg(s
, rd
, tmp
);
6865 if (insn
& (1 << 4)) {
6867 /* Armv6 Media instructions. */
6869 rn
= (insn
>> 16) & 0xf;
6870 rd
= (insn
>> 12) & 0xf;
6871 rs
= (insn
>> 8) & 0xf;
6872 switch ((insn
>> 23) & 3) {
6873 case 0: /* Parallel add/subtract. */
6874 op1
= (insn
>> 20) & 7;
6875 tmp
= load_reg(s
, rn
);
6876 tmp2
= load_reg(s
, rm
);
6877 sh
= (insn
>> 5) & 7;
6878 if ((op1
& 3) == 0 || sh
== 5 || sh
== 6)
6880 gen_arm_parallel_addsub(op1
, sh
, tmp
, tmp2
);
6882 store_reg(s
, rd
, tmp
);
6885 if ((insn
& 0x00700020) == 0) {
6886 /* Halfword pack. */
6887 tmp
= load_reg(s
, rn
);
6888 tmp2
= load_reg(s
, rm
);
6889 shift
= (insn
>> 7) & 0x1f;
6890 if (insn
& (1 << 6)) {
6894 tcg_gen_sari_i32(tmp2
, tmp2
, shift
);
6895 tcg_gen_andi_i32(tmp
, tmp
, 0xffff0000);
6896 tcg_gen_ext16u_i32(tmp2
, tmp2
);
6900 tcg_gen_shli_i32(tmp2
, tmp2
, shift
);
6901 tcg_gen_ext16u_i32(tmp
, tmp
);
6902 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffff0000);
6904 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
6906 store_reg(s
, rd
, tmp
);
6907 } else if ((insn
& 0x00200020) == 0x00200000) {
6909 tmp
= load_reg(s
, rm
);
6910 shift
= (insn
>> 7) & 0x1f;
6911 if (insn
& (1 << 6)) {
6914 tcg_gen_sari_i32(tmp
, tmp
, shift
);
6916 tcg_gen_shli_i32(tmp
, tmp
, shift
);
6918 sh
= (insn
>> 16) & 0x1f;
6919 tmp2
= tcg_const_i32(sh
);
6920 if (insn
& (1 << 22))
6921 gen_helper_usat(tmp
, tmp
, tmp2
);
6923 gen_helper_ssat(tmp
, tmp
, tmp2
);
6924 tcg_temp_free_i32(tmp2
);
6925 store_reg(s
, rd
, tmp
);
6926 } else if ((insn
& 0x00300fe0) == 0x00200f20) {
6928 tmp
= load_reg(s
, rm
);
6929 sh
= (insn
>> 16) & 0x1f;
6930 tmp2
= tcg_const_i32(sh
);
6931 if (insn
& (1 << 22))
6932 gen_helper_usat16(tmp
, tmp
, tmp2
);
6934 gen_helper_ssat16(tmp
, tmp
, tmp2
);
6935 tcg_temp_free_i32(tmp2
);
6936 store_reg(s
, rd
, tmp
);
6937 } else if ((insn
& 0x00700fe0) == 0x00000fa0) {
6939 tmp
= load_reg(s
, rn
);
6940 tmp2
= load_reg(s
, rm
);
6942 tcg_gen_ld_i32(tmp3
, cpu_env
, offsetof(CPUState
, GE
));
6943 gen_helper_sel_flags(tmp
, tmp3
, tmp
, tmp2
);
6946 store_reg(s
, rd
, tmp
);
6947 } else if ((insn
& 0x000003e0) == 0x00000060) {
6948 tmp
= load_reg(s
, rm
);
6949 shift
= (insn
>> 10) & 3;
6950 /* ??? In many cases it's not neccessary to do a
6951 rotate, a shift is sufficient. */
6953 tcg_gen_rotri_i32(tmp
, tmp
, shift
* 8);
6954 op1
= (insn
>> 20) & 7;
6956 case 0: gen_sxtb16(tmp
); break;
6957 case 2: gen_sxtb(tmp
); break;
6958 case 3: gen_sxth(tmp
); break;
6959 case 4: gen_uxtb16(tmp
); break;
6960 case 6: gen_uxtb(tmp
); break;
6961 case 7: gen_uxth(tmp
); break;
6962 default: goto illegal_op
;
6965 tmp2
= load_reg(s
, rn
);
6966 if ((op1
& 3) == 0) {
6967 gen_add16(tmp
, tmp2
);
6969 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
6973 store_reg(s
, rd
, tmp
);
6974 } else if ((insn
& 0x003f0f60) == 0x003f0f20) {
6976 tmp
= load_reg(s
, rm
);
6977 if (insn
& (1 << 22)) {
6978 if (insn
& (1 << 7)) {
6982 gen_helper_rbit(tmp
, tmp
);
6985 if (insn
& (1 << 7))
6988 tcg_gen_bswap32_i32(tmp
, tmp
);
6990 store_reg(s
, rd
, tmp
);
6995 case 2: /* Multiplies (Type 3). */
6996 tmp
= load_reg(s
, rm
);
6997 tmp2
= load_reg(s
, rs
);
6998 if (insn
& (1 << 20)) {
6999 /* Signed multiply most significant [accumulate].
7000 (SMMUL, SMMLA, SMMLS) */
7001 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
7004 tmp
= load_reg(s
, rd
);
7005 if (insn
& (1 << 6)) {
7006 tmp64
= gen_subq_msw(tmp64
, tmp
);
7008 tmp64
= gen_addq_msw(tmp64
, tmp
);
7011 if (insn
& (1 << 5)) {
7012 tcg_gen_addi_i64(tmp64
, tmp64
, 0x80000000u
);
7014 tcg_gen_shri_i64(tmp64
, tmp64
, 32);
7016 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
7017 tcg_temp_free_i64(tmp64
);
7018 store_reg(s
, rn
, tmp
);
7020 if (insn
& (1 << 5))
7021 gen_swap_half(tmp2
);
7022 gen_smul_dual(tmp
, tmp2
);
7023 /* This addition cannot overflow. */
7024 if (insn
& (1 << 6)) {
7025 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
7027 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7030 if (insn
& (1 << 22)) {
7031 /* smlald, smlsld */
7032 tmp64
= tcg_temp_new_i64();
7033 tcg_gen_ext_i32_i64(tmp64
, tmp
);
7035 gen_addq(s
, tmp64
, rd
, rn
);
7036 gen_storeq_reg(s
, rd
, rn
, tmp64
);
7037 tcg_temp_free_i64(tmp64
);
7039 /* smuad, smusd, smlad, smlsd */
7042 tmp2
= load_reg(s
, rd
);
7043 gen_helper_add_setq(tmp
, tmp
, tmp2
);
7046 store_reg(s
, rn
, tmp
);
7051 op1
= ((insn
>> 17) & 0x38) | ((insn
>> 5) & 7);
7053 case 0: /* Unsigned sum of absolute differences. */
7055 tmp
= load_reg(s
, rm
);
7056 tmp2
= load_reg(s
, rs
);
7057 gen_helper_usad8(tmp
, tmp
, tmp2
);
7060 tmp2
= load_reg(s
, rd
);
7061 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7064 store_reg(s
, rn
, tmp
);
7066 case 0x20: case 0x24: case 0x28: case 0x2c:
7067 /* Bitfield insert/clear. */
7069 shift
= (insn
>> 7) & 0x1f;
7070 i
= (insn
>> 16) & 0x1f;
7074 tcg_gen_movi_i32(tmp
, 0);
7076 tmp
= load_reg(s
, rm
);
7079 tmp2
= load_reg(s
, rd
);
7080 gen_bfi(tmp
, tmp2
, tmp
, shift
, (1u << i
) - 1);
7083 store_reg(s
, rd
, tmp
);
7085 case 0x12: case 0x16: case 0x1a: case 0x1e: /* sbfx */
7086 case 0x32: case 0x36: case 0x3a: case 0x3e: /* ubfx */
7088 tmp
= load_reg(s
, rm
);
7089 shift
= (insn
>> 7) & 0x1f;
7090 i
= ((insn
>> 16) & 0x1f) + 1;
7095 gen_ubfx(tmp
, shift
, (1u << i
) - 1);
7097 gen_sbfx(tmp
, shift
, i
);
7100 store_reg(s
, rd
, tmp
);
7110 /* Check for undefined extension instructions
7111 * per the ARM Bible IE:
7112 * xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
7114 sh
= (0xf << 20) | (0xf << 4);
7115 if (op1
== 0x7 && ((insn
& sh
) == sh
))
7119 /* load/store byte/word */
7120 rn
= (insn
>> 16) & 0xf;
7121 rd
= (insn
>> 12) & 0xf;
7122 tmp2
= load_reg(s
, rn
);
7123 i
= (IS_USER(s
) || (insn
& 0x01200000) == 0x00200000);
7124 if (insn
& (1 << 24))
7125 gen_add_data_offset(s
, insn
, tmp2
);
7126 if (insn
& (1 << 20)) {
7128 if (insn
& (1 << 22)) {
7129 tmp
= gen_ld8u(tmp2
, i
);
7131 tmp
= gen_ld32(tmp2
, i
);
7135 tmp
= load_reg(s
, rd
);
7136 if (insn
& (1 << 22))
7137 gen_st8(tmp
, tmp2
, i
);
7139 gen_st32(tmp
, tmp2
, i
);
7141 if (!(insn
& (1 << 24))) {
7142 gen_add_data_offset(s
, insn
, tmp2
);
7143 store_reg(s
, rn
, tmp2
);
7144 } else if (insn
& (1 << 21)) {
7145 store_reg(s
, rn
, tmp2
);
7149 if (insn
& (1 << 20)) {
7150 /* Complete the load. */
7154 store_reg(s
, rd
, tmp
);
7160 int j
, n
, user
, loaded_base
;
7162 /* load/store multiple words */
7163 /* XXX: store correct base if write back */
7165 if (insn
& (1 << 22)) {
7167 goto illegal_op
; /* only usable in supervisor mode */
7169 if ((insn
& (1 << 15)) == 0)
7172 rn
= (insn
>> 16) & 0xf;
7173 addr
= load_reg(s
, rn
);
7175 /* compute total size */
7177 TCGV_UNUSED(loaded_var
);
7180 if (insn
& (1 << i
))
7183 /* XXX: test invalid n == 0 case ? */
7184 if (insn
& (1 << 23)) {
7185 if (insn
& (1 << 24)) {
7187 tcg_gen_addi_i32(addr
, addr
, 4);
7189 /* post increment */
7192 if (insn
& (1 << 24)) {
7194 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
7196 /* post decrement */
7198 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
7203 if (insn
& (1 << i
)) {
7204 if (insn
& (1 << 20)) {
7206 tmp
= gen_ld32(addr
, IS_USER(s
));
7210 tmp2
= tcg_const_i32(i
);
7211 gen_helper_set_user_reg(tmp2
, tmp
);
7212 tcg_temp_free_i32(tmp2
);
7214 } else if (i
== rn
) {
7218 store_reg(s
, i
, tmp
);
7223 /* special case: r15 = PC + 8 */
7224 val
= (long)s
->pc
+ 4;
7226 tcg_gen_movi_i32(tmp
, val
);
7229 tmp2
= tcg_const_i32(i
);
7230 gen_helper_get_user_reg(tmp
, tmp2
);
7231 tcg_temp_free_i32(tmp2
);
7233 tmp
= load_reg(s
, i
);
7235 gen_st32(tmp
, addr
, IS_USER(s
));
7238 /* no need to add after the last transfer */
7240 tcg_gen_addi_i32(addr
, addr
, 4);
7243 if (insn
& (1 << 21)) {
7245 if (insn
& (1 << 23)) {
7246 if (insn
& (1 << 24)) {
7249 /* post increment */
7250 tcg_gen_addi_i32(addr
, addr
, 4);
7253 if (insn
& (1 << 24)) {
7256 tcg_gen_addi_i32(addr
, addr
, -((n
- 1) * 4));
7258 /* post decrement */
7259 tcg_gen_addi_i32(addr
, addr
, -(n
* 4));
7262 store_reg(s
, rn
, addr
);
7267 store_reg(s
, rn
, loaded_var
);
7269 if ((insn
& (1 << 22)) && !user
) {
7270 /* Restore CPSR from SPSR. */
7271 tmp
= load_cpu_field(spsr
);
7272 gen_set_cpsr(tmp
, 0xffffffff);
7274 s
->is_jmp
= DISAS_UPDATE
;
7283 /* branch (and link) */
7284 val
= (int32_t)s
->pc
;
7285 if (insn
& (1 << 24)) {
7287 tcg_gen_movi_i32(tmp
, val
);
7288 store_reg(s
, 14, tmp
);
7290 offset
= (((int32_t)insn
<< 8) >> 8);
7291 val
+= (offset
<< 2) + 4;
7299 if (disas_coproc_insn(env
, s
, insn
))
7304 gen_set_pc_im(s
->pc
);
7305 s
->is_jmp
= DISAS_SWI
;
7309 gen_exception_insn(s
, 4, EXCP_UDEF
);
7315 /* Return true if this is a Thumb-2 logical op. */
7317 thumb2_logic_op(int op
)
7322 /* Generate code for a Thumb-2 data processing operation. If CONDS is nonzero
7323 then set condition code flags based on the result of the operation.
7324 If SHIFTER_OUT is nonzero then set the carry flag for logical operations
7325 to the high bit of T1.
7326 Returns zero if the opcode is valid. */
7329 gen_thumb2_data_op(DisasContext
*s
, int op
, int conds
, uint32_t shifter_out
, TCGv t0
, TCGv t1
)
7336 tcg_gen_and_i32(t0
, t0
, t1
);
7340 tcg_gen_andc_i32(t0
, t0
, t1
);
7344 tcg_gen_or_i32(t0
, t0
, t1
);
7348 tcg_gen_not_i32(t1
, t1
);
7349 tcg_gen_or_i32(t0
, t0
, t1
);
7353 tcg_gen_xor_i32(t0
, t0
, t1
);
7358 gen_helper_add_cc(t0
, t0
, t1
);
7360 tcg_gen_add_i32(t0
, t0
, t1
);
7364 gen_helper_adc_cc(t0
, t0
, t1
);
7370 gen_helper_sbc_cc(t0
, t0
, t1
);
7372 gen_sub_carry(t0
, t0
, t1
);
7376 gen_helper_sub_cc(t0
, t0
, t1
);
7378 tcg_gen_sub_i32(t0
, t0
, t1
);
7382 gen_helper_sub_cc(t0
, t1
, t0
);
7384 tcg_gen_sub_i32(t0
, t1
, t0
);
7386 default: /* 5, 6, 7, 9, 12, 15. */
7392 gen_set_CF_bit31(t1
);
7397 /* Translate a 32-bit thumb instruction. Returns nonzero if the instruction
7399 static int disas_thumb2_insn(CPUState
*env
, DisasContext
*s
, uint16_t insn_hw1
)
7401 uint32_t insn
, imm
, shift
, offset
;
7402 uint32_t rd
, rn
, rm
, rs
;
7413 if (!(arm_feature(env
, ARM_FEATURE_THUMB2
)
7414 || arm_feature (env
, ARM_FEATURE_M
))) {
7415 /* Thumb-1 cores may need to treat bl and blx as a pair of
7416 16-bit instructions to get correct prefetch abort behavior. */
7418 if ((insn
& (1 << 12)) == 0) {
7419 /* Second half of blx. */
7420 offset
= ((insn
& 0x7ff) << 1);
7421 tmp
= load_reg(s
, 14);
7422 tcg_gen_addi_i32(tmp
, tmp
, offset
);
7423 tcg_gen_andi_i32(tmp
, tmp
, 0xfffffffc);
7426 tcg_gen_movi_i32(tmp2
, s
->pc
| 1);
7427 store_reg(s
, 14, tmp2
);
7431 if (insn
& (1 << 11)) {
7432 /* Second half of bl. */
7433 offset
= ((insn
& 0x7ff) << 1) | 1;
7434 tmp
= load_reg(s
, 14);
7435 tcg_gen_addi_i32(tmp
, tmp
, offset
);
7438 tcg_gen_movi_i32(tmp2
, s
->pc
| 1);
7439 store_reg(s
, 14, tmp2
);
7443 if ((s
->pc
& ~TARGET_PAGE_MASK
) == 0) {
7444 /* Instruction spans a page boundary. Implement it as two
7445 16-bit instructions in case the second half causes an
7447 offset
= ((int32_t)insn
<< 21) >> 9;
7448 tcg_gen_movi_i32(cpu_R
[14], s
->pc
+ 2 + offset
);
7451 /* Fall through to 32-bit decode. */
7454 insn
= lduw_code(s
->pc
);
7456 insn
|= (uint32_t)insn_hw1
<< 16;
7458 if ((insn
& 0xf800e800) != 0xf000e800) {
7462 rn
= (insn
>> 16) & 0xf;
7463 rs
= (insn
>> 12) & 0xf;
7464 rd
= (insn
>> 8) & 0xf;
7466 switch ((insn
>> 25) & 0xf) {
7467 case 0: case 1: case 2: case 3:
7468 /* 16-bit instructions. Should never happen. */
7471 if (insn
& (1 << 22)) {
7472 /* Other load/store, table branch. */
7473 if (insn
& 0x01200000) {
7474 /* Load/store doubleword. */
7477 tcg_gen_movi_i32(addr
, s
->pc
& ~3);
7479 addr
= load_reg(s
, rn
);
7481 offset
= (insn
& 0xff) * 4;
7482 if ((insn
& (1 << 23)) == 0)
7484 if (insn
& (1 << 24)) {
7485 tcg_gen_addi_i32(addr
, addr
, offset
);
7488 if (insn
& (1 << 20)) {
7490 tmp
= gen_ld32(addr
, IS_USER(s
));
7491 store_reg(s
, rs
, tmp
);
7492 tcg_gen_addi_i32(addr
, addr
, 4);
7493 tmp
= gen_ld32(addr
, IS_USER(s
));
7494 store_reg(s
, rd
, tmp
);
7497 tmp
= load_reg(s
, rs
);
7498 gen_st32(tmp
, addr
, IS_USER(s
));
7499 tcg_gen_addi_i32(addr
, addr
, 4);
7500 tmp
= load_reg(s
, rd
);
7501 gen_st32(tmp
, addr
, IS_USER(s
));
7503 if (insn
& (1 << 21)) {
7504 /* Base writeback. */
7507 tcg_gen_addi_i32(addr
, addr
, offset
- 4);
7508 store_reg(s
, rn
, addr
);
7512 } else if ((insn
& (1 << 23)) == 0) {
7513 /* Load/store exclusive word. */
7514 addr
= tcg_temp_local_new();
7515 load_reg_var(s
, addr
, rn
);
7516 tcg_gen_addi_i32(addr
, addr
, (insn
& 0xff) << 2);
7517 if (insn
& (1 << 20)) {
7518 gen_load_exclusive(s
, rs
, 15, addr
, 2);
7520 gen_store_exclusive(s
, rd
, rs
, 15, addr
, 2);
7522 tcg_temp_free(addr
);
7523 } else if ((insn
& (1 << 6)) == 0) {
7527 tcg_gen_movi_i32(addr
, s
->pc
);
7529 addr
= load_reg(s
, rn
);
7531 tmp
= load_reg(s
, rm
);
7532 tcg_gen_add_i32(addr
, addr
, tmp
);
7533 if (insn
& (1 << 4)) {
7535 tcg_gen_add_i32(addr
, addr
, tmp
);
7537 tmp
= gen_ld16u(addr
, IS_USER(s
));
7540 tmp
= gen_ld8u(addr
, IS_USER(s
));
7543 tcg_gen_shli_i32(tmp
, tmp
, 1);
7544 tcg_gen_addi_i32(tmp
, tmp
, s
->pc
);
7545 store_reg(s
, 15, tmp
);
7547 /* Load/store exclusive byte/halfword/doubleword. */
7549 op
= (insn
>> 4) & 0x3;
7553 addr
= tcg_temp_local_new();
7554 load_reg_var(s
, addr
, rn
);
7555 if (insn
& (1 << 20)) {
7556 gen_load_exclusive(s
, rs
, rd
, addr
, op
);
7558 gen_store_exclusive(s
, rm
, rs
, rd
, addr
, op
);
7560 tcg_temp_free(addr
);
7563 /* Load/store multiple, RFE, SRS. */
7564 if (((insn
>> 23) & 1) == ((insn
>> 24) & 1)) {
7565 /* Not available in user mode. */
7568 if (insn
& (1 << 20)) {
7570 addr
= load_reg(s
, rn
);
7571 if ((insn
& (1 << 24)) == 0)
7572 tcg_gen_addi_i32(addr
, addr
, -8);
7573 /* Load PC into tmp and CPSR into tmp2. */
7574 tmp
= gen_ld32(addr
, 0);
7575 tcg_gen_addi_i32(addr
, addr
, 4);
7576 tmp2
= gen_ld32(addr
, 0);
7577 if (insn
& (1 << 21)) {
7578 /* Base writeback. */
7579 if (insn
& (1 << 24)) {
7580 tcg_gen_addi_i32(addr
, addr
, 4);
7582 tcg_gen_addi_i32(addr
, addr
, -4);
7584 store_reg(s
, rn
, addr
);
7588 gen_rfe(s
, tmp
, tmp2
);
7593 tmp
= tcg_const_i32(op
);
7594 gen_helper_get_r13_banked(addr
, cpu_env
, tmp
);
7595 tcg_temp_free_i32(tmp
);
7596 if ((insn
& (1 << 24)) == 0) {
7597 tcg_gen_addi_i32(addr
, addr
, -8);
7599 tmp
= load_reg(s
, 14);
7600 gen_st32(tmp
, addr
, 0);
7601 tcg_gen_addi_i32(addr
, addr
, 4);
7603 gen_helper_cpsr_read(tmp
);
7604 gen_st32(tmp
, addr
, 0);
7605 if (insn
& (1 << 21)) {
7606 if ((insn
& (1 << 24)) == 0) {
7607 tcg_gen_addi_i32(addr
, addr
, -4);
7609 tcg_gen_addi_i32(addr
, addr
, 4);
7611 tmp
= tcg_const_i32(op
);
7612 gen_helper_set_r13_banked(cpu_env
, tmp
, addr
);
7613 tcg_temp_free_i32(tmp
);
7620 /* Load/store multiple. */
7621 addr
= load_reg(s
, rn
);
7623 for (i
= 0; i
< 16; i
++) {
7624 if (insn
& (1 << i
))
7627 if (insn
& (1 << 24)) {
7628 tcg_gen_addi_i32(addr
, addr
, -offset
);
7631 for (i
= 0; i
< 16; i
++) {
7632 if ((insn
& (1 << i
)) == 0)
7634 if (insn
& (1 << 20)) {
7636 tmp
= gen_ld32(addr
, IS_USER(s
));
7640 store_reg(s
, i
, tmp
);
7644 tmp
= load_reg(s
, i
);
7645 gen_st32(tmp
, addr
, IS_USER(s
));
7647 tcg_gen_addi_i32(addr
, addr
, 4);
7649 if (insn
& (1 << 21)) {
7650 /* Base register writeback. */
7651 if (insn
& (1 << 24)) {
7652 tcg_gen_addi_i32(addr
, addr
, -offset
);
7654 /* Fault if writeback register is in register list. */
7655 if (insn
& (1 << rn
))
7657 store_reg(s
, rn
, addr
);
7666 op
= (insn
>> 21) & 0xf;
7668 /* Halfword pack. */
7669 tmp
= load_reg(s
, rn
);
7670 tmp2
= load_reg(s
, rm
);
7671 shift
= ((insn
>> 10) & 0x1c) | ((insn
>> 6) & 0x3);
7672 if (insn
& (1 << 5)) {
7676 tcg_gen_sari_i32(tmp2
, tmp2
, shift
);
7677 tcg_gen_andi_i32(tmp
, tmp
, 0xffff0000);
7678 tcg_gen_ext16u_i32(tmp2
, tmp2
);
7682 tcg_gen_shli_i32(tmp2
, tmp2
, shift
);
7683 tcg_gen_ext16u_i32(tmp
, tmp
);
7684 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffff0000);
7686 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
7688 store_reg(s
, rd
, tmp
);
7690 /* Data processing register constant shift. */
7693 tcg_gen_movi_i32(tmp
, 0);
7695 tmp
= load_reg(s
, rn
);
7697 tmp2
= load_reg(s
, rm
);
7699 shiftop
= (insn
>> 4) & 3;
7700 shift
= ((insn
>> 6) & 3) | ((insn
>> 10) & 0x1c);
7701 conds
= (insn
& (1 << 20)) != 0;
7702 logic_cc
= (conds
&& thumb2_logic_op(op
));
7703 gen_arm_shift_im(tmp2
, shiftop
, shift
, logic_cc
);
7704 if (gen_thumb2_data_op(s
, op
, conds
, 0, tmp
, tmp2
))
7708 store_reg(s
, rd
, tmp
);
7714 case 13: /* Misc data processing. */
7715 op
= ((insn
>> 22) & 6) | ((insn
>> 7) & 1);
7716 if (op
< 4 && (insn
& 0xf000) != 0xf000)
7719 case 0: /* Register controlled shift. */
7720 tmp
= load_reg(s
, rn
);
7721 tmp2
= load_reg(s
, rm
);
7722 if ((insn
& 0x70) != 0)
7724 op
= (insn
>> 21) & 3;
7725 logic_cc
= (insn
& (1 << 20)) != 0;
7726 gen_arm_shift_reg(tmp
, op
, tmp2
, logic_cc
);
7729 store_reg_bx(env
, s
, rd
, tmp
);
7731 case 1: /* Sign/zero extend. */
7732 tmp
= load_reg(s
, rm
);
7733 shift
= (insn
>> 4) & 3;
7734 /* ??? In many cases it's not neccessary to do a
7735 rotate, a shift is sufficient. */
7737 tcg_gen_rotri_i32(tmp
, tmp
, shift
* 8);
7738 op
= (insn
>> 20) & 7;
7740 case 0: gen_sxth(tmp
); break;
7741 case 1: gen_uxth(tmp
); break;
7742 case 2: gen_sxtb16(tmp
); break;
7743 case 3: gen_uxtb16(tmp
); break;
7744 case 4: gen_sxtb(tmp
); break;
7745 case 5: gen_uxtb(tmp
); break;
7746 default: goto illegal_op
;
7749 tmp2
= load_reg(s
, rn
);
7750 if ((op
>> 1) == 1) {
7751 gen_add16(tmp
, tmp2
);
7753 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7757 store_reg(s
, rd
, tmp
);
7759 case 2: /* SIMD add/subtract. */
7760 op
= (insn
>> 20) & 7;
7761 shift
= (insn
>> 4) & 7;
7762 if ((op
& 3) == 3 || (shift
& 3) == 3)
7764 tmp
= load_reg(s
, rn
);
7765 tmp2
= load_reg(s
, rm
);
7766 gen_thumb2_parallel_addsub(op
, shift
, tmp
, tmp2
);
7768 store_reg(s
, rd
, tmp
);
7770 case 3: /* Other data processing. */
7771 op
= ((insn
>> 17) & 0x38) | ((insn
>> 4) & 7);
7773 /* Saturating add/subtract. */
7774 tmp
= load_reg(s
, rn
);
7775 tmp2
= load_reg(s
, rm
);
7777 gen_helper_double_saturate(tmp
, tmp
);
7779 gen_helper_sub_saturate(tmp
, tmp2
, tmp
);
7781 gen_helper_add_saturate(tmp
, tmp
, tmp2
);
7784 tmp
= load_reg(s
, rn
);
7786 case 0x0a: /* rbit */
7787 gen_helper_rbit(tmp
, tmp
);
7789 case 0x08: /* rev */
7790 tcg_gen_bswap32_i32(tmp
, tmp
);
7792 case 0x09: /* rev16 */
7795 case 0x0b: /* revsh */
7798 case 0x10: /* sel */
7799 tmp2
= load_reg(s
, rm
);
7801 tcg_gen_ld_i32(tmp3
, cpu_env
, offsetof(CPUState
, GE
));
7802 gen_helper_sel_flags(tmp
, tmp3
, tmp
, tmp2
);
7806 case 0x18: /* clz */
7807 gen_helper_clz(tmp
, tmp
);
7813 store_reg(s
, rd
, tmp
);
7815 case 4: case 5: /* 32-bit multiply. Sum of absolute differences. */
7816 op
= (insn
>> 4) & 0xf;
7817 tmp
= load_reg(s
, rn
);
7818 tmp2
= load_reg(s
, rm
);
7819 switch ((insn
>> 20) & 7) {
7820 case 0: /* 32 x 32 -> 32 */
7821 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
7824 tmp2
= load_reg(s
, rs
);
7826 tcg_gen_sub_i32(tmp
, tmp2
, tmp
);
7828 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7832 case 1: /* 16 x 16 -> 32 */
7833 gen_mulxy(tmp
, tmp2
, op
& 2, op
& 1);
7836 tmp2
= load_reg(s
, rs
);
7837 gen_helper_add_setq(tmp
, tmp
, tmp2
);
7841 case 2: /* Dual multiply add. */
7842 case 4: /* Dual multiply subtract. */
7844 gen_swap_half(tmp2
);
7845 gen_smul_dual(tmp
, tmp2
);
7846 /* This addition cannot overflow. */
7847 if (insn
& (1 << 22)) {
7848 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
7850 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7855 tmp2
= load_reg(s
, rs
);
7856 gen_helper_add_setq(tmp
, tmp
, tmp2
);
7860 case 3: /* 32 * 16 -> 32msb */
7862 tcg_gen_sari_i32(tmp2
, tmp2
, 16);
7865 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
7866 tcg_gen_shri_i64(tmp64
, tmp64
, 16);
7868 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
7869 tcg_temp_free_i64(tmp64
);
7872 tmp2
= load_reg(s
, rs
);
7873 gen_helper_add_setq(tmp
, tmp
, tmp2
);
7877 case 5: case 6: /* 32 * 32 -> 32msb (SMMUL, SMMLA, SMMLS) */
7878 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
7880 tmp
= load_reg(s
, rs
);
7881 if (insn
& (1 << 20)) {
7882 tmp64
= gen_addq_msw(tmp64
, tmp
);
7884 tmp64
= gen_subq_msw(tmp64
, tmp
);
7887 if (insn
& (1 << 4)) {
7888 tcg_gen_addi_i64(tmp64
, tmp64
, 0x80000000u
);
7890 tcg_gen_shri_i64(tmp64
, tmp64
, 32);
7892 tcg_gen_trunc_i64_i32(tmp
, tmp64
);
7893 tcg_temp_free_i64(tmp64
);
7895 case 7: /* Unsigned sum of absolute differences. */
7896 gen_helper_usad8(tmp
, tmp
, tmp2
);
7899 tmp2
= load_reg(s
, rs
);
7900 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7905 store_reg(s
, rd
, tmp
);
7907 case 6: case 7: /* 64-bit multiply, Divide. */
7908 op
= ((insn
>> 4) & 0xf) | ((insn
>> 16) & 0x70);
7909 tmp
= load_reg(s
, rn
);
7910 tmp2
= load_reg(s
, rm
);
7911 if ((op
& 0x50) == 0x10) {
7913 if (!arm_feature(env
, ARM_FEATURE_DIV
))
7916 gen_helper_udiv(tmp
, tmp
, tmp2
);
7918 gen_helper_sdiv(tmp
, tmp
, tmp2
);
7920 store_reg(s
, rd
, tmp
);
7921 } else if ((op
& 0xe) == 0xc) {
7922 /* Dual multiply accumulate long. */
7924 gen_swap_half(tmp2
);
7925 gen_smul_dual(tmp
, tmp2
);
7927 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
7929 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
7933 tmp64
= tcg_temp_new_i64();
7934 tcg_gen_ext_i32_i64(tmp64
, tmp
);
7936 gen_addq(s
, tmp64
, rs
, rd
);
7937 gen_storeq_reg(s
, rs
, rd
, tmp64
);
7938 tcg_temp_free_i64(tmp64
);
7941 /* Unsigned 64-bit multiply */
7942 tmp64
= gen_mulu_i64_i32(tmp
, tmp2
);
7946 gen_mulxy(tmp
, tmp2
, op
& 2, op
& 1);
7948 tmp64
= tcg_temp_new_i64();
7949 tcg_gen_ext_i32_i64(tmp64
, tmp
);
7952 /* Signed 64-bit multiply */
7953 tmp64
= gen_muls_i64_i32(tmp
, tmp2
);
7958 gen_addq_lo(s
, tmp64
, rs
);
7959 gen_addq_lo(s
, tmp64
, rd
);
7960 } else if (op
& 0x40) {
7961 /* 64-bit accumulate. */
7962 gen_addq(s
, tmp64
, rs
, rd
);
7964 gen_storeq_reg(s
, rs
, rd
, tmp64
);
7965 tcg_temp_free_i64(tmp64
);
7970 case 6: case 7: case 14: case 15:
7972 if (((insn
>> 24) & 3) == 3) {
7973 /* Translate into the equivalent ARM encoding. */
7974 insn
= (insn
& 0xe2ffffff) | ((insn
& (1 << 28)) >> 4);
7975 if (disas_neon_data_insn(env
, s
, insn
))
7978 if (insn
& (1 << 28))
7980 if (disas_coproc_insn (env
, s
, insn
))
7984 case 8: case 9: case 10: case 11:
7985 if (insn
& (1 << 15)) {
7986 /* Branches, misc control. */
7987 if (insn
& 0x5000) {
7988 /* Unconditional branch. */
7989 /* signextend(hw1[10:0]) -> offset[:12]. */
7990 offset
= ((int32_t)insn
<< 5) >> 9 & ~(int32_t)0xfff;
7991 /* hw1[10:0] -> offset[11:1]. */
7992 offset
|= (insn
& 0x7ff) << 1;
7993 /* (~hw2[13, 11] ^ offset[24]) -> offset[23,22]
7994 offset[24:22] already have the same value because of the
7995 sign extension above. */
7996 offset
^= ((~insn
) & (1 << 13)) << 10;
7997 offset
^= ((~insn
) & (1 << 11)) << 11;
7999 if (insn
& (1 << 14)) {
8000 /* Branch and link. */
8001 tcg_gen_movi_i32(cpu_R
[14], s
->pc
| 1);
8005 if (insn
& (1 << 12)) {
8010 offset
&= ~(uint32_t)2;
8011 gen_bx_im(s
, offset
);
8013 } else if (((insn
>> 23) & 7) == 7) {
8015 if (insn
& (1 << 13))
8018 if (insn
& (1 << 26)) {
8019 /* Secure monitor call (v6Z) */
8020 goto illegal_op
; /* not implemented. */
8022 op
= (insn
>> 20) & 7;
8024 case 0: /* msr cpsr. */
8026 tmp
= load_reg(s
, rn
);
8027 addr
= tcg_const_i32(insn
& 0xff);
8028 gen_helper_v7m_msr(cpu_env
, addr
, tmp
);
8029 tcg_temp_free_i32(addr
);
8035 case 1: /* msr spsr. */
8038 tmp
= load_reg(s
, rn
);
8040 msr_mask(env
, s
, (insn
>> 8) & 0xf, op
== 1),
8044 case 2: /* cps, nop-hint. */
8045 if (((insn
>> 8) & 7) == 0) {
8046 gen_nop_hint(s
, insn
& 0xff);
8048 /* Implemented as NOP in user mode. */
8053 if (insn
& (1 << 10)) {
8054 if (insn
& (1 << 7))
8056 if (insn
& (1 << 6))
8058 if (insn
& (1 << 5))
8060 if (insn
& (1 << 9))
8061 imm
= CPSR_A
| CPSR_I
| CPSR_F
;
8063 if (insn
& (1 << 8)) {
8065 imm
|= (insn
& 0x1f);
8068 gen_set_psr_im(s
, offset
, 0, imm
);
8071 case 3: /* Special control operations. */
8073 op
= (insn
>> 4) & 0xf;
8081 /* These execute as NOPs. */
8088 /* Trivial implementation equivalent to bx. */
8089 tmp
= load_reg(s
, rn
);
8092 case 5: /* Exception return. */
8096 if (rn
!= 14 || rd
!= 15) {
8099 tmp
= load_reg(s
, rn
);
8100 tcg_gen_subi_i32(tmp
, tmp
, insn
& 0xff);
8101 gen_exception_return(s
, tmp
);
8103 case 6: /* mrs cpsr. */
8106 addr
= tcg_const_i32(insn
& 0xff);
8107 gen_helper_v7m_mrs(tmp
, cpu_env
, addr
);
8108 tcg_temp_free_i32(addr
);
8110 gen_helper_cpsr_read(tmp
);
8112 store_reg(s
, rd
, tmp
);
8114 case 7: /* mrs spsr. */
8115 /* Not accessible in user mode. */
8116 if (IS_USER(s
) || IS_M(env
))
8118 tmp
= load_cpu_field(spsr
);
8119 store_reg(s
, rd
, tmp
);
8124 /* Conditional branch. */
8125 op
= (insn
>> 22) & 0xf;
8126 /* Generate a conditional jump to next instruction. */
8127 s
->condlabel
= gen_new_label();
8128 gen_test_cc(op
^ 1, s
->condlabel
);
8131 /* offset[11:1] = insn[10:0] */
8132 offset
= (insn
& 0x7ff) << 1;
8133 /* offset[17:12] = insn[21:16]. */
8134 offset
|= (insn
& 0x003f0000) >> 4;
8135 /* offset[31:20] = insn[26]. */
8136 offset
|= ((int32_t)((insn
<< 5) & 0x80000000)) >> 11;
8137 /* offset[18] = insn[13]. */
8138 offset
|= (insn
& (1 << 13)) << 5;
8139 /* offset[19] = insn[11]. */
8140 offset
|= (insn
& (1 << 11)) << 8;
8142 /* jump to the offset */
8143 gen_jmp(s
, s
->pc
+ offset
);
8146 /* Data processing immediate. */
8147 if (insn
& (1 << 25)) {
8148 if (insn
& (1 << 24)) {
8149 if (insn
& (1 << 20))
8151 /* Bitfield/Saturate. */
8152 op
= (insn
>> 21) & 7;
8154 shift
= ((insn
>> 6) & 3) | ((insn
>> 10) & 0x1c);
8157 tcg_gen_movi_i32(tmp
, 0);
8159 tmp
= load_reg(s
, rn
);
8162 case 2: /* Signed bitfield extract. */
8164 if (shift
+ imm
> 32)
8167 gen_sbfx(tmp
, shift
, imm
);
8169 case 6: /* Unsigned bitfield extract. */
8171 if (shift
+ imm
> 32)
8174 gen_ubfx(tmp
, shift
, (1u << imm
) - 1);
8176 case 3: /* Bitfield insert/clear. */
8179 imm
= imm
+ 1 - shift
;
8181 tmp2
= load_reg(s
, rd
);
8182 gen_bfi(tmp
, tmp2
, tmp
, shift
, (1u << imm
) - 1);
8188 default: /* Saturate. */
8191 tcg_gen_sari_i32(tmp
, tmp
, shift
);
8193 tcg_gen_shli_i32(tmp
, tmp
, shift
);
8195 tmp2
= tcg_const_i32(imm
);
8198 if ((op
& 1) && shift
== 0)
8199 gen_helper_usat16(tmp
, tmp
, tmp2
);
8201 gen_helper_usat(tmp
, tmp
, tmp2
);
8204 if ((op
& 1) && shift
== 0)
8205 gen_helper_ssat16(tmp
, tmp
, tmp2
);
8207 gen_helper_ssat(tmp
, tmp
, tmp2
);
8209 tcg_temp_free_i32(tmp2
);
8212 store_reg(s
, rd
, tmp
);
8214 imm
= ((insn
& 0x04000000) >> 15)
8215 | ((insn
& 0x7000) >> 4) | (insn
& 0xff);
8216 if (insn
& (1 << 22)) {
8217 /* 16-bit immediate. */
8218 imm
|= (insn
>> 4) & 0xf000;
8219 if (insn
& (1 << 23)) {
8221 tmp
= load_reg(s
, rd
);
8222 tcg_gen_ext16u_i32(tmp
, tmp
);
8223 tcg_gen_ori_i32(tmp
, tmp
, imm
<< 16);
8227 tcg_gen_movi_i32(tmp
, imm
);
8230 /* Add/sub 12-bit immediate. */
8232 offset
= s
->pc
& ~(uint32_t)3;
8233 if (insn
& (1 << 23))
8238 tcg_gen_movi_i32(tmp
, offset
);
8240 tmp
= load_reg(s
, rn
);
8241 if (insn
& (1 << 23))
8242 tcg_gen_subi_i32(tmp
, tmp
, imm
);
8244 tcg_gen_addi_i32(tmp
, tmp
, imm
);
8247 store_reg(s
, rd
, tmp
);
8250 int shifter_out
= 0;
8251 /* modified 12-bit immediate. */
8252 shift
= ((insn
& 0x04000000) >> 23) | ((insn
& 0x7000) >> 12);
8253 imm
= (insn
& 0xff);
8256 /* Nothing to do. */
8258 case 1: /* 00XY00XY */
8261 case 2: /* XY00XY00 */
8265 case 3: /* XYXYXYXY */
8269 default: /* Rotated constant. */
8270 shift
= (shift
<< 1) | (imm
>> 7);
8272 imm
= imm
<< (32 - shift
);
8277 tcg_gen_movi_i32(tmp2
, imm
);
8278 rn
= (insn
>> 16) & 0xf;
8281 tcg_gen_movi_i32(tmp
, 0);
8283 tmp
= load_reg(s
, rn
);
8285 op
= (insn
>> 21) & 0xf;
8286 if (gen_thumb2_data_op(s
, op
, (insn
& (1 << 20)) != 0,
8287 shifter_out
, tmp
, tmp2
))
8290 rd
= (insn
>> 8) & 0xf;
8292 store_reg(s
, rd
, tmp
);
8299 case 12: /* Load/store single data item. */
8304 if ((insn
& 0x01100000) == 0x01000000) {
8305 if (disas_neon_ls_insn(env
, s
, insn
))
8309 op
= ((insn
>> 21) & 3) | ((insn
>> 22) & 4);
8311 if (!(insn
& (1 << 20))) {
8315 /* Byte or halfword load space with dest == r15 : memory hints.
8316 * Catch them early so we don't emit pointless addressing code.
8317 * This space is a mix of:
8318 * PLD/PLDW/PLI, which we implement as NOPs (note that unlike
8319 * the ARM encodings, PLDW space doesn't UNDEF for non-v7MP
8321 * unallocated hints, which must be treated as NOPs
8322 * UNPREDICTABLE space, which we NOP or UNDEF depending on
8323 * which is easiest for the decoding logic
8324 * Some space which must UNDEF
8326 int op1
= (insn
>> 23) & 3;
8327 int op2
= (insn
>> 6) & 0x3f;
8332 /* UNPREDICTABLE or unallocated hint */
8336 return 0; /* PLD* or unallocated hint */
8338 if ((op2
== 0) || ((op2
& 0x3c) == 0x30)) {
8339 return 0; /* PLD* or unallocated hint */
8341 /* UNDEF space, or an UNPREDICTABLE */
8349 /* s->pc has already been incremented by 4. */
8350 imm
= s
->pc
& 0xfffffffc;
8351 if (insn
& (1 << 23))
8352 imm
+= insn
& 0xfff;
8354 imm
-= insn
& 0xfff;
8355 tcg_gen_movi_i32(addr
, imm
);
8357 addr
= load_reg(s
, rn
);
8358 if (insn
& (1 << 23)) {
8359 /* Positive offset. */
8361 tcg_gen_addi_i32(addr
, addr
, imm
);
8364 switch ((insn
>> 8) & 7) {
8365 case 0: case 8: /* Shifted Register. */
8366 shift
= (insn
>> 4) & 0xf;
8369 tmp
= load_reg(s
, rm
);
8371 tcg_gen_shli_i32(tmp
, tmp
, shift
);
8372 tcg_gen_add_i32(addr
, addr
, tmp
);
8375 case 4: /* Negative offset. */
8376 tcg_gen_addi_i32(addr
, addr
, -imm
);
8378 case 6: /* User privilege. */
8379 tcg_gen_addi_i32(addr
, addr
, imm
);
8382 case 1: /* Post-decrement. */
8385 case 3: /* Post-increment. */
8389 case 5: /* Pre-decrement. */
8392 case 7: /* Pre-increment. */
8393 tcg_gen_addi_i32(addr
, addr
, imm
);
8401 if (insn
& (1 << 20)) {
8404 case 0: tmp
= gen_ld8u(addr
, user
); break;
8405 case 4: tmp
= gen_ld8s(addr
, user
); break;
8406 case 1: tmp
= gen_ld16u(addr
, user
); break;
8407 case 5: tmp
= gen_ld16s(addr
, user
); break;
8408 case 2: tmp
= gen_ld32(addr
, user
); break;
8409 default: goto illegal_op
;
8414 store_reg(s
, rs
, tmp
);
8418 tmp
= load_reg(s
, rs
);
8420 case 0: gen_st8(tmp
, addr
, user
); break;
8421 case 1: gen_st16(tmp
, addr
, user
); break;
8422 case 2: gen_st32(tmp
, addr
, user
); break;
8423 default: goto illegal_op
;
8427 tcg_gen_addi_i32(addr
, addr
, imm
);
8429 store_reg(s
, rn
, addr
);
8443 static void disas_thumb_insn(CPUState
*env
, DisasContext
*s
)
8445 uint32_t val
, insn
, op
, rm
, rn
, rd
, shift
, cond
;
8452 if (s
->condexec_mask
) {
8453 cond
= s
->condexec_cond
;
8454 if (cond
!= 0x0e) { /* Skip conditional when condition is AL. */
8455 s
->condlabel
= gen_new_label();
8456 gen_test_cc(cond
^ 1, s
->condlabel
);
8461 insn
= lduw_code(s
->pc
);
8464 switch (insn
>> 12) {
8468 op
= (insn
>> 11) & 3;
8471 rn
= (insn
>> 3) & 7;
8472 tmp
= load_reg(s
, rn
);
8473 if (insn
& (1 << 10)) {
8476 tcg_gen_movi_i32(tmp2
, (insn
>> 6) & 7);
8479 rm
= (insn
>> 6) & 7;
8480 tmp2
= load_reg(s
, rm
);
8482 if (insn
& (1 << 9)) {
8483 if (s
->condexec_mask
)
8484 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
8486 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8488 if (s
->condexec_mask
)
8489 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8491 gen_helper_add_cc(tmp
, tmp
, tmp2
);
8494 store_reg(s
, rd
, tmp
);
8496 /* shift immediate */
8497 rm
= (insn
>> 3) & 7;
8498 shift
= (insn
>> 6) & 0x1f;
8499 tmp
= load_reg(s
, rm
);
8500 gen_arm_shift_im(tmp
, op
, shift
, s
->condexec_mask
== 0);
8501 if (!s
->condexec_mask
)
8503 store_reg(s
, rd
, tmp
);
8507 /* arithmetic large immediate */
8508 op
= (insn
>> 11) & 3;
8509 rd
= (insn
>> 8) & 0x7;
8510 if (op
== 0) { /* mov */
8512 tcg_gen_movi_i32(tmp
, insn
& 0xff);
8513 if (!s
->condexec_mask
)
8515 store_reg(s
, rd
, tmp
);
8517 tmp
= load_reg(s
, rd
);
8519 tcg_gen_movi_i32(tmp2
, insn
& 0xff);
8522 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8527 if (s
->condexec_mask
)
8528 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8530 gen_helper_add_cc(tmp
, tmp
, tmp2
);
8532 store_reg(s
, rd
, tmp
);
8535 if (s
->condexec_mask
)
8536 tcg_gen_sub_i32(tmp
, tmp
, tmp2
);
8538 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8540 store_reg(s
, rd
, tmp
);
8546 if (insn
& (1 << 11)) {
8547 rd
= (insn
>> 8) & 7;
8548 /* load pc-relative. Bit 1 of PC is ignored. */
8549 val
= s
->pc
+ 2 + ((insn
& 0xff) * 4);
8550 val
&= ~(uint32_t)2;
8552 tcg_gen_movi_i32(addr
, val
);
8553 tmp
= gen_ld32(addr
, IS_USER(s
));
8555 store_reg(s
, rd
, tmp
);
8558 if (insn
& (1 << 10)) {
8559 /* data processing extended or blx */
8560 rd
= (insn
& 7) | ((insn
>> 4) & 8);
8561 rm
= (insn
>> 3) & 0xf;
8562 op
= (insn
>> 8) & 3;
8565 tmp
= load_reg(s
, rd
);
8566 tmp2
= load_reg(s
, rm
);
8567 tcg_gen_add_i32(tmp
, tmp
, tmp2
);
8569 store_reg(s
, rd
, tmp
);
8572 tmp
= load_reg(s
, rd
);
8573 tmp2
= load_reg(s
, rm
);
8574 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8578 case 2: /* mov/cpy */
8579 tmp
= load_reg(s
, rm
);
8580 store_reg(s
, rd
, tmp
);
8582 case 3:/* branch [and link] exchange thumb register */
8583 tmp
= load_reg(s
, rm
);
8584 if (insn
& (1 << 7)) {
8585 val
= (uint32_t)s
->pc
| 1;
8587 tcg_gen_movi_i32(tmp2
, val
);
8588 store_reg(s
, 14, tmp2
);
8596 /* data processing register */
8598 rm
= (insn
>> 3) & 7;
8599 op
= (insn
>> 6) & 0xf;
8600 if (op
== 2 || op
== 3 || op
== 4 || op
== 7) {
8601 /* the shift/rotate ops want the operands backwards */
8610 if (op
== 9) { /* neg */
8612 tcg_gen_movi_i32(tmp
, 0);
8613 } else if (op
!= 0xf) { /* mvn doesn't read its first operand */
8614 tmp
= load_reg(s
, rd
);
8619 tmp2
= load_reg(s
, rm
);
8622 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
8623 if (!s
->condexec_mask
)
8627 tcg_gen_xor_i32(tmp
, tmp
, tmp2
);
8628 if (!s
->condexec_mask
)
8632 if (s
->condexec_mask
) {
8633 gen_helper_shl(tmp2
, tmp2
, tmp
);
8635 gen_helper_shl_cc(tmp2
, tmp2
, tmp
);
8640 if (s
->condexec_mask
) {
8641 gen_helper_shr(tmp2
, tmp2
, tmp
);
8643 gen_helper_shr_cc(tmp2
, tmp2
, tmp
);
8648 if (s
->condexec_mask
) {
8649 gen_helper_sar(tmp2
, tmp2
, tmp
);
8651 gen_helper_sar_cc(tmp2
, tmp2
, tmp
);
8656 if (s
->condexec_mask
)
8659 gen_helper_adc_cc(tmp
, tmp
, tmp2
);
8662 if (s
->condexec_mask
)
8663 gen_sub_carry(tmp
, tmp
, tmp2
);
8665 gen_helper_sbc_cc(tmp
, tmp
, tmp2
);
8668 if (s
->condexec_mask
) {
8669 tcg_gen_andi_i32(tmp
, tmp
, 0x1f);
8670 tcg_gen_rotr_i32(tmp2
, tmp2
, tmp
);
8672 gen_helper_ror_cc(tmp2
, tmp2
, tmp
);
8677 tcg_gen_and_i32(tmp
, tmp
, tmp2
);
8682 if (s
->condexec_mask
)
8683 tcg_gen_neg_i32(tmp
, tmp2
);
8685 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8688 gen_helper_sub_cc(tmp
, tmp
, tmp2
);
8692 gen_helper_add_cc(tmp
, tmp
, tmp2
);
8696 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
8697 if (!s
->condexec_mask
)
8701 tcg_gen_mul_i32(tmp
, tmp
, tmp2
);
8702 if (!s
->condexec_mask
)
8706 tcg_gen_andc_i32(tmp
, tmp
, tmp2
);
8707 if (!s
->condexec_mask
)
8711 tcg_gen_not_i32(tmp2
, tmp2
);
8712 if (!s
->condexec_mask
)
8720 store_reg(s
, rm
, tmp2
);
8724 store_reg(s
, rd
, tmp
);
8734 /* load/store register offset. */
8736 rn
= (insn
>> 3) & 7;
8737 rm
= (insn
>> 6) & 7;
8738 op
= (insn
>> 9) & 7;
8739 addr
= load_reg(s
, rn
);
8740 tmp
= load_reg(s
, rm
);
8741 tcg_gen_add_i32(addr
, addr
, tmp
);
8744 if (op
< 3) /* store */
8745 tmp
= load_reg(s
, rd
);
8749 gen_st32(tmp
, addr
, IS_USER(s
));
8752 gen_st16(tmp
, addr
, IS_USER(s
));
8755 gen_st8(tmp
, addr
, IS_USER(s
));
8758 tmp
= gen_ld8s(addr
, IS_USER(s
));
8761 tmp
= gen_ld32(addr
, IS_USER(s
));
8764 tmp
= gen_ld16u(addr
, IS_USER(s
));
8767 tmp
= gen_ld8u(addr
, IS_USER(s
));
8770 tmp
= gen_ld16s(addr
, IS_USER(s
));
8773 if (op
>= 3) /* load */
8774 store_reg(s
, rd
, tmp
);
8779 /* load/store word immediate offset */
8781 rn
= (insn
>> 3) & 7;
8782 addr
= load_reg(s
, rn
);
8783 val
= (insn
>> 4) & 0x7c;
8784 tcg_gen_addi_i32(addr
, addr
, val
);
8786 if (insn
& (1 << 11)) {
8788 tmp
= gen_ld32(addr
, IS_USER(s
));
8789 store_reg(s
, rd
, tmp
);
8792 tmp
= load_reg(s
, rd
);
8793 gen_st32(tmp
, addr
, IS_USER(s
));
8799 /* load/store byte immediate offset */
8801 rn
= (insn
>> 3) & 7;
8802 addr
= load_reg(s
, rn
);
8803 val
= (insn
>> 6) & 0x1f;
8804 tcg_gen_addi_i32(addr
, addr
, val
);
8806 if (insn
& (1 << 11)) {
8808 tmp
= gen_ld8u(addr
, IS_USER(s
));
8809 store_reg(s
, rd
, tmp
);
8812 tmp
= load_reg(s
, rd
);
8813 gen_st8(tmp
, addr
, IS_USER(s
));
8819 /* load/store halfword immediate offset */
8821 rn
= (insn
>> 3) & 7;
8822 addr
= load_reg(s
, rn
);
8823 val
= (insn
>> 5) & 0x3e;
8824 tcg_gen_addi_i32(addr
, addr
, val
);
8826 if (insn
& (1 << 11)) {
8828 tmp
= gen_ld16u(addr
, IS_USER(s
));
8829 store_reg(s
, rd
, tmp
);
8832 tmp
= load_reg(s
, rd
);
8833 gen_st16(tmp
, addr
, IS_USER(s
));
8839 /* load/store from stack */
8840 rd
= (insn
>> 8) & 7;
8841 addr
= load_reg(s
, 13);
8842 val
= (insn
& 0xff) * 4;
8843 tcg_gen_addi_i32(addr
, addr
, val
);
8845 if (insn
& (1 << 11)) {
8847 tmp
= gen_ld32(addr
, IS_USER(s
));
8848 store_reg(s
, rd
, tmp
);
8851 tmp
= load_reg(s
, rd
);
8852 gen_st32(tmp
, addr
, IS_USER(s
));
8858 /* add to high reg */
8859 rd
= (insn
>> 8) & 7;
8860 if (insn
& (1 << 11)) {
8862 tmp
= load_reg(s
, 13);
8864 /* PC. bit 1 is ignored. */
8866 tcg_gen_movi_i32(tmp
, (s
->pc
+ 2) & ~(uint32_t)2);
8868 val
= (insn
& 0xff) * 4;
8869 tcg_gen_addi_i32(tmp
, tmp
, val
);
8870 store_reg(s
, rd
, tmp
);
8875 op
= (insn
>> 8) & 0xf;
8878 /* adjust stack pointer */
8879 tmp
= load_reg(s
, 13);
8880 val
= (insn
& 0x7f) * 4;
8881 if (insn
& (1 << 7))
8882 val
= -(int32_t)val
;
8883 tcg_gen_addi_i32(tmp
, tmp
, val
);
8884 store_reg(s
, 13, tmp
);
8887 case 2: /* sign/zero extend. */
8890 rm
= (insn
>> 3) & 7;
8891 tmp
= load_reg(s
, rm
);
8892 switch ((insn
>> 6) & 3) {
8893 case 0: gen_sxth(tmp
); break;
8894 case 1: gen_sxtb(tmp
); break;
8895 case 2: gen_uxth(tmp
); break;
8896 case 3: gen_uxtb(tmp
); break;
8898 store_reg(s
, rd
, tmp
);
8900 case 4: case 5: case 0xc: case 0xd:
8902 addr
= load_reg(s
, 13);
8903 if (insn
& (1 << 8))
8907 for (i
= 0; i
< 8; i
++) {
8908 if (insn
& (1 << i
))
8911 if ((insn
& (1 << 11)) == 0) {
8912 tcg_gen_addi_i32(addr
, addr
, -offset
);
8914 for (i
= 0; i
< 8; i
++) {
8915 if (insn
& (1 << i
)) {
8916 if (insn
& (1 << 11)) {
8918 tmp
= gen_ld32(addr
, IS_USER(s
));
8919 store_reg(s
, i
, tmp
);
8922 tmp
= load_reg(s
, i
);
8923 gen_st32(tmp
, addr
, IS_USER(s
));
8925 /* advance to the next address. */
8926 tcg_gen_addi_i32(addr
, addr
, 4);
8930 if (insn
& (1 << 8)) {
8931 if (insn
& (1 << 11)) {
8933 tmp
= gen_ld32(addr
, IS_USER(s
));
8934 /* don't set the pc until the rest of the instruction
8938 tmp
= load_reg(s
, 14);
8939 gen_st32(tmp
, addr
, IS_USER(s
));
8941 tcg_gen_addi_i32(addr
, addr
, 4);
8943 if ((insn
& (1 << 11)) == 0) {
8944 tcg_gen_addi_i32(addr
, addr
, -offset
);
8946 /* write back the new stack pointer */
8947 store_reg(s
, 13, addr
);
8948 /* set the new PC value */
8949 if ((insn
& 0x0900) == 0x0900)
8953 case 1: case 3: case 9: case 11: /* czb */
8955 tmp
= load_reg(s
, rm
);
8956 s
->condlabel
= gen_new_label();
8958 if (insn
& (1 << 11))
8959 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, s
->condlabel
);
8961 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, s
->condlabel
);
8963 offset
= ((insn
& 0xf8) >> 2) | (insn
& 0x200) >> 3;
8964 val
= (uint32_t)s
->pc
+ 2;
8969 case 15: /* IT, nop-hint. */
8970 if ((insn
& 0xf) == 0) {
8971 gen_nop_hint(s
, (insn
>> 4) & 0xf);
8975 s
->condexec_cond
= (insn
>> 4) & 0xe;
8976 s
->condexec_mask
= insn
& 0x1f;
8977 /* No actual code generated for this insn, just setup state. */
8980 case 0xe: /* bkpt */
8981 gen_exception_insn(s
, 2, EXCP_BKPT
);
8986 rn
= (insn
>> 3) & 0x7;
8988 tmp
= load_reg(s
, rn
);
8989 switch ((insn
>> 6) & 3) {
8990 case 0: tcg_gen_bswap32_i32(tmp
, tmp
); break;
8991 case 1: gen_rev16(tmp
); break;
8992 case 3: gen_revsh(tmp
); break;
8993 default: goto illegal_op
;
8995 store_reg(s
, rd
, tmp
);
9003 tmp
= tcg_const_i32((insn
& (1 << 4)) != 0);
9006 addr
= tcg_const_i32(16);
9007 gen_helper_v7m_msr(cpu_env
, addr
, tmp
);
9008 tcg_temp_free_i32(addr
);
9012 addr
= tcg_const_i32(17);
9013 gen_helper_v7m_msr(cpu_env
, addr
, tmp
);
9014 tcg_temp_free_i32(addr
);
9016 tcg_temp_free_i32(tmp
);
9019 if (insn
& (1 << 4))
9020 shift
= CPSR_A
| CPSR_I
| CPSR_F
;
9023 gen_set_psr_im(s
, ((insn
& 7) << 6), 0, shift
);
9033 /* load/store multiple */
9034 rn
= (insn
>> 8) & 0x7;
9035 addr
= load_reg(s
, rn
);
9036 for (i
= 0; i
< 8; i
++) {
9037 if (insn
& (1 << i
)) {
9038 if (insn
& (1 << 11)) {
9040 tmp
= gen_ld32(addr
, IS_USER(s
));
9041 store_reg(s
, i
, tmp
);
9044 tmp
= load_reg(s
, i
);
9045 gen_st32(tmp
, addr
, IS_USER(s
));
9047 /* advance to the next address */
9048 tcg_gen_addi_i32(addr
, addr
, 4);
9051 /* Base register writeback. */
9052 if ((insn
& (1 << rn
)) == 0) {
9053 store_reg(s
, rn
, addr
);
9060 /* conditional branch or swi */
9061 cond
= (insn
>> 8) & 0xf;
9067 gen_set_pc_im(s
->pc
);
9068 s
->is_jmp
= DISAS_SWI
;
9071 /* generate a conditional jump to next instruction */
9072 s
->condlabel
= gen_new_label();
9073 gen_test_cc(cond
^ 1, s
->condlabel
);
9076 /* jump to the offset */
9077 val
= (uint32_t)s
->pc
+ 2;
9078 offset
= ((int32_t)insn
<< 24) >> 24;
9084 if (insn
& (1 << 11)) {
9085 if (disas_thumb2_insn(env
, s
, insn
))
9089 /* unconditional branch */
9090 val
= (uint32_t)s
->pc
;
9091 offset
= ((int32_t)insn
<< 21) >> 21;
9092 val
+= (offset
<< 1) + 2;
9097 if (disas_thumb2_insn(env
, s
, insn
))
9103 gen_exception_insn(s
, 4, EXCP_UDEF
);
9107 gen_exception_insn(s
, 2, EXCP_UDEF
);
9110 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
9111 basic block 'tb'. If search_pc is TRUE, also generate PC
9112 information for each intermediate instruction. */
9113 static inline void gen_intermediate_code_internal(CPUState
*env
,
9114 TranslationBlock
*tb
,
9117 DisasContext dc1
, *dc
= &dc1
;
9119 uint16_t *gen_opc_end
;
9121 target_ulong pc_start
;
9122 uint32_t next_page_start
;
9126 /* generate intermediate code */
9133 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9135 dc
->is_jmp
= DISAS_NEXT
;
9137 dc
->singlestep_enabled
= env
->singlestep_enabled
;
9139 dc
->thumb
= ARM_TBFLAG_THUMB(tb
->flags
);
9140 dc
->condexec_mask
= (ARM_TBFLAG_CONDEXEC(tb
->flags
) & 0xf) << 1;
9141 dc
->condexec_cond
= ARM_TBFLAG_CONDEXEC(tb
->flags
) >> 4;
9142 #if !defined(CONFIG_USER_ONLY)
9143 dc
->user
= (ARM_TBFLAG_PRIV(tb
->flags
) == 0);
9145 dc
->vfp_enabled
= ARM_TBFLAG_VFPEN(tb
->flags
);
9146 dc
->vec_len
= ARM_TBFLAG_VECLEN(tb
->flags
);
9147 dc
->vec_stride
= ARM_TBFLAG_VECSTRIDE(tb
->flags
);
9148 cpu_F0s
= tcg_temp_new_i32();
9149 cpu_F1s
= tcg_temp_new_i32();
9150 cpu_F0d
= tcg_temp_new_i64();
9151 cpu_F1d
= tcg_temp_new_i64();
9154 /* FIXME: cpu_M0 can probably be the same as cpu_V0. */
9155 cpu_M0
= tcg_temp_new_i64();
9156 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
9159 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9161 max_insns
= CF_COUNT_MASK
;
9165 /* A note on handling of the condexec (IT) bits:
9167 * We want to avoid the overhead of having to write the updated condexec
9168 * bits back to the CPUState for every instruction in an IT block. So:
9169 * (1) if the condexec bits are not already zero then we write
9170 * zero back into the CPUState now. This avoids complications trying
9171 * to do it at the end of the block. (For example if we don't do this
9172 * it's hard to identify whether we can safely skip writing condexec
9173 * at the end of the TB, which we definitely want to do for the case
9174 * where a TB doesn't do anything with the IT state at all.)
9175 * (2) if we are going to leave the TB then we call gen_set_condexec()
9176 * which will write the correct value into CPUState if zero is wrong.
9177 * This is done both for leaving the TB at the end, and for leaving
9178 * it because of an exception we know will happen, which is done in
9179 * gen_exception_insn(). The latter is necessary because we need to
9180 * leave the TB with the PC/IT state just prior to execution of the
9181 * instruction which caused the exception.
9182 * (3) if we leave the TB unexpectedly (eg a data abort on a load)
9183 * then the CPUState will be wrong and we need to reset it.
9184 * This is handled in the same way as restoration of the
9185 * PC in these situations: we will be called again with search_pc=1
9186 * and generate a mapping of the condexec bits for each PC in
9187 * gen_opc_condexec_bits[]. gen_pc_load[] then uses this to restore
9188 * the condexec bits.
9190 * Note that there are no instructions which can read the condexec
9191 * bits, and none which can write non-static values to them, so
9192 * we don't need to care about whether CPUState is correct in the
9196 /* Reset the conditional execution bits immediately. This avoids
9197 complications trying to do it at the end of the block. */
9198 if (dc
->condexec_mask
|| dc
->condexec_cond
)
9200 TCGv tmp
= new_tmp();
9201 tcg_gen_movi_i32(tmp
, 0);
9202 store_cpu_field(tmp
, condexec_bits
);
9205 #ifdef CONFIG_USER_ONLY
9206 /* Intercept jump to the magic kernel page. */
9207 if (dc
->pc
>= 0xffff0000) {
9208 /* We always get here via a jump, so know we are not in a
9209 conditional execution block. */
9210 gen_exception(EXCP_KERNEL_TRAP
);
9211 dc
->is_jmp
= DISAS_UPDATE
;
9215 if (dc
->pc
>= 0xfffffff0 && IS_M(env
)) {
9216 /* We always get here via a jump, so know we are not in a
9217 conditional execution block. */
9218 gen_exception(EXCP_EXCEPTION_EXIT
);
9219 dc
->is_jmp
= DISAS_UPDATE
;
9224 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9225 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9226 if (bp
->pc
== dc
->pc
) {
9227 gen_exception_insn(dc
, 0, EXCP_DEBUG
);
9228 /* Advance PC so that clearing the breakpoint will
9229 invalidate this TB. */
9231 goto done_generating
;
9237 j
= gen_opc_ptr
- gen_opc_buf
;
9241 gen_opc_instr_start
[lj
++] = 0;
9243 gen_opc_pc
[lj
] = dc
->pc
;
9244 gen_opc_condexec_bits
[lj
] = (dc
->condexec_cond
<< 4) | (dc
->condexec_mask
>> 1);
9245 gen_opc_instr_start
[lj
] = 1;
9246 gen_opc_icount
[lj
] = num_insns
;
9249 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9252 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
))) {
9253 tcg_gen_debug_insn_start(dc
->pc
);
9257 disas_thumb_insn(env
, dc
);
9258 if (dc
->condexec_mask
) {
9259 dc
->condexec_cond
= (dc
->condexec_cond
& 0xe)
9260 | ((dc
->condexec_mask
>> 4) & 1);
9261 dc
->condexec_mask
= (dc
->condexec_mask
<< 1) & 0x1f;
9262 if (dc
->condexec_mask
== 0) {
9263 dc
->condexec_cond
= 0;
9267 disas_arm_insn(env
, dc
);
9270 fprintf(stderr
, "Internal resource leak before %08x\n", dc
->pc
);
9274 if (dc
->condjmp
&& !dc
->is_jmp
) {
9275 gen_set_label(dc
->condlabel
);
9278 /* Translation stops when a conditional branch is encountered.
9279 * Otherwise the subsequent code could get translated several times.
9280 * Also stop translation when a page boundary is reached. This
9281 * ensures prefetch aborts occur at the right place. */
9283 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
&&
9284 !env
->singlestep_enabled
&&
9286 dc
->pc
< next_page_start
&&
9287 num_insns
< max_insns
);
9289 if (tb
->cflags
& CF_LAST_IO
) {
9291 /* FIXME: This can theoretically happen with self-modifying
9293 cpu_abort(env
, "IO on conditional branch instruction");
9298 /* At this stage dc->condjmp will only be set when the skipped
9299 instruction was a conditional branch or trap, and the PC has
9300 already been written. */
9301 if (unlikely(env
->singlestep_enabled
)) {
9302 /* Make sure the pc is updated, and raise a debug exception. */
9304 gen_set_condexec(dc
);
9305 if (dc
->is_jmp
== DISAS_SWI
) {
9306 gen_exception(EXCP_SWI
);
9308 gen_exception(EXCP_DEBUG
);
9310 gen_set_label(dc
->condlabel
);
9312 if (dc
->condjmp
|| !dc
->is_jmp
) {
9313 gen_set_pc_im(dc
->pc
);
9316 gen_set_condexec(dc
);
9317 if (dc
->is_jmp
== DISAS_SWI
&& !dc
->condjmp
) {
9318 gen_exception(EXCP_SWI
);
9320 /* FIXME: Single stepping a WFI insn will not halt
9322 gen_exception(EXCP_DEBUG
);
9325 /* While branches must always occur at the end of an IT block,
9326 there are a few other things that can cause us to terminate
9327 the TB in the middel of an IT block:
9328 - Exception generating instructions (bkpt, swi, undefined).
9330 - Hardware watchpoints.
9331 Hardware breakpoints have already been handled and skip this code.
9333 gen_set_condexec(dc
);
9334 switch(dc
->is_jmp
) {
9336 gen_goto_tb(dc
, 1, dc
->pc
);
9341 /* indicate that the hash table must be used to find the next TB */
9345 /* nothing more to generate */
9351 gen_exception(EXCP_SWI
);
9355 gen_set_label(dc
->condlabel
);
9356 gen_set_condexec(dc
);
9357 gen_goto_tb(dc
, 1, dc
->pc
);
9363 gen_icount_end(tb
, num_insns
);
9364 *gen_opc_ptr
= INDEX_op_end
;
9367 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9368 qemu_log("----------------\n");
9369 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9370 log_target_disas(pc_start
, dc
->pc
- pc_start
, dc
->thumb
);
9375 j
= gen_opc_ptr
- gen_opc_buf
;
9378 gen_opc_instr_start
[lj
++] = 0;
9380 tb
->size
= dc
->pc
- pc_start
;
9381 tb
->icount
= num_insns
;
9385 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
9387 gen_intermediate_code_internal(env
, tb
, 0);
9390 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
9392 gen_intermediate_code_internal(env
, tb
, 1);
9395 static const char *cpu_mode_names
[16] = {
9396 "usr", "fiq", "irq", "svc", "???", "???", "???", "abt",
9397 "???", "???", "???", "und", "???", "???", "???", "sys"
9400 void cpu_dump_state(CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9410 /* ??? This assumes float64 and double have the same layout.
9411 Oh well, it's only debug dumps. */
9420 cpu_fprintf(f
, "R%02d=%08x", i
, env
->regs
[i
]);
9422 cpu_fprintf(f
, "\n");
9424 cpu_fprintf(f
, " ");
9426 psr
= cpsr_read(env
);
9427 cpu_fprintf(f
, "PSR=%08x %c%c%c%c %c %s%d\n",
9429 psr
& (1 << 31) ? 'N' : '-',
9430 psr
& (1 << 30) ? 'Z' : '-',
9431 psr
& (1 << 29) ? 'C' : '-',
9432 psr
& (1 << 28) ? 'V' : '-',
9433 psr
& CPSR_T
? 'T' : 'A',
9434 cpu_mode_names
[psr
& 0xf], (psr
& 0x10) ? 32 : 26);
9437 for (i
= 0; i
< 16; i
++) {
9438 d
.d
= env
->vfp
.regs
[i
];
9442 cpu_fprintf(f
, "s%02d=%08x(%8g) s%02d=%08x(%8g) d%02d=%08x%08x(%8g)\n",
9443 i
* 2, (int)s0
.i
, s0
.s
,
9444 i
* 2 + 1, (int)s1
.i
, s1
.s
,
9445 i
, (int)(uint32_t)d
.l
.upper
, (int)(uint32_t)d
.l
.lower
,
9448 cpu_fprintf(f
, "FPSCR: %08x\n", (int)env
->vfp
.xregs
[ARM_VFP_FPSCR
]);
9452 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
9453 unsigned long searched_pc
, int pc_pos
, void *puc
)
9455 env
->regs
[15] = gen_opc_pc
[pc_pos
];
9456 env
->condexec_bits
= gen_opc_condexec_bits
[pc_pos
];