38 #include "debug/PMP.hh"
41 #include "params/PMP.hh"
49 pmpEntries(params.pmp_entries),
64 if (req->hasVaddr()) {
65 DPRINTF(
PMP,
"Checking pmp permissions for va: %#x , pa: %#x\n",
66 req->getVaddr(), req->getPaddr());
69 DPRINTF(
PMP,
"Checking pmp permissions for pa: %#x\n",
87 if (pmp_range.
contains(req->getPaddr()) &&
88 pmp_range.
contains(req->getPaddr() + req->getSize())) {
95 if ((match_index > -1)
101 allowed_privs &=
pmpTable[match_index].pmpCfg;
103 if ((
mode == BaseMMU::Mode::Read) &&
106 }
else if ((
mode == BaseMMU::Mode::Write) &&
109 }
else if ((
mode == BaseMMU::Mode::Execute) &&
113 if (req->hasVaddr()) {
122 if (req->hasVaddr()) {
140 warn(
"pmp access fault.\n");
141 return std::make_shared<RiscvISA::AddressFault>(
vaddr, code);
148 uint8_t
a = cfg >> 3;
156 DPRINTF(
PMP,
"Update pmp config with %u for pmp entry: %u \n",
157 (
unsigned)this_cfg, pmp_index);
159 warn_if((
PMP_LOCK & this_cfg),
"pmp lock feature is not supported.\n");
161 pmpTable[pmp_index].pmpCfg = this_cfg;
175 if (pmp_index >= 1) {
176 prevAddr =
pmpTable[pmp_index - 1].rawAddr;
180 uint8_t this_cfg =
pmpTable[pmp_index].pmpCfg;
191 this_range =
AddrRange(prevAddr << 2, (this_addr << 2) - 1);
195 this_range =
AddrRange(this_addr << 2, (this_addr + 4) - 1);
205 pmpTable[pmp_index].pmpAddr = this_range;
218 DPRINTF(
PMP,
"Update pmp addr %#x for pmp entry %u \n",
219 this_addr, pmp_index);
224 pmpTable[pmp_index].rawAddr = this_addr;
250 return (cond1 || cond2 || cond3);
261 uint64_t range = (std::pow(2,
t1+3))-1;
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
This class helps to implement RISCV's physical memory protection (pmp) primitive.
const uint8_t PMP_LOCK
pmpcfg address range locked mask
const uint8_t PMP_WRITE
pmpcfg address range write permission mask
int pmpEntries
maximum number of entries in the pmp table
PMP(const Params ¶ms)
void pmpUpdateRule(uint32_t pmp_index)
pmpUpdateRule updates the pmp rule for a given pmp entry depending on the value of pmpaddr and pmpcfg...
const uint8_t PMP_READ
pmpcfg address range read permission mask
int numRules
variable to keep track of active number of rules any time
AddrRange pmpDecodeNapot(Addr pmpaddr)
This function decodes a pmpaddr register value into an address range when A field of pmpcfg register ...
std::vector< PmpEntry > pmpTable
a table of pmp entries
void pmpUpdateAddr(uint32_t pmp_index, Addr this_addr)
pmpUpdateAddr updates the pmpaddr for a pmp entry and calls pmpUpdateRule to update the rule of corre...
Fault createAddrfault(Addr vaddr, BaseMMU::Mode mode)
createAddrfault creates an address fault if the pmp checks fail to pass for a given access.
void pmpUpdateCfg(uint32_t pmp_index, uint8_t this_cfg)
pmpUpdateCfg updates the pmpcfg for a pmp entry and calls pmpUpdateRule to update the rule of corresp...
uint8_t pmpGetAField(uint8_t cfg)
pmpGetAField extracts the A field (address matching mode) from an input pmpcfg register
const uint8_t PMP_EXEC
pmpcfg address range execute permission mask
Fault pmpCheck(const RequestPtr &req, BaseMMU::Mode mode, RiscvISA::PrivilegeMode pmode, ThreadContext *tc, Addr vaddr=0)
pmpCheck checks if a particular memory access is allowed based on the pmp rules.
bool shouldCheckPMP(RiscvISA::PrivilegeMode pmode, BaseMMU::Mode mode, ThreadContext *tc)
This function is called during a memory access to determine if the pmp table should be consulted for ...
Abstract superclass for simulation objects.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
bool contains(const Addr &a) const
Determine if the range contains an address.
constexpr T mbits(T val, unsigned first, unsigned last)
Mask off the given bits in place like bits() but without shifting.
constexpr int ctz64(uint64_t value)
Count trailing zeros in a 64-bit value.
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
std::shared_ptr< Request > RequestPtr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
constexpr decltype(nullptr) NoFault
Declaration of a request, the overall memory request consisting of the parts of the request that are ...