From 7a6f61057b0305515bb82e6697765a7fc36cfefe Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Feb 2019 19:20:14 -0500 Subject: [PATCH] target/m68k: Correct instruction emulation Previously we weren't even initializing the instruction table, so any attempt at emulation would cause a segmentation fault. This also moves the end address check after the decoding to correctly perform exiting behavior with the new translator model. --- qemu/target/m68k/cpu.c | 3 +++ qemu/target/m68k/translate.c | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/qemu/target/m68k/cpu.c b/qemu/target/m68k/cpu.c index 55f9cd08..23809513 100644 --- a/qemu/target/m68k/cpu.c +++ b/qemu/target/m68k/cpu.c @@ -211,8 +211,11 @@ static void any_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) static int m68k_cpu_realizefn(struct uc_struct *uc, DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); + M68kCPU *cpu = M68K_CPU(uc, dev); M68kCPUClass *mcc = M68K_CPU_GET_CLASS(uc, dev); + register_m68k_insns(&cpu->env); + cpu_reset(cs); qemu_init_vcpu(cs); diff --git a/qemu/target/m68k/translate.c b/qemu/target/m68k/translate.c index dc9d00c6..bc2cdec3 100644 --- a/qemu/target/m68k/translate.c +++ b/qemu/target/m68k/translate.c @@ -6334,12 +6334,6 @@ static void m68k_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) TCGContext *tcg_ctx = env->uc->tcg_ctx; uint16_t insn = read_im16(env, dc); - // Unicorn: end address tells us to stop emulation - if (dc->pc == dc->uc->addr_end) { - gen_exception(dc, dc->pc, EXCP_HLT); - return; - } - // Unicorn: trace this instruction on request if (HOOK_EXISTS_BOUNDED(env->uc, UC_HOOK_CODE, dc->pc)) { gen_uc_tracecode(tcg_ctx, 2, UC_HOOK_CODE_IDX, env->uc, dc->pc); @@ -6353,6 +6347,12 @@ static void m68k_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) dc->base.pc_next = dc->pc; + // Unicorn: end address tells us to stop emulation + if (dc->pc == dc->uc->addr_end) { + gen_exception(dc, dc->pc, EXCP_HLT); + return; + } + if (dc->base.is_jmp == DISAS_NEXT) { /* Stop translation when the next insn might touch a new page. * This ensures that prefetch aborts at the right place.