target/arm: Split out thumb_tr_translate_insn

We need not check for ARM vs Thumb state in order to dispatch
disassembly of every instruction.

Tested-by: Emilio G. Cota <cota@braap.org>
Reviewed-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
This commit is contained in:
Richard Henderson 2017-07-14 12:29:07 -10:00 committed by Richard Henderson
parent f7708456aa
commit 722ef0a562
1 changed files with 80 additions and 41 deletions

View File

@ -11981,11 +11981,8 @@ static bool arm_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
return true; return true;
} }
static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) static bool arm_pre_translate_insn(DisasContext *dc)
{ {
DisasContext *dc = container_of(dcbase, DisasContext, base);
CPUARMState *env = cpu->env_ptr;
#ifdef CONFIG_USER_ONLY #ifdef CONFIG_USER_ONLY
/* Intercept jump to the magic kernel page. */ /* Intercept jump to the magic kernel page. */
if (dc->pc >= 0xffff0000) { if (dc->pc >= 0xffff0000) {
@ -11993,7 +11990,7 @@ static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
conditional execution block. */ conditional execution block. */
gen_exception_internal(EXCP_KERNEL_TRAP); gen_exception_internal(EXCP_KERNEL_TRAP);
dc->base.is_jmp = DISAS_NORETURN; dc->base.is_jmp = DISAS_NORETURN;
return; return true;
} }
#endif #endif
@ -12012,56 +12009,85 @@ static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0), gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0),
default_exception_el(dc)); default_exception_el(dc));
dc->base.is_jmp = DISAS_NORETURN; dc->base.is_jmp = DISAS_NORETURN;
return; return true;
} }
if (dc->thumb) { return false;
disas_thumb_insn(env, dc); }
if (dc->condexec_mask) {
dc->condexec_cond = (dc->condexec_cond & 0xe)
| ((dc->condexec_mask >> 4) & 1);
dc->condexec_mask = (dc->condexec_mask << 1) & 0x1f;
if (dc->condexec_mask == 0) {
dc->condexec_cond = 0;
}
}
} else {
unsigned int insn = arm_ldl_code(env, dc->pc, dc->sctlr_b);
dc->pc += 4;
disas_arm_insn(dc, insn);
}
static void arm_post_translate_insn(CPUARMState *env, DisasContext *dc)
{
if (dc->condjmp && !dc->base.is_jmp) { if (dc->condjmp && !dc->base.is_jmp) {
gen_set_label(dc->condlabel); gen_set_label(dc->condlabel);
dc->condjmp = 0; dc->condjmp = 0;
} }
if (dc->base.is_jmp == DISAS_NEXT) { /* Translation stops when a conditional branch is encountered.
/* Translation stops when a conditional branch is encountered. * Otherwise the subsequent code could get translated several times.
* Otherwise the subsequent code could get translated several times. * Also stop translation when a page boundary is reached. This
* Also stop translation when a page boundary is reached. This * ensures prefetch aborts occur at the right place.
* ensures prefetch aborts occur at the right place. */ *
* We want to stop the TB if the next insn starts in a new page,
if (dc->pc >= dc->next_page_start || * or if it spans between this page and the next. This means that
(dc->pc >= dc->next_page_start - 3 && * if we're looking at the last halfword in the page we need to
insn_crosses_page(env, dc))) { * see if it's a 16-bit Thumb insn (which will fit in this TB)
/* We want to stop the TB if the next insn starts in a new page, * or a 32-bit Thumb insn (which won't).
* or if it spans between this page and the next. This means that * This is to avoid generating a silly TB with a single 16-bit insn
* if we're looking at the last halfword in the page we need to * in it at the end of this page (which would execute correctly
* see if it's a 16-bit Thumb insn (which will fit in this TB) * but isn't very efficient).
* or a 32-bit Thumb insn (which won't). */
* This is to avoid generating a silly TB with a single 16-bit insn if (dc->base.is_jmp == DISAS_NEXT
* in it at the end of this page (which would execute correctly && (dc->pc >= dc->next_page_start
* but isn't very efficient). || (dc->pc >= dc->next_page_start - 3
*/ && insn_crosses_page(env, dc)))) {
dc->base.is_jmp = DISAS_TOO_MANY; dc->base.is_jmp = DISAS_TOO_MANY;
}
} }
dc->base.pc_next = dc->pc; dc->base.pc_next = dc->pc;
translator_loop_temp_check(&dc->base); translator_loop_temp_check(&dc->base);
} }
static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
{
DisasContext *dc = container_of(dcbase, DisasContext, base);
CPUARMState *env = cpu->env_ptr;
unsigned int insn;
if (arm_pre_translate_insn(dc)) {
return;
}
insn = arm_ldl_code(env, dc->pc, dc->sctlr_b);
dc->pc += 4;
disas_arm_insn(dc, insn);
arm_post_translate_insn(env, dc);
}
static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
{
DisasContext *dc = container_of(dcbase, DisasContext, base);
CPUARMState *env = cpu->env_ptr;
if (arm_pre_translate_insn(dc)) {
return;
}
disas_thumb_insn(env, dc);
/* Advance the Thumb condexec condition. */
if (dc->condexec_mask) {
dc->condexec_cond = ((dc->condexec_cond & 0xe) |
((dc->condexec_mask >> 4) & 1));
dc->condexec_mask = (dc->condexec_mask << 1) & 0x1f;
if (dc->condexec_mask == 0) {
dc->condexec_cond = 0;
}
}
arm_post_translate_insn(env, dc);
}
static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
{ {
DisasContext *dc = container_of(dcbase, DisasContext, base); DisasContext *dc = container_of(dcbase, DisasContext, base);
@ -12198,12 +12224,25 @@ static const TranslatorOps arm_translator_ops = {
.disas_log = arm_tr_disas_log, .disas_log = arm_tr_disas_log,
}; };
static const TranslatorOps thumb_translator_ops = {
.init_disas_context = arm_tr_init_disas_context,
.tb_start = arm_tr_tb_start,
.insn_start = arm_tr_insn_start,
.breakpoint_check = arm_tr_breakpoint_check,
.translate_insn = thumb_tr_translate_insn,
.tb_stop = arm_tr_tb_stop,
.disas_log = arm_tr_disas_log,
};
/* generate intermediate code for basic block 'tb'. */ /* generate intermediate code for basic block 'tb'. */
void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb) void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb)
{ {
DisasContext dc; DisasContext dc;
const TranslatorOps *ops = &arm_translator_ops; const TranslatorOps *ops = &arm_translator_ops;
if (ARM_TBFLAG_THUMB(tb->flags)) {
ops = &thumb_translator_ops;
}
#ifdef TARGET_AARCH64 #ifdef TARGET_AARCH64
if (ARM_TBFLAG_AARCH64_STATE(tb->flags)) { if (ARM_TBFLAG_AARCH64_STATE(tb->flags)) {
ops = &aarch64_translator_ops; ops = &aarch64_translator_ops;