Fix bug in nios2 and m68k semihosting
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.
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
PATCH 2/2 target/m68k: Fix bug in semihosted exit handling
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.
--- target/m68k/m68k-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/m68k/m68k-semi.c +2 -2
@@ -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
PATCH 1/2 target/nios2: Fix bug in semihosted exit handling
In reply to Sandra LoosemoreThis 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.
--- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/nios2/nios2-semi.c +2 -2
@@ -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
Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
Quoted 4 lines · 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 theHOSTED_EXITrequest number) instead of registerR_ARG1.
Quoted 1 line
Signed-off-by Sandra Loosemore <[email protected]>
Quoted 20 lines
--- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/nios2/nios2-semi.c +2
-2@@ -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 );
Re: [Qemu-devel] [PATCH 2/2] target/m68k: Fix bug in semihosted exit handling
In reply to Sandra LoosemoreQuoted 4 lines · 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_EXITrequest number) instead of D1.
Quoted 1 line
Signed-off-by Sandra Loosemore <[email protected]>
Quoted 20 lines
--- target/m68k/m68k-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/m68k/m68k-semi.c +2
-2@@ -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 );
Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
In reply to Sandra LoosemoreLe 21/08/2019 à 16:21, Sandra Loosemore a écrit :
Quoted 14 lines
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 theHOSTED_EXITrequest number) instead of registerR_ARG1.Signed-off-by Sandra Loosemore <[email protected]>--- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/nios2/nios2-semi.c +0
-0
target/nios2/nios2-semi.c void do_nios2_semihosting(CPUNios2State *env) · line 219
Quoted 7 lines
target/nios2/nios2-semi.c +2
-2@@ -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 ]);
It's weird: in line 215, env->regs[R_ARG1] is args.
Are you sure it's not something like:
GET_ARG(0)
gdb_exit(env, arg0);
exit(arg0);same for m68k.
Did you check the kernel code?
Thanks,
Laurent
Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
Quoted 27 lines · Laurent Vivier
Le 21/08/2019 à 16:21, Sandra Loosemore a écrit :
Quoted 14 lines
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 theHOSTED_EXITrequest number) instead of registerR_ARG1.Signed-off-by Sandra Loosemore <[email protected]>--- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/nios2/nios2-semi.c +0
-0target/nios2/nios2-semi.c void do_nios2_semihosting(CPUNios2State *env) · line 219
Quoted 7 lines
target/nios2/nios2-semi.c +2
-2@@ -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 ]);It's weird: in line 215, env->regs[R_ARG1] is args.
Are you sure it's not something like:
Quoted 7 lines
GET_ARG(0) gdb_exit(env, arg0); exit(arg0);same for m68k.
Did you check the kernel code?
It's not the kernel that's involved here, it's libgloss. And yes, the HOSTED_EXIT case takes an immediate argument in the register rather than a pointer to an argument block.
Here's the documentation for nios2 semihosting.
And m68k:
Again, a lot of cutting and pasting involved here. ;-)
-Sandra
Laurent Vivier
Reviewed-byRe: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
Le 21/08/2019 à 17:27, Sandra Loosemore a écrit :
Quoted 45 lines · Laurent Vivier
Quoted 27 lines
Le 21/08/2019 à 16:21, Sandra Loosemore a écrit :
Quoted 16 lines
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 theHOSTED_EXITrequest number) instead of registerR_ARG1.Signed-off-by Sandra Loosemore <[email protected]>---
target/nios2/nios2-semi.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)target/nios2/nios2-semi.c +0
-0@@ -215,8 +215,8 @@ void do_nios2_semihosting(CPUNios2State *env) args = env->regs[R_ARG1]; switch (nr) {Quoted 5 lines
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]);It's weird: in line 215, env->regs[R_ARG1] is args.
Are you sure it's not something like:
Quoted 7 lines
GET_ARG(0)
gdb_exit(env, arg0);
exit(arg0);same for m68k.
Did you check the kernel code?
It's not the kernel that's involved here, it's libgloss. And yes, the
HOSTED_EXITcase takes an immediate argument in the register rather than a pointer to an argument block.Here's the documentation for nios2 semihosting.
Quoted 8 lines
And m68k:
Again, a lot of cutting and pasting involved here. ;-)
-Sandra
Thank you for the details.
Could add this information in the commit messages of each patch?
Re: [Qemu-devel] [PATCH 2/2] target/m68k: Fix bug in semihosted exit handling
In reply to Sandra LoosemoreLe 21/08/2019 à 16:21, Sandra Loosemore a écrit :
Quoted 15 lines
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_EXITrequest number) instead of D1.Signed-off-by Sandra Loosemore <[email protected]>--- target/m68k/m68k-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/m68k/m68k-semi.c +0
-0
target/m68k/m68k-semi.c void do_m68k_semihosting(CPUM68KState *env, int nr) · line 201
Quoted 10 lines
target/m68k/m68k-semi.c +2
-2@@ -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 );
Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
In reply to Laurent VivierQuoted 1 line · Laurent Vivier
Could add this information in the commit messages of each patch?
Sure. V2 of the patches coming up shortly.
-Sandra