qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] Fix bug in nios2 and m68k semihosting
@ 2019-08-21 14:21 Sandra Loosemore
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling Sandra Loosemore
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 2/2] target/m68k: " Sandra Loosemore
  0 siblings, 2 replies; 10+ messages in thread
From: Sandra Loosemore @ 2019-08-21 14:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marek Vasut, Chris Wulff, Laurent Vivier

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(-)

-- 
2.8.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
  2019-08-21 14:21 [Qemu-devel] [PATCH 0/2] Fix bug in nios2 and m68k semihosting Sandra Loosemore
@ 2019-08-21 14:21 ` Sandra Loosemore
  2019-08-21 14:29   ` Philippe Mathieu-Daudé
  2019-08-21 14:41   ` Laurent Vivier
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 2/2] target/m68k: " Sandra Loosemore
  1 sibling, 2 replies; 10+ messages in thread
From: Sandra Loosemore @ 2019-08-21 14:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marek Vasut, Chris Wulff, Laurent Vivier

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.

Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
---
 target/nios2/nios2-semi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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);
-- 
2.8.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 2/2] target/m68k: Fix bug in semihosted exit handling
  2019-08-21 14:21 [Qemu-devel] [PATCH 0/2] Fix bug in nios2 and m68k semihosting Sandra Loosemore
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling Sandra Loosemore
@ 2019-08-21 14:21 ` Sandra Loosemore
  2019-08-21 14:31   ` Philippe Mathieu-Daudé
  2019-08-21 15:41   ` Laurent Vivier
  1 sibling, 2 replies; 10+ messages in thread
From: Sandra Loosemore @ 2019-08-21 14:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marek Vasut, Chris Wulff, Laurent Vivier

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.

Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
---
 target/m68k/m68k-semi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
index 8e5fbfc..f189c92 100644
--- a/target/m68k/m68k-semi.c
+++ b/target/m68k/m68k-semi.c
@@ -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);
-- 
2.8.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling Sandra Loosemore
@ 2019-08-21 14:29   ` Philippe Mathieu-Daudé
  2019-08-21 14:41   ` Laurent Vivier
  1 sibling, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-08-21 14:29 UTC (permalink / raw)
  To: Sandra Loosemore, qemu-devel; +Cc: Marek Vasut, Chris Wulff, Laurent Vivier

On 8/21/19 4:21 PM, Sandra Loosemore wrote:
> 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.
> 

Fixes: 413a99a92c1

> Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  target/nios2/nios2-semi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> 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);
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] target/m68k: Fix bug in semihosted exit handling
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 2/2] target/m68k: " Sandra Loosemore
@ 2019-08-21 14:31   ` Philippe Mathieu-Daudé
  2019-08-21 15:41   ` Laurent Vivier
  1 sibling, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-08-21 14:31 UTC (permalink / raw)
  To: Sandra Loosemore, qemu-devel
  Cc: Marek Vasut, Peter Maydell, Chris Wulff, Laurent Vivier

On 8/21/19 4:21 PM, Sandra Loosemore wrote:
> 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.
> 

Fixes: a87295e8df0 and 0e1c9c54afb

> Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  target/m68k/m68k-semi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
> index 8e5fbfc..f189c92 100644
> --- a/target/m68k/m68k-semi.c
> +++ b/target/m68k/m68k-semi.c
> @@ -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);
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling Sandra Loosemore
  2019-08-21 14:29   ` Philippe Mathieu-Daudé
@ 2019-08-21 14:41   ` Laurent Vivier
  2019-08-21 15:27     ` Sandra Loosemore
  1 sibling, 1 reply; 10+ messages in thread
From: Laurent Vivier @ 2019-08-21 14:41 UTC (permalink / raw)
  To: Sandra Loosemore, qemu-devel; +Cc: Marek Vasut, Chris Wulff

Le 21/08/2019 à 16:21, Sandra Loosemore a écrit :
> 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.
> 
> Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
> ---
>  target/nios2/nios2-semi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> 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]);

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
  2019-08-21 14:41   ` Laurent Vivier
@ 2019-08-21 15:27     ` Sandra Loosemore
  2019-08-21 15:41       ` Laurent Vivier
  0 siblings, 1 reply; 10+ messages in thread
From: Sandra Loosemore @ 2019-08-21 15:27 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel; +Cc: Marek Vasut, Chris Wulff

On 8/21/19 8:41 AM, Laurent Vivier wrote:
> Le 21/08/2019 à 16:21, Sandra Loosemore a écrit :
>> 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.
>>
>> Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
>> ---
>>   target/nios2/nios2-semi.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> 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]);
> 
> 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?

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.

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

And m68k:

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

Again, a lot of cutting and pasting involved here.  ;-)

-Sandra


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
  2019-08-21 15:27     ` Sandra Loosemore
@ 2019-08-21 15:41       ` Laurent Vivier
  2019-08-21 17:48         ` Sandra Loosemore
  0 siblings, 1 reply; 10+ messages in thread
From: Laurent Vivier @ 2019-08-21 15:41 UTC (permalink / raw)
  To: Sandra Loosemore, qemu-devel; +Cc: Marek Vasut, Chris Wulff

Le 21/08/2019 à 17:27, Sandra Loosemore a écrit :
> On 8/21/19 8:41 AM, Laurent Vivier wrote:
>> Le 21/08/2019 à 16:21, Sandra Loosemore a écrit :
>>> 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.
>>>
>>> Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
>>> ---
>>>   target/nios2/nios2-semi.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> 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]);
>>
>> 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?
> 
> 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.
> 
> https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/nios2/nios2-semi.txt;h=ded3a093c03dbae84cb95b4cd45bc3e0d751eda2;hb=HEAD
> 
> 
> And m68k:
> 
> https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;h=50520c15292aa7edf7eef28e09fd9202ce75b153;hb=HEAD
> 
> 
> 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?

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] target/m68k: Fix bug in semihosted exit handling
  2019-08-21 14:21 ` [Qemu-devel] [PATCH 2/2] target/m68k: " Sandra Loosemore
  2019-08-21 14:31   ` Philippe Mathieu-Daudé
@ 2019-08-21 15:41   ` Laurent Vivier
  1 sibling, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2019-08-21 15:41 UTC (permalink / raw)
  To: Sandra Loosemore, qemu-devel; +Cc: Marek Vasut, Chris Wulff

Le 21/08/2019 à 16:21, Sandra Loosemore a écrit :
> 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.
> 
> Signed-off-by: Sandra Loosemore <sandra@codesourcery.com>
> ---
>  target/m68k/m68k-semi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
> index 8e5fbfc..f189c92 100644
> --- a/target/m68k/m68k-semi.c
> +++ b/target/m68k/m68k-semi.c
> @@ -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);
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
  2019-08-21 15:41       ` Laurent Vivier
@ 2019-08-21 17:48         ` Sandra Loosemore
  0 siblings, 0 replies; 10+ messages in thread
From: Sandra Loosemore @ 2019-08-21 17:48 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel; +Cc: Marek Vasut, Chris Wulff

On 8/21/19 9:41 AM, Laurent Vivier wrote:

> Could add this information in the commit messages of each patch?

Sure.  V2 of the patches coming up shortly.

-Sandra


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-08-21 18:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21 14:21 [Qemu-devel] [PATCH 0/2] Fix bug in nios2 and m68k semihosting Sandra Loosemore
2019-08-21 14:21 ` [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling Sandra Loosemore
2019-08-21 14:29   ` Philippe Mathieu-Daudé
2019-08-21 14:41   ` Laurent Vivier
2019-08-21 15:27     ` Sandra Loosemore
2019-08-21 15:41       ` Laurent Vivier
2019-08-21 17:48         ` Sandra Loosemore
2019-08-21 14:21 ` [Qemu-devel] [PATCH 2/2] target/m68k: " Sandra Loosemore
2019-08-21 14:31   ` Philippe Mathieu-Daudé
2019-08-21 15:41   ` Laurent Vivier

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