Received: from eggs.gnu.org ([208.118.235.92]:52648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf4S0-0005t7-CG for qemu-devel@nongnu.org; Wed, 22 May 2013 04:31:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uf4Ru-0007Mi-0G for qemu-devel@nongnu.org; Wed, 22 May 2013 04:31:12 -0400 Received: from indium.canonical.com ([91.189.90.7]:41895) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf4Rt-0007MW-PY for qemu-devel@nongnu.org; Wed, 22 May 2013 04:31:05 -0400 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Uf4Rs-0007cm-QN for ; Wed, 22 May 2013 08:31:04 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id C590A2E800E for ; Wed, 22 May 2013 08:31:04 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Wed, 22 May 2013 08:22:18 -0000 From: Sebastian Huber Sender: bounces@canonical.com References: <20130521075402.636.30099.malonedeb@soybean.canonical.com> Message-Id: <20130522082218.1051.47363.malone@soybean.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 1182344] Re: ARM: invalid code execution after subs instruction Reply-To: Bug 1182344 <1182344@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org If I replace the idle thread with this code void *_CPU_Thread_Idle_body( uintptr_t ignored ) { while ( true ) { __asm__ volatile ("wfi"); } } void foobarblub(void) { __asm__ volatile ("nop; nop; nop; nop; nop"); bsp_reset(); } then I get also an invalid execution sequence: 0x00010214 : ldm r0, {r0, r1, r2, r3, r4, r5, r= 12} 0x00010218 : mov lr, r4 0x0001021c : msr SPSR_fc, r5 0x00010220 : pop {r4, r5} 0x00010224 : subs pc, lr, #4 0x00010306 <_CPU_Thread_Idle_body+10>: b.n 0x10304 <_CPU_Thread_Idle_bod= y+8> 0x00010308 : push {r7, lr} 0x0001030a : add r7, sp, #0 0x0001030c : nop 0x0001030e : nop 0x00010310 : nop 0x00010312 : nop 0x00010314 : nop 0x00010316 : bl 0xe40 Normally the execution sequence around the idle thread looks like this: 0x00010210 : push {r4, r5} 0x00010214 : ldm r0, {r0, r1, r2, r3, r4, r5, r= 12} 0x00010218 : mov lr, r4 0x0001021c : msr SPSR_fc, r5 0x00010220 : pop {r4, r5} 0x00010224 : subs pc, lr, #4 0x00010306 <_CPU_Thread_Idle_body+10>: b.n 0x10304 <_CPU_Thread_Idle_bod= y+8> 0x00010304 <_CPU_Thread_Idle_body+8>: wfi 0x00000018 : ldr pc, [pc, #24] ; 0x38 0x00010168 <_ARMV4_Exception_interrupt+0>: stmdb sp, {r4, r5, r6, r7} 0x0001016c <_ARMV4_Exception_interrupt+4>: mov r4, lr 0x00010170 <_ARMV4_Exception_interrupt+8>: mrs r5, SPSR 0x00010174 <_ARMV4_Exception_interrupt+12>: mrs r6, CPSR -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1182344 Title: ARM: invalid code execution after subs instruction Status in QEMU: New Bug description: I use Qemu (Git 1239b472bb0dba8060f1af29d40dafbc1b2860d4) to test a SMP application on ARM. I use the following command line: qemu-system-arm -S -s -net none -nographic -M realview-pbx-a9 -kernel app.exe -m 256M -no-reboot -smp 2 -icount 8 The application crashes because Qemu executes the B.N instruction wrong after a SUBS (return from interrupt): 0x00010428 : vldmia r1!, {d16-d31} 0x0001042c : ldr r0, [r1] 0x00010430 : add sp, sp, #200 ; 0xc8 0x00010434 : vmsr fpscr, r0 0x00010438 : ldmfd sp!, {lr} 0x0001043c : mov r0, sp 0x00010440 : add sp, sp, #28 0x00010444 : mrs r1, CPSR 0x00010448 : bic r1, r1, #1 0x0001044c : msr CPSR_fc, r1 0x00010450 : push {r4, r5} 0x00010454 : ldm r0, {r0, r1, r2, r3, r4, r5,= r12} 0x00010458 : mov lr, r4 0x0001045c : msr SPSR_fc, r5 0x00010460 : pop {r4, r5} 0x00010464 : subs pc, lr, #4 0x00000690 <_Thread_Idle_body+8>: b.n 0x690 <_Thread_Idle_body+8> 0x00000692: nop 0x00000694 <__getreent+0>: push {r7, lr} 0x00000696 <__getreent+2>: add r7, sp, #0 0x00000698 <__getreent+4>: bl 0x1cf0 0x00001cf0 : push {r7, lr} This instruction trace was generated with the attached patch. The 0x00000690 <_Thread_Idle_body+8>: b.n 0x690 <_Thread_Idle_body+8> should jump to itself. Instead the next instruction is executed: 0x00000692: nop To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1182344/+subscriptions