Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JnM8e-0000aE-Hv for qemu-devel@nongnu.org; Sat, 19 Apr 2008 19:06:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JnM8b-0000YC-MN for qemu-devel@nongnu.org; Sat, 19 Apr 2008 19:06:31 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JnM8b-0000Xc-El for qemu-devel@nongnu.org; Sat, 19 Apr 2008 19:06:29 -0400 Received: from [195.159.99.196] (helo=nepa.nlc.no) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JnM8a-0002D9-Tz for qemu-devel@nongnu.org; Sat, 19 Apr 2008 19:06:29 -0400 Message-ID: <25448.84.48.218.113.1208628994.squirrel@nepa.nlc.no> Date: Sat, 19 Apr 2008 20:16:34 +0200 (CEST) From: stian@nixia.no MIME-Version: 1.0 Content-Type: multipart/mixed;boundary="----=_20080419201634_54506" Subject: [Qemu-devel] FreeRTOS Cortex M3 demo fails when doing context-switch Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers ------=_20080419201634_54506 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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 ------=_20080419201634_54506 Content-Type: text/x-diff; name="qemu-svn-freertos-cortex-m3-pushpop-thumb2.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="qemu-svn-freertos-cortex-m3-pushpop-thumb2.patch" Index: target-arm/helper.c =================================================================== --- target-arm/helper.c (revision 4220) +++ target-arm/helper.c (working copy) @@ -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]); ------=_20080419201634_54506--