4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 #include "translate.h"
29 #include "qemu/host-utils.h"
31 #include "exec/gen-icount.h"
37 static TCGv_i64 cpu_X
[32];
38 static TCGv_i64 cpu_pc
;
39 static TCGv_i32 cpu_NF
, cpu_ZF
, cpu_CF
, cpu_VF
;
41 static const char *regnames
[] = {
42 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
43 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
44 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
45 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
49 A64_SHIFT_TYPE_LSL
= 0,
50 A64_SHIFT_TYPE_LSR
= 1,
51 A64_SHIFT_TYPE_ASR
= 2,
52 A64_SHIFT_TYPE_ROR
= 3
55 /* initialize TCG globals. */
56 void a64_translate_init(void)
60 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
61 offsetof(CPUARMState
, pc
),
63 for (i
= 0; i
< 32; i
++) {
64 cpu_X
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
65 offsetof(CPUARMState
, xregs
[i
]),
69 cpu_NF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, NF
), "NF");
70 cpu_ZF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, ZF
), "ZF");
71 cpu_CF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, CF
), "CF");
72 cpu_VF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, VF
), "VF");
75 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
76 fprintf_function cpu_fprintf
, int flags
)
78 ARMCPU
*cpu
= ARM_CPU(cs
);
79 CPUARMState
*env
= &cpu
->env
;
80 uint32_t psr
= pstate_read(env
);
83 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
84 env
->pc
, env
->xregs
[31]);
85 for (i
= 0; i
< 31; i
++) {
86 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
93 cpu_fprintf(f
, "PSTATE=%08x (flags %c%c%c%c)\n",
95 psr
& PSTATE_N
? 'N' : '-',
96 psr
& PSTATE_Z
? 'Z' : '-',
97 psr
& PSTATE_C
? 'C' : '-',
98 psr
& PSTATE_V
? 'V' : '-');
102 static int get_mem_index(DisasContext
*s
)
104 #ifdef CONFIG_USER_ONLY
111 void gen_a64_set_pc_im(uint64_t val
)
113 tcg_gen_movi_i64(cpu_pc
, val
);
116 static void gen_exception(int excp
)
118 TCGv_i32 tmp
= tcg_temp_new_i32();
119 tcg_gen_movi_i32(tmp
, excp
);
120 gen_helper_exception(cpu_env
, tmp
);
121 tcg_temp_free_i32(tmp
);
124 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
)
126 gen_a64_set_pc_im(s
->pc
- offset
);
128 s
->is_jmp
= DISAS_EXC
;
131 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
133 /* No direct tb linking with singlestep or deterministic io */
134 if (s
->singlestep_enabled
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
138 /* Only link tbs from inside the same guest page */
139 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
146 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
148 TranslationBlock
*tb
;
151 if (use_goto_tb(s
, n
, dest
)) {
153 gen_a64_set_pc_im(dest
);
154 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
155 s
->is_jmp
= DISAS_TB_JUMP
;
157 gen_a64_set_pc_im(dest
);
158 if (s
->singlestep_enabled
) {
159 gen_exception(EXCP_DEBUG
);
162 s
->is_jmp
= DISAS_JUMP
;
166 static void unallocated_encoding(DisasContext
*s
)
168 gen_exception_insn(s
, 4, EXCP_UDEF
);
171 #define unsupported_encoding(s, insn) \
173 qemu_log_mask(LOG_UNIMP, \
174 "%s:%d: unsupported instruction encoding 0x%08x " \
175 "at pc=%016" PRIx64 "\n", \
176 __FILE__, __LINE__, insn, s->pc - 4); \
177 unallocated_encoding(s); \
180 static void init_tmp_a64_array(DisasContext
*s
)
182 #ifdef CONFIG_DEBUG_TCG
184 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
185 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
188 s
->tmp_a64_count
= 0;
191 static void free_tmp_a64(DisasContext
*s
)
194 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
195 tcg_temp_free_i64(s
->tmp_a64
[i
]);
197 init_tmp_a64_array(s
);
200 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
202 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
203 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
206 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
208 TCGv_i64 t
= new_tmp_a64(s
);
209 tcg_gen_movi_i64(t
, 0);
214 * Register access functions
216 * These functions are used for directly accessing a register in where
217 * changes to the final register value are likely to be made. If you
218 * need to use a register for temporary calculation (e.g. index type
219 * operations) use the read_* form.
221 * B1.2.1 Register mappings
223 * In instruction register encoding 31 can refer to ZR (zero register) or
224 * the SP (stack pointer) depending on context. In QEMU's case we map SP
225 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
226 * This is the point of the _sp forms.
228 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
231 return new_tmp_a64_zero(s
);
237 /* register access for when 31 == SP */
238 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
243 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
244 * representing the register contents. This TCGv is an auto-freed
245 * temporary so it need not be explicitly freed, and may be modified.
247 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
249 TCGv_i64 v
= new_tmp_a64(s
);
252 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
254 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
257 tcg_gen_movi_i64(v
, 0);
262 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
264 TCGv_i64 v
= new_tmp_a64(s
);
266 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
268 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
273 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
274 * than the 32 bit equivalent.
276 static inline void gen_set_NZ64(TCGv_i64 result
)
278 TCGv_i64 flag
= tcg_temp_new_i64();
280 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
281 tcg_gen_trunc_i64_i32(cpu_ZF
, flag
);
282 tcg_gen_shri_i64(flag
, result
, 32);
283 tcg_gen_trunc_i64_i32(cpu_NF
, flag
);
284 tcg_temp_free_i64(flag
);
287 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
288 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
291 gen_set_NZ64(result
);
293 tcg_gen_trunc_i64_i32(cpu_ZF
, result
);
294 tcg_gen_trunc_i64_i32(cpu_NF
, result
);
296 tcg_gen_movi_i32(cpu_CF
, 0);
297 tcg_gen_movi_i32(cpu_VF
, 0);
301 * Load/Store generators
305 * Store from GPR register to memory
307 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
308 TCGv_i64 tcg_addr
, int size
)
311 tcg_gen_qemu_st_i64(source
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
315 * Load from memory to GPR register
317 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
318 int size
, bool is_signed
, bool extend
)
320 TCGMemOp memop
= MO_TE
+ size
;
328 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, get_mem_index(s
), memop
);
330 if (extend
&& is_signed
) {
332 tcg_gen_ext32u_i64(dest
, dest
);
337 * Store from FP register to memory
339 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
341 /* This writes the bottom N bits of a 128 bit wide vector to memory */
342 int freg_offs
= offsetof(CPUARMState
, vfp
.regs
[srcidx
* 2]);
343 TCGv_i64 tmp
= tcg_temp_new_i64();
348 tcg_gen_ld8u_i64(tmp
, cpu_env
, freg_offs
);
351 tcg_gen_ld16u_i64(tmp
, cpu_env
, freg_offs
);
354 tcg_gen_ld32u_i64(tmp
, cpu_env
, freg_offs
);
357 tcg_gen_ld_i64(tmp
, cpu_env
, freg_offs
);
360 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
362 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
363 tcg_gen_ld_i64(tmp
, cpu_env
, freg_offs
);
364 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
365 tcg_gen_qemu_st64(tmp
, tcg_addr
, get_mem_index(s
));
366 tcg_gen_ld_i64(tmp
, cpu_env
, freg_offs
+ sizeof(float64
));
367 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
368 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
369 tcg_temp_free_i64(tcg_hiaddr
);
372 tcg_temp_free_i64(tmp
);
376 * Load from memory to FP register
378 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
380 /* This always zero-extends and writes to a full 128 bit wide vector */
381 int freg_offs
= offsetof(CPUARMState
, vfp
.regs
[destidx
* 2]);
382 TCGv_i64 tmplo
= tcg_temp_new_i64();
386 TCGMemOp memop
= MO_TE
+ size
;
387 tmphi
= tcg_const_i64(0);
388 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
391 tmphi
= tcg_temp_new_i64();
392 tcg_hiaddr
= tcg_temp_new_i64();
394 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
395 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
396 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
397 tcg_temp_free_i64(tcg_hiaddr
);
400 tcg_gen_st_i64(tmplo
, cpu_env
, freg_offs
);
401 tcg_gen_st_i64(tmphi
, cpu_env
, freg_offs
+ sizeof(float64
));
403 tcg_temp_free_i64(tmplo
);
404 tcg_temp_free_i64(tmphi
);
408 * This utility function is for doing register extension with an
409 * optional shift. You will likely want to pass a temporary for the
410 * destination register. See DecodeRegExtend() in the ARM ARM.
412 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
413 int option
, unsigned int shift
)
415 int extsize
= extract32(option
, 0, 2);
416 bool is_signed
= extract32(option
, 2, 1);
421 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
424 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
427 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
430 tcg_gen_mov_i64(tcg_out
, tcg_in
);
436 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
439 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
442 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
445 tcg_gen_mov_i64(tcg_out
, tcg_in
);
451 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
455 static inline void gen_check_sp_alignment(DisasContext
*s
)
457 /* The AArch64 architecture mandates that (if enabled via PSTATE
458 * or SCTLR bits) there is a check that SP is 16-aligned on every
459 * SP-relative load or store (with an exception generated if it is not).
460 * In line with general QEMU practice regarding misaligned accesses,
461 * we omit these checks for the sake of guest program performance.
462 * This function is provided as a hook so we can more easily add these
463 * checks in future (possibly as a "favour catching guest program bugs
464 * over speed" user selectable option).
469 * the instruction disassembly implemented here matches
470 * the instruction encoding classifications in chapter 3 (C3)
471 * of the ARM Architecture Reference Manual (DDI0487A_a)
474 /* C3.2.7 Unconditional branch (immediate)
476 * +----+-----------+-------------------------------------+
477 * | op | 0 0 1 0 1 | imm26 |
478 * +----+-----------+-------------------------------------+
480 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
482 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
484 if (insn
& (1 << 31)) {
485 /* C5.6.26 BL Branch with link */
486 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
489 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
490 gen_goto_tb(s
, 0, addr
);
493 /* C3.2.1 Compare & branch (immediate)
494 * 31 30 25 24 23 5 4 0
495 * +----+-------------+----+---------------------+--------+
496 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
497 * +----+-------------+----+---------------------+--------+
499 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
501 unsigned int sf
, op
, rt
;
506 sf
= extract32(insn
, 31, 1);
507 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
508 rt
= extract32(insn
, 0, 5);
509 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
511 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
512 label_match
= gen_new_label();
514 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
515 tcg_cmp
, 0, label_match
);
517 gen_goto_tb(s
, 0, s
->pc
);
518 gen_set_label(label_match
);
519 gen_goto_tb(s
, 1, addr
);
522 /* C3.2.5 Test & branch (immediate)
523 * 31 30 25 24 23 19 18 5 4 0
524 * +----+-------------+----+-------+-------------+------+
525 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
526 * +----+-------------+----+-------+-------------+------+
528 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
530 unsigned int bit_pos
, op
, rt
;
535 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
536 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
537 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
538 rt
= extract32(insn
, 0, 5);
540 tcg_cmp
= tcg_temp_new_i64();
541 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
542 label_match
= gen_new_label();
543 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
544 tcg_cmp
, 0, label_match
);
545 tcg_temp_free_i64(tcg_cmp
);
546 gen_goto_tb(s
, 0, s
->pc
);
547 gen_set_label(label_match
);
548 gen_goto_tb(s
, 1, addr
);
551 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
552 * 31 25 24 23 5 4 3 0
553 * +---------------+----+---------------------+----+------+
554 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
555 * +---------------+----+---------------------+----+------+
557 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
562 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
563 unallocated_encoding(s
);
566 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
567 cond
= extract32(insn
, 0, 4);
570 /* genuinely conditional branches */
571 int label_match
= gen_new_label();
572 arm_gen_test_cc(cond
, label_match
);
573 gen_goto_tb(s
, 0, s
->pc
);
574 gen_set_label(label_match
);
575 gen_goto_tb(s
, 1, addr
);
577 /* 0xe and 0xf are both "always" conditions */
578 gen_goto_tb(s
, 0, addr
);
583 static void handle_hint(DisasContext
*s
, uint32_t insn
,
584 unsigned int op1
, unsigned int op2
, unsigned int crm
)
586 unsigned int selector
= crm
<< 3 | op2
;
589 unallocated_encoding(s
);
601 /* we treat all as NOP at least for now */
604 /* default specified as NOP equivalent */
609 /* CLREX, DSB, DMB, ISB */
610 static void handle_sync(DisasContext
*s
, uint32_t insn
,
611 unsigned int op1
, unsigned int op2
, unsigned int crm
)
614 unallocated_encoding(s
);
620 unsupported_encoding(s
, insn
);
625 /* We don't emulate caches so barriers are no-ops */
628 unallocated_encoding(s
);
633 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
634 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
635 unsigned int op1
, unsigned int op2
, unsigned int crm
)
637 unsupported_encoding(s
, insn
);
641 static void handle_sys(DisasContext
*s
, uint32_t insn
, unsigned int l
,
642 unsigned int op1
, unsigned int op2
,
643 unsigned int crn
, unsigned int crm
, unsigned int rt
)
645 unsupported_encoding(s
, insn
);
648 /* C5.6.129 MRS - move from system register */
649 static void handle_mrs(DisasContext
*s
, uint32_t insn
, unsigned int op0
,
650 unsigned int op1
, unsigned int op2
,
651 unsigned int crn
, unsigned int crm
, unsigned int rt
)
653 unsupported_encoding(s
, insn
);
656 /* C5.6.131 MSR (register) - move to system register */
657 static void handle_msr(DisasContext
*s
, uint32_t insn
, unsigned int op0
,
658 unsigned int op1
, unsigned int op2
,
659 unsigned int crn
, unsigned int crm
, unsigned int rt
)
661 unsupported_encoding(s
, insn
);
665 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
666 * +---------------------+---+-----+-----+-------+-------+-----+------+
667 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
668 * +---------------------+---+-----+-----+-------+-------+-----+------+
670 static void disas_system(DisasContext
*s
, uint32_t insn
)
672 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
673 l
= extract32(insn
, 21, 1);
674 op0
= extract32(insn
, 19, 2);
675 op1
= extract32(insn
, 16, 3);
676 crn
= extract32(insn
, 12, 4);
677 crm
= extract32(insn
, 8, 4);
678 op2
= extract32(insn
, 5, 3);
679 rt
= extract32(insn
, 0, 5);
683 unallocated_encoding(s
);
687 case 2: /* C5.6.68 HINT */
688 handle_hint(s
, insn
, op1
, op2
, crm
);
690 case 3: /* CLREX, DSB, DMB, ISB */
691 handle_sync(s
, insn
, op1
, op2
, crm
);
693 case 4: /* C5.6.130 MSR (immediate) */
694 handle_msr_i(s
, insn
, op1
, op2
, crm
);
697 unallocated_encoding(s
);
705 handle_sys(s
, insn
, l
, op1
, op2
, crn
, crm
, rt
);
706 } else if (l
) { /* op0 > 1 */
707 /* C5.6.129 MRS - move from system register */
708 handle_mrs(s
, insn
, op0
, op1
, op2
, crn
, crm
, rt
);
710 /* C5.6.131 MSR (register) - move to system register */
711 handle_msr(s
, insn
, op0
, op1
, op2
, crn
, crm
, rt
);
715 /* Exception generation */
716 static void disas_exc(DisasContext
*s
, uint32_t insn
)
718 unsupported_encoding(s
, insn
);
721 /* C3.2.7 Unconditional branch (register)
722 * 31 25 24 21 20 16 15 10 9 5 4 0
723 * +---------------+-------+-------+-------+------+-------+
724 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
725 * +---------------+-------+-------+-------+------+-------+
727 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
729 unsigned int opc
, op2
, op3
, rn
, op4
;
731 opc
= extract32(insn
, 21, 4);
732 op2
= extract32(insn
, 16, 5);
733 op3
= extract32(insn
, 10, 6);
734 rn
= extract32(insn
, 5, 5);
735 op4
= extract32(insn
, 0, 5);
737 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
738 unallocated_encoding(s
);
747 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
752 unallocated_encoding(s
);
754 unsupported_encoding(s
, insn
);
758 unallocated_encoding(s
);
762 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
763 s
->is_jmp
= DISAS_JUMP
;
766 /* C3.2 Branches, exception generating and system instructions */
767 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
769 switch (extract32(insn
, 25, 7)) {
770 case 0x0a: case 0x0b:
771 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
772 disas_uncond_b_imm(s
, insn
);
774 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
775 disas_comp_b_imm(s
, insn
);
777 case 0x1b: case 0x5b: /* Test & branch (immediate) */
778 disas_test_b_imm(s
, insn
);
780 case 0x2a: /* Conditional branch (immediate) */
781 disas_cond_b_imm(s
, insn
);
783 case 0x6a: /* Exception generation / System */
784 if (insn
& (1 << 24)) {
785 disas_system(s
, insn
);
790 case 0x6b: /* Unconditional branch (register) */
791 disas_uncond_b_reg(s
, insn
);
794 unallocated_encoding(s
);
799 /* Load/store exclusive */
800 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
802 unsupported_encoding(s
, insn
);
805 /* Load register (literal) */
806 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
808 unsupported_encoding(s
, insn
);
812 * C5.6.80 LDNP (Load Pair - non-temporal hint)
813 * C5.6.81 LDP (Load Pair - non vector)
814 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
815 * C5.6.176 STNP (Store Pair - non-temporal hint)
816 * C5.6.177 STP (Store Pair - non vector)
817 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
818 * C6.3.165 LDP (Load Pair of SIMD&FP)
819 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
820 * C6.3.284 STP (Store Pair of SIMD&FP)
822 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
823 * +-----+-------+---+---+-------+---+-----------------------------+
824 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
825 * +-----+-------+---+---+-------+---+-------+-------+------+------+
827 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
829 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
830 * V: 0 -> GPR, 1 -> Vector
831 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
832 * 10 -> signed offset, 11 -> pre-index
833 * L: 0 -> Store 1 -> Load
835 * Rt, Rt2 = GPR or SIMD registers to be stored
836 * Rn = general purpose register containing address
837 * imm7 = signed offset (multiple of 4 or 8 depending on size)
839 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
841 int rt
= extract32(insn
, 0, 5);
842 int rn
= extract32(insn
, 5, 5);
843 int rt2
= extract32(insn
, 10, 5);
844 int64_t offset
= sextract32(insn
, 15, 7);
845 int index
= extract32(insn
, 23, 2);
846 bool is_vector
= extract32(insn
, 26, 1);
847 bool is_load
= extract32(insn
, 22, 1);
848 int opc
= extract32(insn
, 30, 2);
850 bool is_signed
= false;
851 bool postindex
= false;
854 TCGv_i64 tcg_addr
; /* calculated address */
858 unallocated_encoding(s
);
865 size
= 2 + extract32(opc
, 1, 1);
866 is_signed
= extract32(opc
, 0, 1);
867 if (!is_load
&& is_signed
) {
868 unallocated_encoding(s
);
874 case 1: /* post-index */
879 /* signed offset with "non-temporal" hint. Since we don't emulate
880 * caches we don't care about hints to the cache system about
881 * data access patterns, and handle this identically to plain
885 /* There is no non-temporal-hint version of LDPSW */
886 unallocated_encoding(s
);
891 case 2: /* signed offset, rn not updated */
894 case 3: /* pre-index */
903 gen_check_sp_alignment(s
);
906 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
909 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
914 do_fp_ld(s
, rt
, tcg_addr
, size
);
916 do_fp_st(s
, rt
, tcg_addr
, size
);
919 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
921 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
923 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
926 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
929 do_fp_ld(s
, rt2
, tcg_addr
, size
);
931 do_fp_st(s
, rt2
, tcg_addr
, size
);
934 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
936 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
938 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
944 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
946 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
948 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
953 * C3.3.10 Load/store (register offset)
955 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
956 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
957 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
958 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
961 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
962 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
964 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
965 * opc<0>: 0 -> store, 1 -> load
966 * V: 1 -> vector/simd
967 * opt: extend encoding (see DecodeRegExtend)
968 * S: if S=1 then scale (essentially index by sizeof(size))
969 * Rt: register to transfer into/out of
970 * Rn: address register or SP for base
971 * Rm: offset register or ZR for offset
973 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
975 int rt
= extract32(insn
, 0, 5);
976 int rn
= extract32(insn
, 5, 5);
977 int shift
= extract32(insn
, 12, 1);
978 int rm
= extract32(insn
, 16, 5);
979 int opc
= extract32(insn
, 22, 2);
980 int opt
= extract32(insn
, 13, 3);
981 int size
= extract32(insn
, 30, 2);
982 bool is_signed
= false;
983 bool is_store
= false;
984 bool is_extended
= false;
985 bool is_vector
= extract32(insn
, 26, 1);
990 if (extract32(opt
, 1, 1) == 0) {
991 unallocated_encoding(s
);
996 size
|= (opc
& 2) << 1;
998 unallocated_encoding(s
);
1001 is_store
= !extract32(opc
, 0, 1);
1003 if (size
== 3 && opc
== 2) {
1004 /* PRFM - prefetch */
1007 if (opc
== 3 && size
> 1) {
1008 unallocated_encoding(s
);
1011 is_store
= (opc
== 0);
1012 is_signed
= extract32(opc
, 1, 1);
1013 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
1017 gen_check_sp_alignment(s
);
1019 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1021 tcg_rm
= read_cpu_reg(s
, rm
, 1);
1022 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
1024 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
1028 do_fp_st(s
, rt
, tcg_addr
, size
);
1030 do_fp_ld(s
, rt
, tcg_addr
, size
);
1033 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1035 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1037 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
1043 * C3.3.13 Load/store (unsigned immediate)
1045 * 31 30 29 27 26 25 24 23 22 21 10 9 5
1046 * +----+-------+---+-----+-----+------------+-------+------+
1047 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
1048 * +----+-------+---+-----+-----+------------+-------+------+
1051 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
1052 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
1054 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
1055 * opc<0>: 0 -> store, 1 -> load
1056 * Rn: base address register (inc SP)
1057 * Rt: target register
1059 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
1061 int rt
= extract32(insn
, 0, 5);
1062 int rn
= extract32(insn
, 5, 5);
1063 unsigned int imm12
= extract32(insn
, 10, 12);
1064 bool is_vector
= extract32(insn
, 26, 1);
1065 int size
= extract32(insn
, 30, 2);
1066 int opc
= extract32(insn
, 22, 2);
1067 unsigned int offset
;
1072 bool is_signed
= false;
1073 bool is_extended
= false;
1076 size
|= (opc
& 2) << 1;
1078 unallocated_encoding(s
);
1081 is_store
= !extract32(opc
, 0, 1);
1083 if (size
== 3 && opc
== 2) {
1084 /* PRFM - prefetch */
1087 if (opc
== 3 && size
> 1) {
1088 unallocated_encoding(s
);
1091 is_store
= (opc
== 0);
1092 is_signed
= extract32(opc
, 1, 1);
1093 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
1097 gen_check_sp_alignment(s
);
1099 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1100 offset
= imm12
<< size
;
1101 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
1105 do_fp_st(s
, rt
, tcg_addr
, size
);
1107 do_fp_ld(s
, rt
, tcg_addr
, size
);
1110 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1112 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1114 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
1119 /* Load/store register (all forms) */
1120 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
1122 switch (extract32(insn
, 24, 2)) {
1124 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
1125 disas_ldst_reg_roffset(s
, insn
);
1127 unsupported_encoding(s
, insn
);
1131 disas_ldst_reg_unsigned_imm(s
, insn
);
1134 unallocated_encoding(s
);
1139 /* AdvSIMD load/store multiple structures */
1140 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
1142 unsupported_encoding(s
, insn
);
1145 /* AdvSIMD load/store single structure */
1146 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
1148 unsupported_encoding(s
, insn
);
1151 /* C3.3 Loads and stores */
1152 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
1154 switch (extract32(insn
, 24, 6)) {
1155 case 0x08: /* Load/store exclusive */
1156 disas_ldst_excl(s
, insn
);
1158 case 0x18: case 0x1c: /* Load register (literal) */
1159 disas_ld_lit(s
, insn
);
1161 case 0x28: case 0x29:
1162 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
1163 disas_ldst_pair(s
, insn
);
1165 case 0x38: case 0x39:
1166 case 0x3c: case 0x3d: /* Load/store register (all forms) */
1167 disas_ldst_reg(s
, insn
);
1169 case 0x0c: /* AdvSIMD load/store multiple structures */
1170 disas_ldst_multiple_struct(s
, insn
);
1172 case 0x0d: /* AdvSIMD load/store single structure */
1173 disas_ldst_single_struct(s
, insn
);
1176 unallocated_encoding(s
);
1181 /* C3.4.6 PC-rel. addressing
1182 * 31 30 29 28 24 23 5 4 0
1183 * +----+-------+-----------+-------------------+------+
1184 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
1185 * +----+-------+-----------+-------------------+------+
1187 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
1189 unsigned int page
, rd
;
1193 page
= extract32(insn
, 31, 1);
1194 /* SignExtend(immhi:immlo) -> offset */
1195 offset
= ((int64_t)sextract32(insn
, 5, 19) << 2) | extract32(insn
, 29, 2);
1196 rd
= extract32(insn
, 0, 5);
1200 /* ADRP (page based) */
1205 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
1208 /* Add/subtract (immediate) */
1209 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
1211 unsupported_encoding(s
, insn
);
1214 /* The input should be a value in the bottom e bits (with higher
1215 * bits zero); returns that value replicated into every element
1216 * of size e in a 64 bit integer.
1218 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
1228 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
1229 static inline uint64_t bitmask64(unsigned int length
)
1231 assert(length
> 0 && length
<= 64);
1232 return ~0ULL >> (64 - length
);
1235 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
1236 * only require the wmask. Returns false if the imms/immr/immn are a reserved
1237 * value (ie should cause a guest UNDEF exception), and true if they are
1238 * valid, in which case the decoded bit pattern is written to result.
1240 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
1241 unsigned int imms
, unsigned int immr
)
1244 unsigned e
, levels
, s
, r
;
1247 assert(immn
< 2 && imms
< 64 && immr
< 64);
1249 /* The bit patterns we create here are 64 bit patterns which
1250 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
1251 * 64 bits each. Each element contains the same value: a run
1252 * of between 1 and e-1 non-zero bits, rotated within the
1253 * element by between 0 and e-1 bits.
1255 * The element size and run length are encoded into immn (1 bit)
1256 * and imms (6 bits) as follows:
1257 * 64 bit elements: immn = 1, imms = <length of run - 1>
1258 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
1259 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
1260 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
1261 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
1262 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
1263 * Notice that immn = 0, imms = 11111x is the only combination
1264 * not covered by one of the above options; this is reserved.
1265 * Further, <length of run - 1> all-ones is a reserved pattern.
1267 * In all cases the rotation is by immr % e (and immr is 6 bits).
1270 /* First determine the element size */
1271 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
1273 /* This is the immn == 0, imms == 0x11111x case */
1283 /* <length of run - 1> mustn't be all-ones. */
1287 /* Create the value of one element: s+1 set bits rotated
1288 * by r within the element (which is e bits wide)...
1290 mask
= bitmask64(s
+ 1);
1291 mask
= (mask
>> r
) | (mask
<< (e
- r
));
1292 /* ...then replicate the element over the whole 64 bit value */
1293 mask
= bitfield_replicate(mask
, e
);
1298 /* C3.4.4 Logical (immediate)
1299 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
1300 * +----+-----+-------------+---+------+------+------+------+
1301 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
1302 * +----+-----+-------------+---+------+------+------+------+
1304 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
1306 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
1307 TCGv_i64 tcg_rd
, tcg_rn
;
1309 bool is_and
= false;
1311 sf
= extract32(insn
, 31, 1);
1312 opc
= extract32(insn
, 29, 2);
1313 is_n
= extract32(insn
, 22, 1);
1314 immr
= extract32(insn
, 16, 6);
1315 imms
= extract32(insn
, 10, 6);
1316 rn
= extract32(insn
, 5, 5);
1317 rd
= extract32(insn
, 0, 5);
1320 unallocated_encoding(s
);
1324 if (opc
== 0x3) { /* ANDS */
1325 tcg_rd
= cpu_reg(s
, rd
);
1327 tcg_rd
= cpu_reg_sp(s
, rd
);
1329 tcg_rn
= cpu_reg(s
, rn
);
1331 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
1332 /* some immediate field values are reserved */
1333 unallocated_encoding(s
);
1338 wmask
&= 0xffffffff;
1342 case 0x3: /* ANDS */
1344 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
1348 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
1351 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
1354 assert(FALSE
); /* must handle all above */
1358 if (!sf
&& !is_and
) {
1359 /* zero extend final result; we know we can skip this for AND
1360 * since the immediate had the high 32 bits clear.
1362 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1365 if (opc
== 3) { /* ANDS */
1366 gen_logic_CC(sf
, tcg_rd
);
1370 /* Move wide (immediate) */
1371 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
1373 unsupported_encoding(s
, insn
);
1377 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
1378 * +----+-----+-------------+---+------+------+------+------+
1379 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
1380 * +----+-----+-------------+---+------+------+------+------+
1382 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
1384 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
1385 TCGv_i64 tcg_rd
, tcg_tmp
;
1387 sf
= extract32(insn
, 31, 1);
1388 opc
= extract32(insn
, 29, 2);
1389 n
= extract32(insn
, 22, 1);
1390 ri
= extract32(insn
, 16, 6);
1391 si
= extract32(insn
, 10, 6);
1392 rn
= extract32(insn
, 5, 5);
1393 rd
= extract32(insn
, 0, 5);
1394 bitsize
= sf
? 64 : 32;
1396 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
1397 unallocated_encoding(s
);
1401 tcg_rd
= cpu_reg(s
, rd
);
1402 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
1404 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
1406 if (opc
!= 1) { /* SBFM or UBFM */
1407 tcg_gen_movi_i64(tcg_rd
, 0);
1410 /* do the bit move operation */
1412 /* Wd<s-r:0> = Wn<s:r> */
1413 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
1415 len
= (si
- ri
) + 1;
1417 /* Wd<32+s-r,32-r> = Wn<s:0> */
1422 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
1424 if (opc
== 0) { /* SBFM - sign extend the destination field */
1425 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
1426 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
1429 if (!sf
) { /* zero extend final result */
1430 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1435 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
1436 * +----+------+-------------+---+----+------+--------+------+------+
1437 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
1438 * +----+------+-------------+---+----+------+--------+------+------+
1440 static void disas_extract(DisasContext
*s
, uint32_t insn
)
1442 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
1444 sf
= extract32(insn
, 31, 1);
1445 n
= extract32(insn
, 22, 1);
1446 rm
= extract32(insn
, 16, 5);
1447 imm
= extract32(insn
, 10, 6);
1448 rn
= extract32(insn
, 5, 5);
1449 rd
= extract32(insn
, 0, 5);
1450 op21
= extract32(insn
, 29, 2);
1451 op0
= extract32(insn
, 21, 1);
1452 bitsize
= sf
? 64 : 32;
1454 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
1455 unallocated_encoding(s
);
1457 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
1459 tcg_rd
= cpu_reg(s
, rd
);
1462 /* OPTME: we can special case rm==rn as a rotate */
1463 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
1464 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
1465 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
1466 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
1467 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
1469 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1472 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
1473 * so an extract from bit 0 is a special case.
1476 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
1478 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
1485 /* C3.4 Data processing - immediate */
1486 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
1488 switch (extract32(insn
, 23, 6)) {
1489 case 0x20: case 0x21: /* PC-rel. addressing */
1490 disas_pc_rel_adr(s
, insn
);
1492 case 0x22: case 0x23: /* Add/subtract (immediate) */
1493 disas_add_sub_imm(s
, insn
);
1495 case 0x24: /* Logical (immediate) */
1496 disas_logic_imm(s
, insn
);
1498 case 0x25: /* Move wide (immediate) */
1499 disas_movw_imm(s
, insn
);
1501 case 0x26: /* Bitfield */
1502 disas_bitfield(s
, insn
);
1504 case 0x27: /* Extract */
1505 disas_extract(s
, insn
);
1508 unallocated_encoding(s
);
1513 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
1514 * Note that it is the caller's responsibility to ensure that the
1515 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
1516 * mandated semantics for out of range shifts.
1518 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
1519 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
1521 switch (shift_type
) {
1522 case A64_SHIFT_TYPE_LSL
:
1523 tcg_gen_shl_i64(dst
, src
, shift_amount
);
1525 case A64_SHIFT_TYPE_LSR
:
1526 tcg_gen_shr_i64(dst
, src
, shift_amount
);
1528 case A64_SHIFT_TYPE_ASR
:
1530 tcg_gen_ext32s_i64(dst
, src
);
1532 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
1534 case A64_SHIFT_TYPE_ROR
:
1536 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
1539 t0
= tcg_temp_new_i32();
1540 t1
= tcg_temp_new_i32();
1541 tcg_gen_trunc_i64_i32(t0
, src
);
1542 tcg_gen_trunc_i64_i32(t1
, shift_amount
);
1543 tcg_gen_rotr_i32(t0
, t0
, t1
);
1544 tcg_gen_extu_i32_i64(dst
, t0
);
1545 tcg_temp_free_i32(t0
);
1546 tcg_temp_free_i32(t1
);
1550 assert(FALSE
); /* all shift types should be handled */
1554 if (!sf
) { /* zero extend final result */
1555 tcg_gen_ext32u_i64(dst
, dst
);
1559 /* Shift a TCGv src by immediate, put result in dst.
1560 * The shift amount must be in range (this should always be true as the
1561 * relevant instructions will UNDEF on bad shift immediates).
1563 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
1564 enum a64_shift_type shift_type
, unsigned int shift_i
)
1566 assert(shift_i
< (sf
? 64 : 32));
1569 tcg_gen_mov_i64(dst
, src
);
1571 TCGv_i64 shift_const
;
1573 shift_const
= tcg_const_i64(shift_i
);
1574 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
1575 tcg_temp_free_i64(shift_const
);
1579 /* C3.5.10 Logical (shifted register)
1580 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
1581 * +----+-----+-----------+-------+---+------+--------+------+------+
1582 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
1583 * +----+-----+-----------+-------+---+------+--------+------+------+
1585 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
1587 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
1588 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
1590 sf
= extract32(insn
, 31, 1);
1591 opc
= extract32(insn
, 29, 2);
1592 shift_type
= extract32(insn
, 22, 2);
1593 invert
= extract32(insn
, 21, 1);
1594 rm
= extract32(insn
, 16, 5);
1595 shift_amount
= extract32(insn
, 10, 6);
1596 rn
= extract32(insn
, 5, 5);
1597 rd
= extract32(insn
, 0, 5);
1599 if (!sf
&& (shift_amount
& (1 << 5))) {
1600 unallocated_encoding(s
);
1604 tcg_rd
= cpu_reg(s
, rd
);
1606 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
1607 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
1608 * register-register MOV and MVN, so it is worth special casing.
1610 tcg_rm
= cpu_reg(s
, rm
);
1612 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
1614 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1618 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
1620 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
1626 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
1629 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
1632 tcg_rn
= cpu_reg(s
, rn
);
1634 switch (opc
| (invert
<< 2)) {
1637 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
1640 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
1643 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
1647 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
1650 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
1653 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
1661 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1665 gen_logic_CC(sf
, tcg_rd
);
1669 /* Add/subtract (extended register) */
1670 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
1672 unsupported_encoding(s
, insn
);
1675 /* Add/subtract (shifted register) */
1676 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
1678 unsupported_encoding(s
, insn
);
1681 /* Data-processing (3 source) */
1682 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
1684 unsupported_encoding(s
, insn
);
1687 /* Add/subtract (with carry) */
1688 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
1690 unsupported_encoding(s
, insn
);
1693 /* Conditional compare (immediate) */
1694 static void disas_cc_imm(DisasContext
*s
, uint32_t insn
)
1696 unsupported_encoding(s
, insn
);
1699 /* Conditional compare (register) */
1700 static void disas_cc_reg(DisasContext
*s
, uint32_t insn
)
1702 unsupported_encoding(s
, insn
);
1705 /* C3.5.6 Conditional select
1706 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
1707 * +----+----+---+-----------------+------+------+-----+------+------+
1708 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
1709 * +----+----+---+-----------------+------+------+-----+------+------+
1711 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
1713 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
1714 TCGv_i64 tcg_rd
, tcg_src
;
1716 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
1717 /* S == 1 or op2<1> == 1 */
1718 unallocated_encoding(s
);
1721 sf
= extract32(insn
, 31, 1);
1722 else_inv
= extract32(insn
, 30, 1);
1723 rm
= extract32(insn
, 16, 5);
1724 cond
= extract32(insn
, 12, 4);
1725 else_inc
= extract32(insn
, 10, 1);
1726 rn
= extract32(insn
, 5, 5);
1727 rd
= extract32(insn
, 0, 5);
1730 /* silly no-op write; until we use movcond we must special-case
1731 * this to avoid a dead temporary across basic blocks.
1736 tcg_rd
= cpu_reg(s
, rd
);
1738 if (cond
>= 0x0e) { /* condition "always" */
1739 tcg_src
= read_cpu_reg(s
, rn
, sf
);
1740 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
1742 /* OPTME: we could use movcond here, at the cost of duplicating
1743 * a lot of the arm_gen_test_cc() logic.
1745 int label_match
= gen_new_label();
1746 int label_continue
= gen_new_label();
1748 arm_gen_test_cc(cond
, label_match
);
1750 tcg_src
= cpu_reg(s
, rm
);
1752 if (else_inv
&& else_inc
) {
1753 tcg_gen_neg_i64(tcg_rd
, tcg_src
);
1754 } else if (else_inv
) {
1755 tcg_gen_not_i64(tcg_rd
, tcg_src
);
1756 } else if (else_inc
) {
1757 tcg_gen_addi_i64(tcg_rd
, tcg_src
, 1);
1759 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
1762 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1764 tcg_gen_br(label_continue
);
1766 gen_set_label(label_match
);
1767 tcg_src
= read_cpu_reg(s
, rn
, sf
);
1768 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
1770 gen_set_label(label_continue
);
1774 static void handle_clz(DisasContext
*s
, unsigned int sf
,
1775 unsigned int rn
, unsigned int rd
)
1777 TCGv_i64 tcg_rd
, tcg_rn
;
1778 tcg_rd
= cpu_reg(s
, rd
);
1779 tcg_rn
= cpu_reg(s
, rn
);
1782 gen_helper_clz64(tcg_rd
, tcg_rn
);
1784 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
1785 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
1786 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
1787 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
1788 tcg_temp_free_i32(tcg_tmp32
);
1792 static void handle_cls(DisasContext
*s
, unsigned int sf
,
1793 unsigned int rn
, unsigned int rd
)
1795 TCGv_i64 tcg_rd
, tcg_rn
;
1796 tcg_rd
= cpu_reg(s
, rd
);
1797 tcg_rn
= cpu_reg(s
, rn
);
1800 gen_helper_cls64(tcg_rd
, tcg_rn
);
1802 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
1803 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
1804 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
1805 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
1806 tcg_temp_free_i32(tcg_tmp32
);
1810 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
1811 unsigned int rn
, unsigned int rd
)
1813 TCGv_i64 tcg_rd
, tcg_rn
;
1814 tcg_rd
= cpu_reg(s
, rd
);
1815 tcg_rn
= cpu_reg(s
, rn
);
1818 gen_helper_rbit64(tcg_rd
, tcg_rn
);
1820 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
1821 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
1822 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
1823 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
1824 tcg_temp_free_i32(tcg_tmp32
);
1828 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
1829 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
1830 unsigned int rn
, unsigned int rd
)
1833 unallocated_encoding(s
);
1836 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
1839 /* C5.6.149 REV with sf==0, opcode==2
1840 * C5.6.151 REV32 (sf==1, opcode==2)
1842 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
1843 unsigned int rn
, unsigned int rd
)
1845 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
1848 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1849 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
1851 /* bswap32_i64 requires zero high word */
1852 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
1853 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
1854 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
1855 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
1856 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
1858 tcg_temp_free_i64(tcg_tmp
);
1860 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
1861 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
1865 /* C5.6.150 REV16 (opcode==1) */
1866 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
1867 unsigned int rn
, unsigned int rd
)
1869 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
1870 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1871 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
1873 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
1874 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
1876 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
1877 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
1878 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
1879 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
1882 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
1883 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
1884 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
1885 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
1887 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
1888 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
1889 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
1892 tcg_temp_free_i64(tcg_tmp
);
1895 /* C3.5.7 Data-processing (1 source)
1896 * 31 30 29 28 21 20 16 15 10 9 5 4 0
1897 * +----+---+---+-----------------+---------+--------+------+------+
1898 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
1899 * +----+---+---+-----------------+---------+--------+------+------+
1901 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
1903 unsigned int sf
, opcode
, rn
, rd
;
1905 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
1906 unallocated_encoding(s
);
1910 sf
= extract32(insn
, 31, 1);
1911 opcode
= extract32(insn
, 10, 6);
1912 rn
= extract32(insn
, 5, 5);
1913 rd
= extract32(insn
, 0, 5);
1917 handle_rbit(s
, sf
, rn
, rd
);
1920 handle_rev16(s
, sf
, rn
, rd
);
1923 handle_rev32(s
, sf
, rn
, rd
);
1926 handle_rev64(s
, sf
, rn
, rd
);
1929 handle_clz(s
, sf
, rn
, rd
);
1932 handle_cls(s
, sf
, rn
, rd
);
1937 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
1938 unsigned int rm
, unsigned int rn
, unsigned int rd
)
1940 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
1941 tcg_rd
= cpu_reg(s
, rd
);
1943 if (!sf
&& is_signed
) {
1944 tcg_n
= new_tmp_a64(s
);
1945 tcg_m
= new_tmp_a64(s
);
1946 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
1947 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
1949 tcg_n
= read_cpu_reg(s
, rn
, sf
);
1950 tcg_m
= read_cpu_reg(s
, rm
, sf
);
1954 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
1956 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
1959 if (!sf
) { /* zero extend final result */
1960 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
1964 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
1965 static void handle_shift_reg(DisasContext
*s
,
1966 enum a64_shift_type shift_type
, unsigned int sf
,
1967 unsigned int rm
, unsigned int rn
, unsigned int rd
)
1969 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
1970 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
1971 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
1973 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
1974 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
1975 tcg_temp_free_i64(tcg_shift
);
1978 /* C3.5.8 Data-processing (2 source)
1979 * 31 30 29 28 21 20 16 15 10 9 5 4 0
1980 * +----+---+---+-----------------+------+--------+------+------+
1981 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
1982 * +----+---+---+-----------------+------+--------+------+------+
1984 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
1986 unsigned int sf
, rm
, opcode
, rn
, rd
;
1987 sf
= extract32(insn
, 31, 1);
1988 rm
= extract32(insn
, 16, 5);
1989 opcode
= extract32(insn
, 10, 6);
1990 rn
= extract32(insn
, 5, 5);
1991 rd
= extract32(insn
, 0, 5);
1993 if (extract32(insn
, 29, 1)) {
1994 unallocated_encoding(s
);
2000 handle_div(s
, false, sf
, rm
, rn
, rd
);
2003 handle_div(s
, true, sf
, rm
, rn
, rd
);
2006 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
2009 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
2012 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
2015 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
2024 case 23: /* CRC32 */
2025 unsupported_encoding(s
, insn
);
2028 unallocated_encoding(s
);
2033 /* C3.5 Data processing - register */
2034 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
2036 switch (extract32(insn
, 24, 5)) {
2037 case 0x0a: /* Logical (shifted register) */
2038 disas_logic_reg(s
, insn
);
2040 case 0x0b: /* Add/subtract */
2041 if (insn
& (1 << 21)) { /* (extended register) */
2042 disas_add_sub_ext_reg(s
, insn
);
2044 disas_add_sub_reg(s
, insn
);
2047 case 0x1b: /* Data-processing (3 source) */
2048 disas_data_proc_3src(s
, insn
);
2051 switch (extract32(insn
, 21, 3)) {
2052 case 0x0: /* Add/subtract (with carry) */
2053 disas_adc_sbc(s
, insn
);
2055 case 0x2: /* Conditional compare */
2056 if (insn
& (1 << 11)) { /* (immediate) */
2057 disas_cc_imm(s
, insn
);
2058 } else { /* (register) */
2059 disas_cc_reg(s
, insn
);
2062 case 0x4: /* Conditional select */
2063 disas_cond_select(s
, insn
);
2065 case 0x6: /* Data-processing */
2066 if (insn
& (1 << 30)) { /* (1 source) */
2067 disas_data_proc_1src(s
, insn
);
2068 } else { /* (2 source) */
2069 disas_data_proc_2src(s
, insn
);
2073 unallocated_encoding(s
);
2078 unallocated_encoding(s
);
2083 /* C3.6 Data processing - SIMD and floating point */
2084 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
2086 unsupported_encoding(s
, insn
);
2089 /* C3.1 A64 instruction index by encoding */
2090 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
2094 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
2098 switch (extract32(insn
, 25, 4)) {
2099 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
2100 unallocated_encoding(s
);
2102 case 0x8: case 0x9: /* Data processing - immediate */
2103 disas_data_proc_imm(s
, insn
);
2105 case 0xa: case 0xb: /* Branch, exception generation and system insns */
2106 disas_b_exc_sys(s
, insn
);
2111 case 0xe: /* Loads and stores */
2112 disas_ldst(s
, insn
);
2115 case 0xd: /* Data processing - register */
2116 disas_data_proc_reg(s
, insn
);
2119 case 0xf: /* Data processing - SIMD and floating point */
2120 disas_data_proc_simd_fp(s
, insn
);
2123 assert(FALSE
); /* all 15 cases should be handled above */
2127 /* if we allocated any temporaries, free them here */
2131 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
2132 TranslationBlock
*tb
,
2135 CPUState
*cs
= CPU(cpu
);
2136 CPUARMState
*env
= &cpu
->env
;
2137 DisasContext dc1
, *dc
= &dc1
;
2139 uint16_t *gen_opc_end
;
2141 target_ulong pc_start
;
2142 target_ulong next_page_start
;
2150 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2152 dc
->is_jmp
= DISAS_NEXT
;
2154 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
2160 dc
->condexec_mask
= 0;
2161 dc
->condexec_cond
= 0;
2162 #if !defined(CONFIG_USER_ONLY)
2165 dc
->vfp_enabled
= 0;
2169 init_tmp_a64_array(dc
);
2171 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2174 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2175 if (max_insns
== 0) {
2176 max_insns
= CF_COUNT_MASK
;
2181 tcg_clear_temp_count();
2184 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2185 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2186 if (bp
->pc
== dc
->pc
) {
2187 gen_exception_insn(dc
, 0, EXCP_DEBUG
);
2188 /* Advance PC so that clearing the breakpoint will
2189 invalidate this TB. */
2191 goto done_generating
;
2197 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2201 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2204 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
2205 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2206 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
2209 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2213 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2214 tcg_gen_debug_insn_start(dc
->pc
);
2217 disas_a64_insn(env
, dc
);
2219 if (tcg_check_temp_count()) {
2220 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
2224 /* Translation stops when a conditional branch is encountered.
2225 * Otherwise the subsequent code could get translated several times.
2226 * Also stop translation when a page boundary is reached. This
2227 * ensures prefetch aborts occur at the right place.
2230 } while (!dc
->is_jmp
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
&&
2231 !cs
->singlestep_enabled
&&
2233 dc
->pc
< next_page_start
&&
2234 num_insns
< max_insns
);
2236 if (tb
->cflags
& CF_LAST_IO
) {
2240 if (unlikely(cs
->singlestep_enabled
) && dc
->is_jmp
!= DISAS_EXC
) {
2241 /* Note that this means single stepping WFI doesn't halt the CPU.
2242 * For conditional branch insns this is harmless unreachable code as
2243 * gen_goto_tb() has already handled emitting the debug exception
2244 * (and thus a tb-jump is not possible when singlestepping).
2246 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
2247 if (dc
->is_jmp
!= DISAS_JUMP
) {
2248 gen_a64_set_pc_im(dc
->pc
);
2250 gen_exception(EXCP_DEBUG
);
2252 switch (dc
->is_jmp
) {
2254 gen_goto_tb(dc
, 1, dc
->pc
);
2259 /* indicate that the hash table must be used to find the next TB */
2267 /* This is a special case because we don't want to just halt the CPU
2268 * if trying to debug across a WFI.
2270 gen_helper_wfi(cpu_env
);
2276 gen_tb_end(tb
, num_insns
);
2277 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
2280 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2281 qemu_log("----------------\n");
2282 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2283 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
2284 dc
->thumb
| (dc
->bswap_code
<< 1));
2289 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2292 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2295 tb
->size
= dc
->pc
- pc_start
;
2296 tb
->icount
= num_insns
;