Received: from eggs.gnu.org ([2001:4830:134:3::10]:51374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJ2T4-0005Zx-Pg for qemu-devel@nongnu.org; Wed, 04 Feb 2015 11:06:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJ2Sy-0004HG-IN for qemu-devel@nongnu.org; Wed, 04 Feb 2015 11:06:18 -0500 Received: from indium.canonical.com ([91.189.90.7]:38369) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJ2Sy-0004H0-Dw for qemu-devel@nongnu.org; Wed, 04 Feb 2015 11:06:12 -0500 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.76 #1 (Debian)) id 1YJ2Sx-00005C-Lf for ; Wed, 04 Feb 2015 16:06:11 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id A26172E80AF for ; Wed, 4 Feb 2015 16:06:11 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Wed, 04 Feb 2015 15:56:20 -0000 From: Karl Zimmerman Sender: bounces@canonical.com References: <20130826101205.25802.19011.malonedeb@soybean.canonical.com> Message-Id: <20150204155620.7219.11103.malone@soybean.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 1216845] Re: qemu-system-arm semihosting always calls exit(0) Reply-To: Bug 1216845 <1216845@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Had a similar problem with my emulation environment. However, I did some inspection of the assembly code generated by newlib for ARM semi- hosting. While it initially appears that exit() and _exit() discard the status code, upon careful inspection one finds that it is pushed on the stack, with the SP pointing right to it at the point at which the SWI is executed. Thus, if the code passed to 0x18 is 0x20026, you can fetch the status code passed to exit() from the stack. -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1216845 Title: qemu-system-arm semihosting always calls exit(0) Status in QEMU: New Bug description: In my embedded ARM project I have a bunch of unit tests that I run in a POSIX synthetic environment, and, as usual for POSIX processes, these tests return 0 for success and !=3D0 for error. Now I expanded the testing environment to run some of these tests compiled for ARM, under QEMU, with the tracing messages forwarded via the semihosting API. Up to now everything is fine with the emulation. However I have a problem with passing the failure code back to the operating system, to drive the continuous integration framework. I checked the arm-semi.c code and for SYS_EXIT and I discovered that the parameter passed is ignored and it always calls exit(0): case SYS_EXIT: gdb_exit(env, 0); exit(0); To solve my problem I temporarily made a patch, and for cases that should return non zero codes, I call an unsupported BKPT instruction, which makes QEMU abort, and pass an non zero code (1) back to the operating system. qemu: Unsupported SemiHosting SWI 0xf1 This kludge is more or less functional, but is quite inconvenient. After checking the ARM manuals, I discovered that SYS_EXIT is not standard, and the 0x18 code used for it originally was used for angel_SWIreason_ReportException, which has a slightly different purpose. Now the question: Would it be possible to no longer ignore the code passed to 0x18, and if it is non zero, to call exit() with a different value? The suggested rule would be: if (code =3D=3D0 || code =3D=3D 0x20026) exit(0); elif (code < 256) exit(code); else exit(1); The value 0x20026 means ADP_Stopped_ApplicationExit, and, if I understood it right, it means that the program terminated successfully. If this is not true, it can be removed from the first conditional statement. What do you think? Can this be added to arm-semi.c? = Regards, Liviu To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1216845/+subscriptions