qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Atish Patra <atishp@rivosinc.com>
To: qemu-devel@nongnu.org
Cc: Atish Patra <atishp@rivosinc.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	Bin Meng <bin.meng@windriver.com>,
	Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
	Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	qemu-riscv@nongnu.org, Weiwei Li <liwei1518@gmail.com>,
	kaiwenxue1@gmail.com
Subject: [PATCH RFC 7/8] target/riscv: Add select value range check for counter delegation
Date: Fri, 16 Feb 2024 16:01:33 -0800	[thread overview]
Message-ID: <20240217000134.3634191-8-atishp@rivosinc.com> (raw)
In-Reply-To: <20240217000134.3634191-1-atishp@rivosinc.com>

From: Kaiwen Xue <kaiwenx@rivosinc.com>

This adds checks in ops performed on xireg and xireg2-xireg6 so that the
counter delegation function will receive a valid xiselect value with the
proper extensions enabled.

Co-developed-by: Atish Patra <atishp@rivosinc.com>
Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 target/riscv/csr.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index a1c10f1d010a..d5218a47ffbf 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -1978,6 +1978,11 @@ static bool xiselect_aia_range(target_ulong isel)
            (ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST);
 }
 
+static bool xiselect_cd_range(target_ulong isel)
+{
+    return (ISELECT_CD_FIRST <= isel && isel <= ISELECT_CD_LAST);
+}
+
 static int rmw_iprio(target_ulong xlen,
                      target_ulong iselect, uint8_t *iprio,
                      target_ulong *val, target_ulong new_val,
@@ -2103,6 +2108,17 @@ done:
     return RISCV_EXCP_NONE;
 }
 
+static int rmw_xireg_cd(CPURISCVState *env, int csrno,
+                        target_ulong isel, target_ulong *val,
+                        target_ulong new_val, target_ulong wr_mask)
+{
+    if (!riscv_cpu_cfg(env)->ext_smcdeleg) {
+        return RISCV_EXCP_ILLEGAL_INST;
+    }
+    /* TODO: Implement the functionality later */
+    return RISCV_EXCP_NONE;
+}
+
 /*
  * rmw_xireg_sxcsrind: Perform indirect access to xireg and xireg2-xireg6
  *
@@ -2114,7 +2130,25 @@ static int rmw_xireg_sxcsrind(CPURISCVState *env, int csrno,
                               target_ulong isel, target_ulong *val,
                               target_ulong new_val, target_ulong wr_mask)
 {
-    return -EINVAL;
+    int ret = -EINVAL;
+    bool virt = csrno == CSR_VSIREG ? true : false;
+
+    if (xiselect_cd_range(isel)) {
+        ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask);
+    } else {
+        /*
+         * As per the specification, access to unimplented region is undefined
+         * but recommendation is to raise illegal instruction exception.
+         */
+        return RISCV_EXCP_ILLEGAL_INST;
+    }
+
+    if (ret) {
+        return (env->virt_enabled && virt) ?
+               RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST;
+    }
+
+    return RISCV_EXCP_NONE;
 }
 
 static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val,
-- 
2.34.1



  parent reply	other threads:[~2024-02-17  0:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17  0:01 [PATCH RFC 0/8] Add Counter delegation ISA extension support Atish Patra
2024-02-17  0:01 ` [PATCH RFC 1/8] target/riscv: Add properties for Indirect CSR Access extension Atish Patra
2024-02-17  0:01 ` [PATCH RFC 2/8] target/riscv: Decouple AIA processing from xiselect and xireg Atish Patra
2024-06-05  8:17   ` Jason Chien
2024-02-17  0:01 ` [PATCH RFC 3/8] target/riscv: Enable S*stateen bits for AIA Atish Patra
2024-02-17  0:01 ` [PATCH RFC 4/8] target/riscv: Support generic CSR indirect access Atish Patra
2024-06-05 11:49   ` Jason Chien
2024-07-23 23:31     ` Atish Kumar Patra
2024-02-17  0:01 ` [PATCH RFC 5/8] target/riscv: Add smcdeleg/ssccfg properties Atish Patra
2024-02-17  0:01 ` [PATCH RFC 6/8] target/riscv: Add counter delegation definitions Atish Patra
2024-02-17  0:01 ` Atish Patra [this message]
2024-02-17  0:01 ` [PATCH RFC 8/8] target/riscv: Add counter delegation/configuration support Atish Patra
2024-02-21 14:58 ` [PATCH RFC 0/8] Add Counter delegation ISA extension support Daniel Henrique Barboza
2024-02-21 17:06   ` Atish Kumar Patra
2024-02-21 18:26     ` Daniel Henrique Barboza
2024-02-21 20:17       ` Atish Patra
2024-02-21 21:10         ` Daniel Henrique Barboza
2024-06-01  9:52 ` Daniel Henrique Barboza
2024-06-02  6:39   ` Atish Kumar Patra

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=20240217000134.3634191-8-atishp@rivosinc.com \
    --to=atishp@rivosinc.com \
    --cc=alistair.francis@wdc.com \
    --cc=bin.meng@windriver.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=kaiwenxue1@gmail.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=zhiwei_liu@linux.alibaba.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).