]> git.proxmox.com Git - mirror_qemu.git/commitdiff
target/arm: Assert thumb pc is aligned
authorRichard Henderson <richard.henderson@linaro.org>
Wed, 3 Nov 2021 04:03:50 +0000 (00:03 -0400)
committerPeter Maydell <peter.maydell@linaro.org>
Wed, 15 Dec 2021 10:35:26 +0000 (10:35 +0000)
Misaligned thumb PC is architecturally impossible.
Assert is better than proceeding, in case we've missed
something somewhere.

Expand a comment about aligning the pc in gdbstub.
Fail an incoming migrate if a thumb pc is misaligned.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
target/arm/gdbstub.c
target/arm/machine.c
target/arm/translate.c

index 134da0d0ae3f8ee464ef48d0e4738e123060752d..ca1de47511601d600223cae5e82d9674ebd083bb 100644 (file)
@@ -77,8 +77,13 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 
     tmp = ldl_p(mem_buf);
 
-    /* Mask out low bit of PC to workaround gdb bugs.  This will probably
-       cause problems if we ever implement the Jazelle DBX extensions.  */
+    /*
+     * Mask out low bits of PC to workaround gdb bugs.
+     * This avoids an assert in thumb_tr_translate_insn, because it is
+     * architecturally impossible to misalign the pc.
+     * This will probably cause problems if we ever implement the
+     * Jazelle DBX extensions.
+     */
     if (n == 15) {
         tmp &= ~1;
     }
index c74d8c3f4b37dceadc8dfb4389f823ff7fb2992e..135d2420b5c9308481effebfcc7967157bb76cfa 100644 (file)
@@ -794,6 +794,16 @@ static int cpu_post_load(void *opaque, int version_id)
             return -1;
         }
     }
+
+    /*
+     * Misaligned thumb pc is architecturally impossible.
+     * We have an assert in thumb_tr_translate_insn to verify this.
+     * Fail an incoming migrate to avoid this assert.
+     */
+    if (!is_a64(env) && env->thumb && (env->regs[15] & 1)) {
+        return -1;
+    }
+
     if (!kvm_enabled()) {
         pmu_op_finish(&cpu->env);
     }
index 45917c3a6d2ce69ace456fea5ced25bff7b4411c..0a3840d227fff43f7f04745a7f7538e8132c591a 100644 (file)
@@ -9646,6 +9646,9 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
     uint32_t insn;
     bool is_16bit;
 
+    /* Misaligned thumb PC is architecturally impossible. */
+    assert((dc->base.pc_next & 1) == 0);
+
     if (arm_check_ss_active(dc) || arm_check_kernelpage(dc)) {
         dc->base.pc_next = pc + 2;
         return;