diff --git a/src/arch/riscv/pmp.cc b/src/arch/riscv/pmp.cc index 6275104062..8fa1ca3cdb 100644 --- a/src/arch/riscv/pmp.cc +++ b/src/arch/riscv/pmp.cc @@ -59,7 +59,7 @@ PMP::pmpCheck(const RequestPtr &req, BaseMMU::Mode mode, Addr vaddr) { // First determine if pmp table should be consulted - if (!shouldCheckPMP(pmode, mode, tc)) + if (!shouldCheckPMP(pmode, tc)) return NoFault; if (req->hasVaddr()) { @@ -71,9 +71,6 @@ PMP::pmpCheck(const RequestPtr &req, BaseMMU::Mode mode, req->getPaddr()); } - if (numRules == 0) - return NoFault; - // match_index will be used to identify the pmp entry // which matched for the given address int match_index = -1; @@ -273,26 +270,14 @@ PMP::pmpUpdateAddr(uint32_t pmp_index, Addr this_addr) } bool -PMP::shouldCheckPMP(RiscvISA::PrivilegeMode pmode, - BaseMMU::Mode mode, ThreadContext *tc) +PMP::shouldCheckPMP(RiscvISA::PrivilegeMode pmode, ThreadContext *tc) { - // instruction fetch in S and U mode - bool cond1 = (mode == BaseMMU::Execute && - (pmode != RiscvISA::PrivilegeMode::PRV_M)); - - // data access in S and U mode when MPRV in mstatus is clear - RiscvISA::STATUS status = - tc->readMiscRegNoEffect(RiscvISA::MISCREG_STATUS); - bool cond2 = (mode != BaseMMU::Execute && - (pmode != RiscvISA::PrivilegeMode::PRV_M) - && (!status.mprv)); - - // data access in any mode when MPRV bit in mstatus is set - // and the MPP field in mstatus is S or U - bool cond3 = (mode != BaseMMU::Execute && (status.mprv) - && (status.mpp != RiscvISA::PrivilegeMode::PRV_M)); - - return (cond1 || cond2 || cond3 || hasLockEntry); + // The privilege mode of memory read and write + // is modified by TLB. It can just simply check if + // the numRule is not zero, then return true if + // privilege mode is not M or has any lock entry + return numRules != 0 && ( + pmode != RiscvISA::PrivilegeMode::PRV_M || hasLockEntry); } AddrRange diff --git a/src/arch/riscv/pmp.hh b/src/arch/riscv/pmp.hh index 24cb4ad1ca..ff8c4fc1b9 100644 --- a/src/arch/riscv/pmp.hh +++ b/src/arch/riscv/pmp.hh @@ -118,7 +118,7 @@ class PMP : public SimObject * is allowed based on the pmp rules. * @param req memory request. * @param mode mode of request (read, write, execute). - * @param pmode current privilege mode of execution (U, S, M). + * @param pmode current privilege mode of memory (U, S, M). * @param tc thread context. * @param vaddr optional parameter to pass vaddr of original * request for which a page table walk is consulted by pmp unit @@ -159,13 +159,11 @@ class PMP : public SimObject * This function is called during a memory * access to determine if the pmp table * should be consulted for this access. - * @param pmode current privilege mode of execution (U, S, M). - * @param mode mode of request (read, write, execute). + * @param pmode current privilege mode of memory (U, S, M). * @param tc thread context. * @return true or false. */ - bool shouldCheckPMP(RiscvISA::PrivilegeMode pmode, - BaseMMU::Mode mode, ThreadContext *tc); + bool shouldCheckPMP(RiscvISA::PrivilegeMode pmode, ThreadContext *tc); /** * createAddrfault creates an address fault