From 15440a83c54f098cbae7ddaf0923fa71c1c0606d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Feb 2019 18:49:18 -0500 Subject: [PATCH] target/arm: Fix execution of ARM instructions Previously we'd be checking prior to the actual decoding if we were at the ending address. This worked fine using the old model of the translation process in qemu. However, this causes the wrong behavior to occur in both ARM and Thumb/Thumb-2 modes using the newer translator model. Given the translator itself checks for the end address already, this needs to be placed within arm_post_translate_insn(). This prevents the emulation process being off-by-one as well when it comes to actually executing the instructions. --- qemu/target/arm/translate.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/qemu/target/arm/translate.c b/qemu/target/arm/translate.c index 72ededee..e635e13c 100644 --- a/qemu/target/arm/translate.c +++ b/qemu/target/arm/translate.c @@ -12595,13 +12595,6 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn) TCGv_i32 tmp2; TCGv_i32 addr; - // Unicorn: end address tells us to stop emulation - if (s->pc == s->uc->addr_end) { - // imitate WFI instruction to halt emulation - s->base.is_jmp = DISAS_WFI; - return; - } - // Unicorn: trace this instruction on request if (HOOK_EXISTS_BOUNDED(s->uc, UC_HOOK_CODE, s->pc)) { // determine instruction size (Thumb/Thumb2) @@ -13666,6 +13659,13 @@ static void arm_post_translate_insn(DisasContext *dc) { TCGContext *tcg_ctx = dc->uc->tcg_ctx; + // Unicorn: end address tells us to stop emulation + if (dc->pc == dc->uc->addr_end) { + // imitate WFI instruction to halt emulation + dc->base.is_jmp = DISAS_WFI; + return; + } + if (dc->condjmp && !dc->base.is_jmp) { gen_set_label(tcg_ctx, dc->condlabel); dc->condjmp = 0;