[PATCH v2] target/riscv: make mstatus.SPELP read-only when S-mode is not present

Christian S. Lima posted 1 patch 1 week, 2 days ago
target/riscv/tcg/csr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH v2] target/riscv: make mstatus.SPELP read-only when S-mode is not present
Posted by Christian S. Lima 1 week, 2 days ago
According to the Zicfilp specification the bit SPELP in the mstatus
register should be 0 (read-only) when s-mode is not present.

changes in v2:
- Change to patch series
- Now tooling can close the issue in Gitlab properly

Link to v1: https://lore.kernel.org/qemu-riscv/20261112214810.78747-2-christianslima@proton.me/

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4456

Signed-off-by: Christian S. Lima <christianslima@proton.me>
---
 target/riscv/tcg/csr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index 398e312c9a..9d0378bc69 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -2131,7 +2131,10 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
 
     /* If cfi lp extension is available, then apply cfi lp mask */
     if (env_archcpu(env)->cfg.ext_zicfilp) {
-        mask |= (MSTATUS_MPELP | MSTATUS_SPELP);
+        mask |= MSTATUS_MPELP;
+        if (riscv_has_ext(env, RVS)) {
+            mask |= MSTATUS_SPELP;
+        }
     }
 
     mstatus = (mstatus & ~mask) | (val & mask);
-- 
2.56.0