From patchwork Tue Nov 18 20:01:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Ionescu X-Patchwork-Id: 412152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B6C021400F4 for ; Wed, 19 Nov 2014 07:02:25 +1100 (AEDT) Received: from localhost ([::1]:55113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xqoyk-0007qx-Lp for incoming@patchwork.ozlabs.org; Tue, 18 Nov 2014 15:02:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqoyP-0007Vq-Na for qemu-devel@nongnu.org; Tue, 18 Nov 2014 15:02:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqoyK-0003QN-Kh for qemu-devel@nongnu.org; Tue, 18 Nov 2014 15:02:01 -0500 Received: from [109.99.239.84] (port=37928 helo=ilg-mbp.local) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqoyK-0003QJ-Dp for qemu-devel@nongnu.org; Tue, 18 Nov 2014 15:01:56 -0500 Received: by ilg-mbp.local (Postfix, from userid 501) id 7C0612E06B39; Tue, 18 Nov 2014 22:01:47 +0200 (EET) From: Liviu Ionescu To: qemu-devel@nongnu.org Date: Tue, 18 Nov 2014 22:01:29 +0200 Message-Id: <1416340889-4991-1-git-send-email-ilg@livius.net> X-Mailer: git-send-email 1.9.3 (Apple Git-50) X-detected-operating-system: by eggs.gnu.org: iOS iPhone or iPad X-Received-From: 109.99.239.84 Cc: peter.maydell@linaro.org, ilg@livius.net Subject: [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In order to run unit tests under semihosting, it is necessary to pass the application exit code back to the system. ARM defines only the code to be used for non-error application exit (ADP_Stopped_ApplicationExit), all other codes should return non-zero exit codes. This patch checks if the application code passed via TARGET_SYS_EXIT is ADP_Stopped_ApplicationExit, and return 0, otherwise return 1. Signed-off-by: Liviu Ionescu --- target-arm/arm-semi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c index ebb5235..a8b83e6 100644 --- a/target-arm/arm-semi.c +++ b/target-arm/arm-semi.c @@ -58,6 +58,10 @@ #define TARGET_SYS_HEAPINFO 0x16 #define TARGET_SYS_EXIT 0x18 +/* ADP_Stopped_ApplicationExit is used for exit(0), + * anything else is implemented as exit(1) */ +#define ADP_Stopped_ApplicationExit (0x20026) + #ifndef O_BINARY #define O_BINARY 0 #endif @@ -551,8 +555,11 @@ uint32_t do_arm_semihosting(CPUARMState *env) return 0; } case TARGET_SYS_EXIT: - gdb_exit(env, 0); - exit(0); + /* ARM specifies only Stopped_ApplicationExit as normal + * exit, everything else is considered an error */ + ret = (args == ADP_Stopped_ApplicationExit) ? 0 : 1; + gdb_exit(env, ret); + exit(ret); default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, fprintf, 0);