qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Francis <alistair23@gmail.com>
To: LIU Zhiwei <zhiwei_liu@c-sky.com>
Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>,
	Bin Meng <bin.meng@windriver.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Palmer Dabbelt <palmer@dabbelt.com>
Subject: Re: [PATCH 1/1] target/riscv: Fix vsip vsie CSR ops in M and HS mode
Date: Fri, 28 May 2021 08:19:24 +1000	[thread overview]
Message-ID: <CAKmqyKMtRCP7gouO0qBUsKPXCgroKsSXkTr8FTgDydXdrUc8tw@mail.gmail.com> (raw)
In-Reply-To: <20210527090051.1837256-1-zhiwei_liu@c-sky.com>

On Thu, May 27, 2021 at 7:01 PM LIU Zhiwei <zhiwei_liu@c-sky.com> wrote:
>
> When V=1, instructions that normally read or modify a supervisor CSR
> shall instead access the corresponding VS CSR. And the VS CSRs can be
> accessed as themselves from M-mode or HS-mode.
>
> In M and HS mode, VSIP or VSIE should be written normally instead of
> shift by 1.
>
> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
> ---
>  target/riscv/csr.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index fe5628fea6..0cce474d3d 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -837,16 +837,16 @@ static RISCVException read_sie(CPURISCVState *env, int csrno,
>  static RISCVException write_vsie(CPURISCVState *env, int csrno,
>                                   target_ulong val)
>  {
> -    /* Shift the S bits to their VS bit location in mie */
>      target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) |
> -                          ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS);
> +                          (val & env->hideleg & VS_MODE_INTERRUPTS);

Ok, so when a Hypervisor writes to vsie it should actually set SSIE
instead of VSSIE. That looks right.

The problem here now is that you are still using the VS mask, so this
won't set anything.

>      return write_mie(env, CSR_MIE, newval);
>  }
>
>  static int write_sie(CPURISCVState *env, int csrno, target_ulong val)
>  {
>      if (riscv_cpu_virt_enabled(env)) {
> -        write_vsie(env, CSR_VSIE, val);
> +        /* Shift the S bits to their VS bit location in mie */
> +        write_vsie(env, CSR_VSIE, val << 1);

A write to SIE when virtulised actually sets VSIE, sounds good.

>      } else {
>          target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) |
>                                (val & S_MODE_INTERRUPTS);
> @@ -950,12 +950,9 @@ static RISCVException rmw_vsip(CPURISCVState *env, int csrno,
>                                 target_ulong *ret_value,
>                                 target_ulong new_value, target_ulong write_mask)
>  {
> -    /* Shift the S bits to their VS bit location in mip */
> -    int ret = rmw_mip(env, 0, ret_value, new_value << 1,
> -                      (write_mask << 1) & vsip_writable_mask & env->hideleg);
> +    int ret = rmw_mip(env, 0, ret_value, new_value,
> +                      write_mask & vsip_writable_mask & env->hideleg);

The mask seems wrong here as well.

Alistair

>      *ret_value &= VS_MODE_INTERRUPTS;
> -    /* Shift the VS bits to their S bit location in vsip */
> -    *ret_value >>= 1;
>      return ret;
>  }
>
> @@ -966,7 +963,11 @@ static RISCVException rmw_sip(CPURISCVState *env, int csrno,
>      int ret;
>
>      if (riscv_cpu_virt_enabled(env)) {
> -        ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask);
> +        /* Shift the S bits to their VS bit location in mip */
> +        ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value << 1,
> +                       write_mask << 1);
> +        /* Shift the VS bits to their S bit location in vsip */
> +        *ret_value >>= 1;
>      } else {
>          ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value,
>                        write_mask & env->mideleg & sip_writable_mask);
> --
> 2.25.1
>
>


  reply	other threads:[~2021-05-27 22:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27  9:00 [PATCH 1/1] target/riscv: Fix vsip vsie CSR ops in M and HS mode LIU Zhiwei
2021-05-27 22:19 ` Alistair Francis [this message]
2021-05-28  0:32   ` LIU Zhiwei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKmqyKMtRCP7gouO0qBUsKPXCgroKsSXkTr8FTgDydXdrUc8tw@mail.gmail.com \
    --to=alistair23@gmail.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=bin.meng@windriver.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=zhiwei_liu@c-sky.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).