Skip to contentSkip to conversation

Fix bug in nios2 and m68k semihosting

PATCH New Sandra Loosemore 1 participant 3 messages Aug 21, 2019

lore
Share & tools
lore
#2 lore raw

PATCH v2 2/2 target/m68k: Fix bug in semihosted exit handling

In reply to Sandra Loosemore

This patch fixes a bug that caused semihosted exit to always return status 0; it was incorrectly using the value of D0 (which contains the HOSTED_EXIT request number) instead of D1.

Note that per the newlib documentation for the m68k semihosting protocol

https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;h=50520c15292aa7edf7eef28e09fd9202ce75b153;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.

---
 target/m68k/m68k-semi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/m68k/m68k-semi.c +2 -2
index 8e5fbfc..f189c92 100644
@@ -194,8 +194,8 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
     args = env->dregs[1];
     switch (nr) {
     case HOSTED_EXIT:
-        gdb_exit(env, env->dregs[0]);
-        exit(env->dregs[0]);
+        gdb_exit(env, env->dregs[1]);
+        exit(env->dregs[1]);
     case HOSTED_OPEN:
         GET_ARG(0);
         GET_ARG(1);
Signature · 1 line
2.8.1
#1 lore raw

PATCH v2 1/2 target/nios2: Fix bug in semihosted exit handling

In reply to Sandra Loosemore

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.

---
 target/nios2/nios2-semi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/nios2/nios2-semi.c +2 -2
index d7a80dd..06c0861 100644
@@ -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);
Signature · 1 line
2.8.1
#0 lore raw

v2 cover Fix bug in nios2 and m68k semihosting

I noticed recently that the exit semihosting call on nios2 was ignoring its parameter and always returning status 0 instead. It turns out the handler was retrieving the value of the wrong register. Since the nios2 semihosting implementation was basically cut-and-pasted from that for m68k, I checked m68k also and it had the same bug. This set of patches fixes both of them.

There are no changes to the actual patches from V1, only more informative commit messages with links to the respective semihosting protocol documents in newlib.

Sandra Loosemore (2):
target/nios2: Fix bug in semihosted exit handling target/m68k: Fix bug in semihosted exit handling

 target/m68k/m68k-semi.c   | 4 ++--
 target/nios2/nios2-semi.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.8.1