]> Git Repo - qemu.git/commitdiff
target-arm: Ignore low bit of PC in M-profile exception return
authorPeter Maydell <[email protected]>
Mon, 16 Mar 2015 12:30:47 +0000 (12:30 +0000)
committerPeter Maydell <[email protected]>
Mon, 16 Mar 2015 12:30:47 +0000 (12:30 +0000)
For the ARM M-profile cores, exception return pops various registers
including the PC from the stack. The architecture defines that if the
lowest bit in the new PC value is set (ie the PC is not halfword
aligned) then behaviour is UNPREDICTABLE. In practice hardware
implementations seem to simply ignore the low bit, and some buggy
RTOSes incorrectly rely on this. QEMU's behaviour was architecturally
permitted, but bringing QEMU into line with the hardware behaviour
allows more guest code to run. We log the situation as a guest error.

This was reported as LP:1428657.

Reported-by: Anders Esbensen <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
target-arm/helper.c

index 7fe3d14773068ac5bf184e543f0dd2afc0ad3f0d..10886c52811108b036e2bbfd4c2b97a8b7ee8479 100644 (file)
@@ -4334,6 +4334,16 @@ static void do_v7m_exception_exit(CPUARMState *env)
     env->regs[12] = v7m_pop(env);
     env->regs[14] = v7m_pop(env);
     env->regs[15] = v7m_pop(env);
+    if (env->regs[15] & 1) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "M profile return from interrupt with misaligned "
+                      "PC is UNPREDICTABLE\n");
+        /* Actual hardware seems to ignore the lsbit, and there are several
+         * RTOSes out there which incorrectly assume the r15 in the stack
+         * frame should be a Thumb-style "lsbit indicates ARM/Thumb" value.
+         */
+        env->regs[15] &= ~1U;
+    }
     xpsr = v7m_pop(env);
     xpsr_write(env, xpsr, 0xfffffdff);
     /* Undo stack alignment.  */
This page took 0.042918 seconds and 4 git commands to generate.