diff mbox series

[V2,1/2] target/nios2: Fix bug in semihosted exit handling

Message ID 20190821175029.21868-2-sandra@codesourcery.com (mailing list archive)
State New, archived
Headers show
Series Fix bug in nios2 and m68k semihosting | expand

Commit Message

Sandra Loosemore Aug. 21, 2019, 5:50 p.m. UTC
This patch fixes a bug that caused semihosted exit to always return
status 0; it was incorrectly using the value of register R_ARG0 (which
contains the HOSTED_EXIT request number) instead of register R_ARG1.

Note that per the newlib documentation for the nios2 semihosting protocol

https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/nios2/nios2-semi.txt;h=ded3a093c03dbae84cb95b4cd45bc3e0d751eda2;hb=HEAD

for the HOSTED_EXIT syscall the parameter is passed directly in the register
instead of in a parameter block pointed to by the register.

Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 target/nios2/nios2-semi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c
index d7a80dd..06c0861 100644
--- a/target/nios2/nios2-semi.c
+++ b/target/nios2/nios2-semi.c
@@ -215,8 +215,8 @@  void do_nios2_semihosting(CPUNios2State *env)
     args = env->regs[R_ARG1];
     switch (nr) {
     case HOSTED_EXIT:
-        gdb_exit(env, env->regs[R_ARG0]);
-        exit(env->regs[R_ARG0]);
+        gdb_exit(env, env->regs[R_ARG1]);
+        exit(env->regs[R_ARG1]);
     case HOSTED_OPEN:
         GET_ARG(0);
         GET_ARG(1);