Skip to contentSkip to conversation

pass ARM semihosting exit code back to system

PATCH Superseded Liviu Ionescu 2 participants 4 messages Nov 18, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pass ARM semihosting exit code back to system

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.

Liviu Ionescu (1):
pass semihosting exit code back to system

 target-arm/arm-semi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3 (Apple Git-50)
#1 lore raw

PATCH 1/1 pass semihosting exit code back to system

---
 target-arm/arm-semi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
target-arm/arm-semi.c +10 -2
index ebb5235..4b982ad 100644
@@ -58,6 +58,11 @@
 #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     ((2 << 16) + 38)
+#define ADP_Stopped_RunTimeError        ((2 << 16) + 35)
+
 #ifndef O_BINARY
 #define O_BINARY 0
 #endif
@@ -551,8 +556,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);
Signature · 1 line
1.9.3 (Apple Git-50)
#2 lore raw

Re: [Qemu-devel] [PATCH] pass semihosting exit code back to system

Quoted 10 lines · Liviu Ionescu
---
 target-arm/arm-semi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
target-arm/arm-semi.c +0 -0
index ebb5235..4b982ad 100644

target-arm/arm-semi.c line 64

Quoted 7 lines
target-arm/arm-semi.c +4 -0
@@ -58,6 +58,11 @@
 #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     ((2 << 16) + 38)
+#define ADP_Stopped_RunTimeError        ((2 << 16) + 35)

The ARM documentation seems to define this value as 0x20026 rather than with a shift-and-decimal-value, so I'd rather follow that. Otherwise this patch looks good.

Again, I can take the patch into my queue and fix this nit as I do so, or you can reroll if you'd rather do it yourself.

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH] pass semihosting exit code back to system

Quoted 3 lines · Peter Maydell

The ARM documentation seems to define this value as 0x20026 rather than with a shift-and-decimal-value, so I'd rather follow that.

right, I changed it and resent.

regards,

Liviu