From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXHL0-0000AE-N0 for qemu-devel@nongnu.org; Mon, 07 Apr 2014 17:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXHKv-0005ot-Or for qemu-devel@nongnu.org; Mon, 07 Apr 2014 17:44:18 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:47205 helo=smtp.eu.adacore.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXHKv-0005ok-IZ for qemu-devel@nongnu.org; Mon, 07 Apr 2014 17:44:13 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 4FE5E2720086 for ; Mon, 7 Apr 2014 23:44:11 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jkUAyhKdT_uE for ; Mon, 7 Apr 2014 23:44:11 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 324382720057 for ; Mon, 7 Apr 2014 23:44:11 +0200 (CEST) From: Eric Botcazou Date: Mon, 07 Apr 2014 23:42:34 +0200 Message-ID: <5047457.AHxDUeBxbN@polaris> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: [Qemu-devel] [PATCH] target-arm: return more meaningful exit status List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi, this partially addresses a long-standing limitation of the ARM semi-hosting mode, whereby the only exit status of the emulator is 0, whatever the exit status of the target executable, by mapping arguments of the SYS_EXIT syscall. See https://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02178.html for an earlier attempt. It's only a partial solution because EXIT_SUCCESS will be returned in all cases as before, except when the target execution is stopped with SIGABRT. But that's sufficient to run the testsuite of the compiler for bare board ARM, e.g. arm-none-eabi with newlib. Signed-off-by: Eric Botcazou --- target-arm/arm-semi.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-) diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c index ebb5235..dd6c2d9 100644 --- a/target-arm/arm-semi.c +++ b/target-arm/arm-semi.c @@ -58,6 +58,9 @@ #define TARGET_SYS_HEAPINFO 0x16 #define TARGET_SYS_EXIT 0x18 +#define ADP_Stopped_ApplicationExit ((2 << 16) + 38) +#define ADP_Stopped_RunTimeError ((2 << 16) + 35) + #ifndef O_BINARY #define O_BINARY 0 #endif @@ -551,8 +554,24 @@ uint32_t do_arm_semihosting(CPUARMState *env) return 0; } case TARGET_SYS_EXIT: - gdb_exit(env, 0); - exit(0); + { + int code; + + switch (args) { + case ADP_Stopped_ApplicationExit: + code = EXIT_SUCCESS; + break; + case ADP_Stopped_RunTimeError: + code = EXIT_FAILURE; + break; + default: + code = -EXIT_FAILURE; + break; + } + + gdb_exit(env, code); + exit(code); + } default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, fprintf, 0); -- 1.7.7 -- Eric Botcazou