Nils Asmussen has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/25654 )

Change subject: arch-riscv: fault according to status.{TVM,TSK,TW}.
......................................................................

arch-riscv: fault according to status.{TVM,TSK,TW}.

Change-Id: I38dddadb3373d2156b8fc57eabff861a062021cf
---
M src/arch/riscv/isa/decoder.isa
M src/arch/riscv/isa/formats/standard.isa
2 files changed, 39 insertions(+), 7 deletions(-)



diff --git a/src/arch/riscv/isa/decoder.isa b/src/arch/riscv/isa/decoder.isa
index 41aa9c9..474e432 100644
--- a/src/arch/riscv/isa/decoder.isa
+++ b/src/arch/riscv/isa/decoder.isa
@@ -1779,13 +1779,16 @@
                     }
                     0x8: decode RS2 {
                         0x2: sret({{
-                            if (xc->readMiscReg(MISCREG_PRV) == PRV_U) {
+ STATUS status = xc->readMiscReg(MISCREG_STATUS);
+                            auto pm = (PrivilegeMode)xc->readMiscReg(
+                                MISCREG_PRV);
+                            if (pm == PRV_U ||
+                                (pm == PRV_S && status.tsr == 1)) {
                                 fault = make_shared<IllegalInstFault>(
-                                            "sret in user mode", machInst);
+ "sret in user mode or TSR enabled",
+                                            machInst);
                                 NPC = NPC;
                             } else {
-                                STATUS status = xc->readMiscReg(
-                                    MISCREG_STATUS);
                                 xc->setMiscReg(MISCREG_PRV, status.spp);
                                 status.sie = status.spie;
                                 status.spie = 1;
@@ -1794,11 +1797,27 @@
                                 NPC = xc->readMiscReg(MISCREG_SEPC);
                             }
                         }}, IsReturn);
-                           0x5: wfi({{
-                               // don't do anything for now
-                           }}, No_OpClass);
+                        0x5: wfi({{
+ STATUS status = xc->readMiscReg(MISCREG_STATUS);
+                            auto pm = (PrivilegeMode)xc->readMiscReg(
+                                MISCREG_PRV);
+                            if (pm == PRV_U ||
+                                (pm == PRV_S && status.tw == 1)) {
+                                fault = make_shared<IllegalInstFault>(
+ "wfi in user mode or TW enabled",
+                                            machInst);
+                            }
+                            // don't do anything for now
+                        }}, No_OpClass);
                     }
                     0x9: sfence_vma({{
+                        STATUS status = xc->readMiscReg(MISCREG_STATUS);
+ auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV); + if (pm == PRV_U || (pm == PRV_S && status.tvm == 1)) {
+                            fault = make_shared<IllegalInstFault>(
+ "sfence in user mode or TVM enabled",
+                                        machInst);
+                        }
                         xc->tcBase()->getITBPtr()->demapPage(Rs1, Rs2);
                         xc->tcBase()->getDTBPtr()->demapPage(Rs1, Rs2);
                     }}, IsNonSpeculative, IsSerializeAfter, No_OpClass);
diff --git a/src/arch/riscv/isa/formats/standard.isa b/src/arch/riscv/isa/formats/standard.isa
index 7ec9484..ea08165 100644
--- a/src/arch/riscv/isa/formats/standard.isa
+++ b/src/arch/riscv/isa/formats/standard.isa
@@ -305,6 +305,19 @@
             olddata = xc->readMiscReg(MISCREG_FFLAGS) |
                       (xc->readMiscReg(MISCREG_FRM) << FRM_OFFSET);
             break;
+          case CSR_SATP: {
+            auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV);
+            STATUS status = xc->readMiscReg(MISCREG_STATUS);
+            if (pm == PRV_U || (pm == PRV_S && status.tvm == 1)) {
+                std::string error = csprintf(
+                    "SATP access in user mode or with TVM enabled\n");
+                fault = make_shared<IllegalInstFault>(error, machInst);
+                olddata = 0;
+            }
+            else
+                olddata = xc->readMiscReg(CSRData.at(csr).physIndex);
+            break;
+          }
           case CSR_MSTATUS: {
             auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV);
             if (pm != PrivilegeMode::PRV_M) {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/25654
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I38dddadb3373d2156b8fc57eabff861a062021cf
Gerrit-Change-Number: 25654
Gerrit-PatchSet: 1
Gerrit-Owner: Nils Asmussen <nils.asmus...@barkhauseninstitut.org>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to