qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/riscv: fix vs() to return proper error code
@ 2021-02-23  6:59 frank.chang
  2021-02-23 18:46 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: frank.chang @ 2021-02-23  6:59 UTC (permalink / raw)
  To: qemu-devel, qemu-riscv
  Cc: Frank Chang, Alistair Francis, Palmer Dabbelt, Sagar Karandikar,
	Bastian Koppelmann

From: Frank Chang <frank.chang@sifive.com>

vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature
is not enabled.

If -1 is returned, exception will be raised and cs->exception_index will
be set to the negative return value. The exception will then be treated
as an instruction access fault instead of illegal instruction fault.

Signed-off-by: Frank Chang <frank.chang@sifive.com>
---
 target/riscv/csr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index fd2e6363f39..d2ae73e4a08 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -54,7 +54,7 @@ static int vs(CPURISCVState *env, int csrno)
     if (env->misa & RVV) {
         return 0;
     }
-    return -1;
+    return -RISCV_EXCP_ILLEGAL_INST;
 }
 
 static int ctr(CPURISCVState *env, int csrno)
-- 
2.17.1



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

* Re: [PATCH] target/riscv: fix vs() to return proper error code
  2021-02-23  6:59 [PATCH] target/riscv: fix vs() to return proper error code frank.chang
@ 2021-02-23 18:46 ` Richard Henderson
  2021-03-08 13:38   ` Alistair Francis
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2021-02-23 18:46 UTC (permalink / raw)
  To: frank.chang, qemu-devel, qemu-riscv
  Cc: Palmer Dabbelt, Alistair Francis, Sagar Karandikar,
	Bastian Koppelmann

On 2/22/21 10:59 PM, frank.chang@sifive.com wrote:
> From: Frank Chang <frank.chang@sifive.com>
> 
> vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature
> is not enabled.
> 
> If -1 is returned, exception will be raised and cs->exception_index will
> be set to the negative return value. The exception will then be treated
> as an instruction access fault instead of illegal instruction fault.

It does seem an unfortunate interface; -1 seems so tempting, but does not by
itself mean anything.

I wonder if we should dispense with the whole "negative number" thing and
simply return an exception value.  Then for bonus points put all of the
RISCV_EXCP_* values in an enumeration, and return that type from these
functions so that it's perfectly clear what the interface really is.

That said,

> @@ -54,7 +54,7 @@ static int vs(CPURISCVState *env, int csrno)
>      if (env->misa & RVV) {
>          return 0;
>      }
> -    return -1;
> +    return -RISCV_EXCP_ILLEGAL_INST;

this fixes the immediate bug, so
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


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

* Re: [PATCH] target/riscv: fix vs() to return proper error code
  2021-02-23 18:46 ` Richard Henderson
@ 2021-03-08 13:38   ` Alistair Francis
  0 siblings, 0 replies; 3+ messages in thread
From: Alistair Francis @ 2021-03-08 13:38 UTC (permalink / raw)
  To: Richard Henderson
  Cc: open list:RISC-V, Sagar Karandikar, Frank Chang,
	Bastian Koppelmann, qemu-devel@nongnu.org Developers,
	Palmer Dabbelt, Alistair Francis

On Tue, Feb 23, 2021 at 1:46 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 2/22/21 10:59 PM, frank.chang@sifive.com wrote:
> > From: Frank Chang <frank.chang@sifive.com>
> >
> > vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature
> > is not enabled.
> >
> > If -1 is returned, exception will be raised and cs->exception_index will
> > be set to the negative return value. The exception will then be treated
> > as an instruction access fault instead of illegal instruction fault.
>
> It does seem an unfortunate interface; -1 seems so tempting, but does not by
> itself mean anything.
>
> I wonder if we should dispense with the whole "negative number" thing and
> simply return an exception value.  Then for bonus points put all of the
> RISCV_EXCP_* values in an enumeration, and return that type from these
> functions so that it's perfectly clear what the interface really is.

Good idea!

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

>
> That said,
>
> > @@ -54,7 +54,7 @@ static int vs(CPURISCVState *env, int csrno)
> >      if (env->misa & RVV) {
> >          return 0;
> >      }
> > -    return -1;
> > +    return -RISCV_EXCP_ILLEGAL_INST;
>
> this fixes the immediate bug, so
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
>
> r~
>


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

end of thread, other threads:[~2021-03-08 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-23  6:59 [PATCH] target/riscv: fix vs() to return proper error code frank.chang
2021-02-23 18:46 ` Richard Henderson
2021-03-08 13:38   ` Alistair Francis

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