Pass 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.

Signed-off-by: Liviu Ionescu <ilg@livius.net>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Liviu Ionescu 2014-12-11 12:07:48 +00:00 committed by Peter Maydell
parent a09f2d16f6
commit 1ecc3a2df1

View File

@ -58,6 +58,10 @@
#define TARGET_SYS_HEAPINFO 0x16 #define TARGET_SYS_HEAPINFO 0x16
#define TARGET_SYS_EXIT 0x18 #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 #ifndef O_BINARY
#define O_BINARY 0 #define O_BINARY 0
#endif #endif
@ -551,8 +555,11 @@ uint32_t do_arm_semihosting(CPUARMState *env)
return 0; return 0;
} }
case TARGET_SYS_EXIT: case TARGET_SYS_EXIT:
gdb_exit(env, 0); /* ARM specifies only Stopped_ApplicationExit as normal
exit(0); * exit, everything else is considered an error */
ret = (args == ADP_Stopped_ApplicationExit) ? 0 : 1;
gdb_exit(env, ret);
exit(ret);
default: default:
fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
cpu_dump_state(cs, stderr, fprintf, 0); cpu_dump_state(cs, stderr, fprintf, 0);