qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/nios2: Pass semihosting arg to exit
@ 2023-07-31 22:41 Keith Packard via
  2023-08-01 12:04 ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Keith Packard via @ 2023-07-31 22:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: Chris Wulff, Marek Vasut, Keith Packard

Instead of using the function number (which is always zero), fetch the
application-provided exit code argument and pass that to the two exit
functions.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 target/nios2/nios2-semi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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



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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-07-31 22:41 [PATCH] target/nios2: Pass semihosting arg to exit Keith Packard via
@ 2023-08-01 12:04 ` Peter Maydell
  2023-08-01 15:10   ` Keith Packard via
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2023-08-01 12:04 UTC (permalink / raw)
  To: Keith Packard; +Cc: qemu-devel, Chris Wulff, Marek Vasut

On Mon, 31 Jul 2023 at 23:42, Keith Packard via <qemu-devel@nongnu.org> wrote:
>
> Instead of using the function number (which is always zero), fetch the
> application-provided exit code argument and pass that to the two exit
> functions.
>
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
>  target/nios2/nios2-semi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c
> index 3738774976..ffd1f095f6 100644
> --- a/target/nios2/nios2-semi.c
> +++ b/target/nios2/nios2-semi.c
> @@ -133,8 +133,9 @@ void do_nios2_semihosting(CPUNios2State *env)
>      args = env->regs[R_ARG1];
>      switch (nr) {
>      case HOSTED_EXIT:
> -        gdb_exit(env->regs[R_ARG0]);
> -        exit(env->regs[R_ARG0]);
> +        GET_ARG(0);
> +        gdb_exit(arg0);
> +        exit(arg0);

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

says that for HOSTED_EXIT the exit code is in r5,
not in a parameter block pointed to by r5. That
would imply that the correct change is to use
R_ARG1 rather than R_ARG0 here.

thanks
-- PMM


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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-08-01 12:04 ` Peter Maydell
@ 2023-08-01 15:10   ` Keith Packard via
  2023-08-01 15:17     ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Keith Packard via @ 2023-08-01 15:10 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Chris Wulff, Marek Vasut

[-- Attachment #1: Type: text/plain, Size: 304 bytes --]


> says that for HOSTED_EXIT the exit code is in r5,
> not in a parameter block pointed to by r5. That
> would imply that the correct change is to use
> R_ARG1 rather than R_ARG0 here.

Ah, thanks -- I hadn't managed to find the actual standard yet. I'll
resubmit with that fixed.

-- 
-keith

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-08-01 15:10   ` Keith Packard via
@ 2023-08-01 15:17     ` Peter Maydell
  2023-08-01 15:28       ` Keith Packard via
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2023-08-01 15:17 UTC (permalink / raw)
  To: Keith Packard; +Cc: qemu-devel, Chris Wulff, Marek Vasut

On Tue, 1 Aug 2023 at 16:10, Keith Packard <keithp@keithp.com> wrote:
>
>
> > says that for HOSTED_EXIT the exit code is in r5,
> > not in a parameter block pointed to by r5. That
> > would imply that the correct change is to use
> > R_ARG1 rather than R_ARG0 here.
>
> Ah, thanks -- I hadn't managed to find the actual standard yet.

Yeah, the closest to a "standard" we have for nios2 is that
I asked the Codesourcery folks to document it in the libgloss
sources and put the URL to it in a comment at the top of
nios2-semi.c, given that there's no official spec and the
original and main guest-side user is libgloss.
m68k is in a similar position only without the URL
in our source file :-)

-- PMM


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

* [PATCH] target/nios2: Pass semihosting arg to exit
@ 2023-08-01 15:22 Keith Packard via
  2023-08-01 15:24 ` Peter Maydell
  2023-08-01 21:45 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 9+ messages in thread
From: Keith Packard via @ 2023-08-01 15:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Chris Wulff, Marek Vasut, Keith Packard

Instead of using R_ARG0 (the semihost function number), use R_ARG1
(the provided exit status).

Signed-off-by: Keith Packard <keithp@keithp.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 3738774976..f3b7aee4f1 100644
--- a/target/nios2/nios2-semi.c
+++ b/target/nios2/nios2-semi.c
@@ -133,8 +133,8 @@ void do_nios2_semihosting(CPUNios2State *env)
     args = env->regs[R_ARG1];
     switch (nr) {
     case HOSTED_EXIT:
-        gdb_exit(env->regs[R_ARG0]);
-        exit(env->regs[R_ARG0]);
+        gdb_exit(env->regs[R_ARG1]);
+        exit(env->regs[R_ARG1]);
 
     case HOSTED_OPEN:
         GET_ARG(0);
-- 
2.40.1



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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-08-01 15:22 Keith Packard via
@ 2023-08-01 15:24 ` Peter Maydell
  2023-08-01 21:45 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 9+ messages in thread
From: Peter Maydell @ 2023-08-01 15:24 UTC (permalink / raw)
  To: Keith Packard; +Cc: qemu-devel, Chris Wulff, Marek Vasut

On Tue, 1 Aug 2023 at 16:23, Keith Packard via <qemu-devel@nongnu.org> wrote:
>
> Instead of using R_ARG0 (the semihost function number), use R_ARG1
> (the provided exit status).
>
> Signed-off-by: Keith Packard <keithp@keithp.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 3738774976..f3b7aee4f1 100644
> --- a/target/nios2/nios2-semi.c
> +++ b/target/nios2/nios2-semi.c
> @@ -133,8 +133,8 @@ void do_nios2_semihosting(CPUNios2State *env)
>      args = env->regs[R_ARG1];
>      switch (nr) {
>      case HOSTED_EXIT:
> -        gdb_exit(env->regs[R_ARG0]);
> -        exit(env->regs[R_ARG0]);
> +        gdb_exit(env->regs[R_ARG1]);
> +        exit(env->regs[R_ARG1]);
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-08-01 15:17     ` Peter Maydell
@ 2023-08-01 15:28       ` Keith Packard via
  2023-08-01 15:33         ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Keith Packard via @ 2023-08-01 15:28 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Chris Wulff, Marek Vasut

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]


> Yeah, the closest to a "standard" we have for nios2 is that
> I asked the Codesourcery folks to document it in the libgloss
> sources and put the URL to it in a comment at the top of
> nios2-semi.c, given that there's no official spec and the
> original and main guest-side user is libgloss.
> m68k is in a similar position only without the URL
> in our source file :-)

Yeah, we had the same ask when getting risc-v semihosting merged. For
that, I actually pushed through an "official" risc-v standard. I kinda
wish I'd used the m68k model instead of the arm model as that provides
simple POSIX semantics...

https://github.com/riscv-software-src/riscv-semihosting/blob/main/riscv-semihosting-spec.adoc

-- 
-keith

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-08-01 15:28       ` Keith Packard via
@ 2023-08-01 15:33         ` Peter Maydell
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Maydell @ 2023-08-01 15:33 UTC (permalink / raw)
  To: Keith Packard; +Cc: qemu-devel, Chris Wulff, Marek Vasut

On Tue, 1 Aug 2023 at 16:28, Keith Packard <keithp@keithp.com> wrote:
>
>
> > Yeah, the closest to a "standard" we have for nios2 is that
> > I asked the Codesourcery folks to document it in the libgloss
> > sources and put the URL to it in a comment at the top of
> > nios2-semi.c, given that there's no official spec and the
> > original and main guest-side user is libgloss.
> > m68k is in a similar position only without the URL
> > in our source file :-)
>
> Yeah, we had the same ask when getting risc-v semihosting merged. For
> that, I actually pushed through an "official" risc-v standard. I kinda
> wish I'd used the m68k model instead of the arm model as that provides
> simple POSIX semantics...

Yeah, there's a lot of stuff in the Arm semihosting API
that I wouldn't put in there for a from-new version
that didn't need to handle legacy guests. Notably the
"errno" concept is badly underspecified and/or broken.
On an architecture with a decent number of registers
it would probably also make sense to use them rather
than having every single call put its args in memory.

thanks
-- PMM


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

* Re: [PATCH] target/nios2: Pass semihosting arg to exit
  2023-08-01 15:22 Keith Packard via
  2023-08-01 15:24 ` Peter Maydell
@ 2023-08-01 21:45 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-08-01 21:45 UTC (permalink / raw)
  To: Keith Packard, qemu-devel; +Cc: Chris Wulff, Marek Vasut

On 1/8/23 17:22, Keith Packard via wrote:
> Instead of using R_ARG0 (the semihost function number), use R_ARG1
> (the provided exit status).
> 
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
>   target/nios2/nios2-semi.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Thanks, queued via misc-fixes.


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

end of thread, other threads:[~2023-08-01 21:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-31 22:41 [PATCH] target/nios2: Pass semihosting arg to exit Keith Packard via
2023-08-01 12:04 ` Peter Maydell
2023-08-01 15:10   ` Keith Packard via
2023-08-01 15:17     ` Peter Maydell
2023-08-01 15:28       ` Keith Packard via
2023-08-01 15:33         ` Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2023-08-01 15:22 Keith Packard via
2023-08-01 15:24 ` Peter Maydell
2023-08-01 21:45 ` Philippe Mathieu-Daudé

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