* [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system.
@ 2014-11-18 20:01 Liviu Ionescu
2014-11-18 20:08 ` Peter Maydell
0 siblings, 1 reply; 6+ messages in thread
From: Liviu Ionescu @ 2014-11-18 20:01 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, ilg
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>
---
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);
--
1.9.3 (Apple Git-50)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system.
2014-11-18 20:01 [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system Liviu Ionescu
@ 2014-11-18 20:08 ` Peter Maydell
2014-11-18 21:19 ` Paolo Bonzini
0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2014-11-18 20:08 UTC (permalink / raw)
To: Liviu Ionescu; +Cc: QEMU Developers
On 18 November 2014 20:01, Liviu Ionescu <ilg@livius.net> wrote:
> 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>
Applied to target-arm.next, thanks.
(That's
https://git.linaro.org/people/peter.maydell/qemu-arm.git target-arm.next
which is a *rebasing* branch.)
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system.
2014-11-18 20:08 ` Peter Maydell
@ 2014-11-18 21:19 ` Paolo Bonzini
2014-11-18 21:43 ` Liviu Ionescu
2014-11-18 22:50 ` Peter Maydell
0 siblings, 2 replies; 6+ messages in thread
From: Paolo Bonzini @ 2014-11-18 21:19 UTC (permalink / raw)
To: Peter Maydell, Liviu Ionescu; +Cc: QEMU Developers
On 18/11/2014 21:08, Peter Maydell wrote:
> Applied to target-arm.next, thanks.
> (That's
> https://git.linaro.org/people/peter.maydell/qemu-arm.git target-arm.next
> which is a *rebasing* branch.)
The isa-debugexit and testdev character device do not exit with exitcode
0, in order to distinguish an exit from a system power down; the
low-order bit is always 1. The return values then should be 1 and 3
instead of 0 and 1.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system.
2014-11-18 21:19 ` Paolo Bonzini
@ 2014-11-18 21:43 ` Liviu Ionescu
2014-11-18 22:50 ` Peter Maydell
1 sibling, 0 replies; 6+ messages in thread
From: Liviu Ionescu @ 2014-11-18 21:43 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Peter Maydell, QEMU Developers
On 18 Nov 2014, at 23:19, Paolo Bonzini <pbonzini@redhat.com> wrote:
> The isa-debugexit and testdev character device do not exit with exitcode
> 0, in order to distinguish an exit from a system power down; the
> low-order bit is always 1. The return values then should be 1 and 3
> instead of 0 and 1.
I have no experience with the isa-debugexit and testdev character device, and if there is any relationship between them and the semihosting code, but the original code always returned 0, regardless of the value passed by TARGET_SYS_EXIT, so I doubt there are any existing use cases that expect the semihosting code to return 1 or 3.
in addition to passing trace messages, the main use of the semihosting calls is to run unit tests, and all automated testing infrastructures assumes the test executables to return 0/non-zero, as any well behaved POSIX processes.
I personally would not change this.
regards,
Liviu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system.
2014-11-18 21:19 ` Paolo Bonzini
2014-11-18 21:43 ` Liviu Ionescu
@ 2014-11-18 22:50 ` Peter Maydell
2014-11-19 9:34 ` Paolo Bonzini
1 sibling, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2014-11-18 22:50 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Liviu Ionescu, QEMU Developers
On 18 November 2014 21:19, Paolo Bonzini <pbonzini@redhat.com> wrote:
> The isa-debugexit and testdev character device do not exit with exitcode
> 0, in order to distinguish an exit from a system power down; the
> low-order bit is always 1. The return values then should be 1 and 3
> instead of 0 and 1.
Semihosting isn't a test device -- it's an implementation of an
ABI (mostly intended for almost-but-not-quite-bare-metal programs).
I'm pretty sure that exiting anything except 0 on a successful
exit request by the guest will break usage of QEMU in scenarios
like the gcc test suite.
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system.
2014-11-18 22:50 ` Peter Maydell
@ 2014-11-19 9:34 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2014-11-19 9:34 UTC (permalink / raw)
To: Peter Maydell; +Cc: Liviu Ionescu, QEMU Developers
On 18/11/2014 23:50, Peter Maydell wrote:
> On 18 November 2014 21:19, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> The isa-debugexit and testdev character device do not exit with exitcode
>> 0, in order to distinguish an exit from a system power down; the
>> low-order bit is always 1. The return values then should be 1 and 3
>> instead of 0 and 1.
>
> Semihosting isn't a test device -- it's an implementation of an
> ABI (mostly intended for almost-but-not-quite-bare-metal programs).
> I'm pretty sure that exiting anything except 0 on a successful
> exit request by the guest will break usage of QEMU in scenarios
> like the gcc test suite.
Thanks! (FWIW, I don't find the behavior of those devices very useful
either... just mentioning them for the sake of consistency).
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-11-19 9:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-18 20:01 [Qemu-devel] [PATCH v2] Pass semihosting exit code back to system Liviu Ionescu
2014-11-18 20:08 ` Peter Maydell
2014-11-18 21:19 ` Paolo Bonzini
2014-11-18 21:43 ` Liviu Ionescu
2014-11-18 22:50 ` Peter Maydell
2014-11-19 9:34 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).