According to the Zicfilp specification the bit SPELP in the mstatus
register should be 0 (read-only) when s-mode is not present.

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

Signed-off-by: Christian S. Lima <[email protected]>
---
 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 af444e3e6f..340c61a1c4 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -2124,7 +2124,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



Reply via email to