Skip to contentSkip to conversation

FreeRTOS Cortex M3 demo fails when doing context-switch

Qemu-devel [email protected] 1 participant 1 message Apr 19, 2008

lore
Share & tools
lore
#0 lore raw

I redid a patch that I tried to submit here on the mailinglist earlier (prev. version of patch-set was agains the cvs tree).

When FreeRTOS wants to do a context switch, it does so by playing with the stack pointer, and when creating a new thread, this fails on qemu. qemu uses even addresses internally, while the cpu that it emulates uses odd number. So this goes where wrong when the image to want to run replaces the stack with the PC it expects to return to.

Patch provided has the correct behaviour (I believe). It atleast works with the FreeRTOS Cortex M3 image.

Stian Skjelstad

helper.c +3 -1
Index: target-arm/helper.c
===================================================================
@@ -607,6 +607,8 @@
     env->regs[12] = v7m_pop(env);
     env->regs[14] = v7m_pop(env);
     env->regs[15] = v7m_pop(env);
+    if ((env->thumb = (env->regs[15]&1)) == 1)
+        env->regs[15] &= ~1;
     xpsr = v7m_pop(env);
     xpsr_write(env, xpsr, 0xfffffdff);
     /* Undo stack alignment.  */
@@ -679,7 +681,7 @@
     }
     /* Switch to the handler mode.  */
     v7m_push(env, xpsr);
-    v7m_push(env, env->regs[15]);
+    v7m_push(env, env->regs[15] | (!!env->thumb) );
     v7m_push(env, env->regs[14]);
     v7m_push(env, env->regs[12]);
     v7m_push(env, env->regs[3]);