Skip to contentSkip to conversation

target/riscv: fix exception handling for SIREG2-SIREG6 accesses

PATCH New Dmitry Kokorev via qemu development 1 participant 1 message Nov 28 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: fix exception handling for SIREG2-SIREG6 accesses

Fix the virt flag in rmw_xireg_csrind() to use a range check covering VSIREG2 through VSIREG6. Avoid the early return for AIA isel ranges so that they are handled by the virtual instruction exception check.

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

---
 target/riscv/tcg/csr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/riscv/tcg/csr.c +3 -2
index af444e3e6f..a7a914627e 100644
@@ -2918,14 +2918,15 @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno,
                               uint16_t isel, target_ulong *val,
                               target_ulong new_val, target_ulong wr_mask)
 {
-    bool virt = csrno == CSR_VSIREG ? true : false;
+    bool virt = CSR_VSIREG <= csrno && csrno <= CSR_VSIREG6 &&
+                csrno != CSR_VSIREG4 - 1;
     int ret = -EINVAL;
 
     if (xiselect_cd_range(isel)) {
         ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask);
     } else if (xiselect_ctr_range(csrno, isel)) {
         ret = rmw_xireg_ctr(env, csrno, isel, val, new_val, wr_mask);
-    } else {
+    } else if (!xiselect_aia_range(isel)) {
         /*
          * As per the specification, access to unimplented region is undefined
          * but recommendation is to raise illegal instruction exception.
Signature · 1 line
2.56.1