qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] target/riscv: Add User CSRs read-only check


From: LIU Zhiwei
Subject: Re: [PATCH] target/riscv: Add User CSRs read-only check
Date: Mon, 9 Aug 2021 17:43:22 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0


On 2021/8/9 下午5:35, Bin Meng wrote:
On Mon, Aug 9, 2021 at 3:09 PM LIU Zhiwei <zhiwei_liu@c-sky.com> wrote:
nits: please write something in the commit message
OK

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
  target/riscv/csr.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 9a4ed18ac5..ea62d9e653 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -1422,11 +1422,11 @@ RISCVException riscv_csrrw(CPURISCVState *env, int 
csrno,
      RISCVException ret;
      target_ulong old_value;
      RISCVCPU *cpu = env_archcpu(env);
+    int read_only = get_field(csrno, 0xC00) == 3;

      /* check privileges and return -1 if check fails */
  #if !defined(CONFIG_USER_ONLY)
      int effective_priv = env->priv;
-    int read_only = get_field(csrno, 0xC00) == 3;

      if (riscv_has_ext(env, RVH) &&
          env->priv == PRV_S &&
@@ -1443,6 +1443,10 @@ RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
          (!env->debugger && (effective_priv < get_field(csrno, 0x300)))) {
          return RISCV_EXCP_ILLEGAL_INST;
      }
+#else
+    if (write_mask && read_only) {
This can be merged by the !CONFIG_USER_ONLY case.

Do you mean

#if !defined(CONFIG_USER_ONLY)
     if (!env->debugger && (effective_priv < get_field(csrno, 0x300))) {
         return -RISCV_EXCP_ILLEGAL_INST;
}
#else
     if (write_mask && read_only) {
         return -RISCV_EXCP_ILLEGAL_INST;
}

#endif


Thanks,
Zhiwei


+        return -RISCV_EXCP_ILLEGAL_INST;
+    }
  #endif

      /* ensure the CSR extension is enabled. */
Regards,
Bin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]