gem5  v22.1.0.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gem5::PMP Class Reference

This class helps to implement RISCV's physical memory protection (pmp) primitive. More...

#include <pmp.hh>

Inheritance diagram for gem5::PMP:
gem5::SimObject gem5::EventManager gem5::Serializable gem5::Drainable gem5::statistics::Group gem5::Named

Classes

struct  PmpEntry
 single pmp entry struct More...
 

Public Member Functions

 PARAMS (PMP)
 
 PMP (const Params &params)
 
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. More...
 
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 corresponding pmp entry. More...
 
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 corresponding pmp entry. More...
 
- Public Member Functions inherited from gem5::SimObject
const Paramsparams () const
 
 SimObject (const Params &p)
 
virtual ~SimObject ()
 
virtual void init ()
 init() is called after all C++ SimObjects have been created and all ports are connected. More...
 
virtual void loadState (CheckpointIn &cp)
 loadState() is called on each SimObject when restoring from a checkpoint. More...
 
virtual void initState ()
 initState() is called on each SimObject when not restoring from a checkpoint. More...
 
virtual void regProbePoints ()
 Register probe points for this object. More...
 
virtual void regProbeListeners ()
 Register probe listeners for this object. More...
 
ProbeManagergetProbeManager ()
 Get the probe manager for this object. More...
 
virtual PortgetPort (const std::string &if_name, PortID idx=InvalidPortID)
 Get a port with a given name and index. More...
 
virtual void startup ()
 startup() is the final initialization call before simulation. More...
 
DrainState drain () override
 Provide a default implementation of the drain interface for objects that don't need draining. More...
 
virtual void memWriteback ()
 Write back dirty buffers to memory using functional writes. More...
 
virtual void memInvalidate ()
 Invalidate the contents of memory buffers. More...
 
void serialize (CheckpointOut &cp) const override
 Serialize an object. More...
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object. More...
 
- Public Member Functions inherited from gem5::EventManager
EventQueueeventQueue () const
 
void schedule (Event &event, Tick when)
 
void deschedule (Event &event)
 
void reschedule (Event &event, Tick when, bool always=false)
 
void schedule (Event *event, Tick when)
 
void deschedule (Event *event)
 
void reschedule (Event *event, Tick when, bool always=false)
 
void wakeupEventQueue (Tick when=(Tick) -1)
 This function is not needed by the usual gem5 event loop but may be necessary in derived EventQueues which host gem5 on other schedulers. More...
 
void setCurTick (Tick newVal)
 
 EventManager (EventManager &em)
 Event manger manages events in the event queue. More...
 
 EventManager (EventManager *em)
 
 EventManager (EventQueue *eq)
 
- Public Member Functions inherited from gem5::Serializable
 Serializable ()
 
virtual ~Serializable ()
 
void serializeSection (CheckpointOut &cp, const char *name) const
 Serialize an object into a new section. More...
 
void serializeSection (CheckpointOut &cp, const std::string &name) const
 
void unserializeSection (CheckpointIn &cp, const char *name)
 Unserialize an a child object. More...
 
void unserializeSection (CheckpointIn &cp, const std::string &name)
 
- Public Member Functions inherited from gem5::Drainable
DrainState drainState () const
 Return the current drain state of an object. More...
 
virtual void notifyFork ()
 Notify a child process of a fork. More...
 
- Public Member Functions inherited from gem5::statistics::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group. More...
 
virtual ~Group ()
 
virtual void regStats ()
 Callback to set stat parameters. More...
 
virtual void resetStats ()
 Callback to reset stats. More...
 
virtual void preDumpStats ()
 Callback before stats are dumped. More...
 
void addStat (statistics::Info *info)
 Register a stat with this group. More...
 
const std::map< std::string, Group * > & getStatGroups () const
 Get all child groups associated with this object. More...
 
const std::vector< Info * > & getStats () const
 Get all stats associated with this object. More...
 
void addStatGroup (const char *name, Group *block)
 Add a stat block as a child of this block. More...
 
const InforesolveStat (std::string name) const
 Resolve a stat by its name within this group. More...
 
void mergeStatGroup (Group *block)
 Merge the contents (stats & children) of a block to this block. More...
 
 Group ()=delete
 
 Group (const Group &)=delete
 
Groupoperator= (const Group &)=delete
 
- Public Member Functions inherited from gem5::Named
 Named (const std::string &name_)
 
virtual ~Named ()=default
 
virtual std::string name () const
 

Private Types

enum  pmpAmatch { PMP_OFF , PMP_TOR , PMP_NA4 , PMP_NAPOT }
 This enum is used for encoding of address matching mode of pmp address register, which is present in bits 3-4 (A) of pmpcfg register for a pmp entry. More...
 

Private Member Functions

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 this access. More...
 
Fault createAddrfault (Addr vaddr, BaseMMU::Mode mode)
 createAddrfault creates an address fault if the pmp checks fail to pass for a given access. More...
 
void pmpUpdateRule (uint32_t pmp_index)
 pmpUpdateRule updates the pmp rule for a given pmp entry depending on the value of pmpaddr and pmpcfg for that entry. More...
 
uint8_t pmpGetAField (uint8_t cfg)
 pmpGetAField extracts the A field (address matching mode) from an input pmpcfg register More...
 
AddrRange pmpDecodeNapot (Addr pmpaddr)
 This function decodes a pmpaddr register value into an address range when A field of pmpcfg register is set to NAPOT mode (naturally aligned power of two region). More...
 

Private Attributes

int pmpEntries
 maximum number of entries in the pmp table More...
 
const uint8_t PMP_READ = 1 << 0
 pmpcfg address range read permission mask More...
 
const uint8_t PMP_WRITE = 1 << 1
 pmpcfg address range write permission mask More...
 
const uint8_t PMP_EXEC = 1 << 2
 pmpcfg address range execute permission mask More...
 
const uint8_t PMP_LOCK = 1 << 7
 pmpcfg address range locked mask More...
 
int numRules
 variable to keep track of active number of rules any time More...
 
std::vector< PmpEntrypmpTable
 a table of pmp entries More...
 

Additional Inherited Members

- Public Types inherited from gem5::SimObject
typedef SimObjectParams Params
 
- Static Public Member Functions inherited from gem5::SimObject
static void serializeAll (const std::string &cpt_dir)
 Create a checkpoint by serializing all SimObjects in the system. More...
 
static SimObjectfind (const char *name)
 Find the SimObject with the given name and return a pointer to it. More...
 
static void setSimObjectResolver (SimObjectResolver *resolver)
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints. More...
 
static SimObjectResolvergetSimObjectResolver ()
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints. More...
 
- Static Public Member Functions inherited from gem5::Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section. More...
 
static void generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream)
 Generate a checkpoint file so that the serialization can be routed to it. More...
 
- Protected Member Functions inherited from gem5::Drainable
 Drainable ()
 
virtual ~Drainable ()
 
virtual void drainResume ()
 Resume execution after a successful drain. More...
 
void signalDrainDone () const
 Signal that an object is drained. More...
 
- Protected Attributes inherited from gem5::SimObject
const SimObjectParams & _params
 Cached copy of the object parameters. More...
 
- Protected Attributes inherited from gem5::EventManager
EventQueueeventq
 A pointer to this object's event queue. More...
 

Detailed Description

This class helps to implement RISCV's physical memory protection (pmp) primitive.

Todo:
Add statistics and debug prints.

Definition at line 53 of file pmp.hh.

Member Enumeration Documentation

◆ pmpAmatch

enum gem5::PMP::pmpAmatch
private

This enum is used for encoding of address matching mode of pmp address register, which is present in bits 3-4 (A) of pmpcfg register for a pmp entry.

PMP_OFF = null region (pmp disabled) MP_TOR = top of range mode PMP_NA4 = naturally aligned four byte region PMP_NAPOT = naturally aligned power of two region, >= 8 bytes

Enumerator
PMP_OFF 
PMP_TOR 
PMP_NA4 
PMP_NAPOT 

Definition at line 71 of file pmp.hh.

Constructor & Destructor Documentation

◆ PMP()

gem5::PMP::PMP ( const Params params)

Definition at line 47 of file pmp.cc.

References pmpEntries, and pmpTable.

Member Function Documentation

◆ createAddrfault()

Fault gem5::PMP::createAddrfault ( Addr  vaddr,
BaseMMU::Mode  mode 
)
private

createAddrfault creates an address fault if the pmp checks fail to pass for a given access.

This function is used by pmpCheck(). given pmp entry depending on the value of pmpaddr and pmpcfg for that entry.

Parameters
vaddrvirtual address of the access.
modemode of access(read, write, execute).
Returns
Fault.

Definition at line 130 of file pmp.cc.

References gem5::RiscvISA::INST_ACCESS, gem5::RiscvISA::LOAD_ACCESS, gem5::ArmISA::mode, gem5::BaseMMU::Read, gem5::RiscvISA::STORE_ACCESS, gem5::MipsISA::vaddr, warn, and gem5::BaseMMU::Write.

Referenced by pmpCheck().

◆ PARAMS()

gem5::PMP::PARAMS ( PMP  )

◆ pmpCheck()

Fault gem5::PMP::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.

Parameters
reqmemory request.
modemode of request (read, write, execute).
pmodecurrent privilege mode of execution (U, S, M).
tcthread context.
vaddroptional parameter to pass vaddr of original request for which a page table walk is consulted by pmp unit
Returns
Fault.

Definition at line 56 of file pmp.cc.

References gem5::AddrRange::contains(), createAddrfault(), DPRINTF, gem5::ArmISA::i, gem5::ArmISA::mode, gem5::NoFault, numRules, PMP_EXEC, PMP_OFF, PMP_READ, PMP_WRITE, pmpGetAField(), pmpTable, gem5::RiscvISA::PRV_M, shouldCheckPMP(), and gem5::MipsISA::vaddr.

◆ pmpDecodeNapot()

AddrRange gem5::PMP::pmpDecodeNapot ( Addr  pmpaddr)
inlineprivate

This function decodes a pmpaddr register value into an address range when A field of pmpcfg register is set to NAPOT mode (naturally aligned power of two region).

Parameters
pmpaddrinput address from a pmp entry.
Returns
an address range.

Definition at line 254 of file pmp.cc.

References gem5::X86ISA::base, gem5::ctz64(), gem5::mbits(), and gem5::ArmISA::t1.

Referenced by pmpUpdateRule().

◆ pmpGetAField()

uint8_t gem5::PMP::pmpGetAField ( uint8_t  cfg)
inlineprivate

pmpGetAField extracts the A field (address matching mode) from an input pmpcfg register

Parameters
cfgpmpcfg register value.
Returns
The A field.

Definition at line 145 of file pmp.cc.

References gem5::ArmISA::a.

Referenced by pmpCheck(), and pmpUpdateRule().

◆ pmpUpdateAddr()

void gem5::PMP::pmpUpdateAddr ( uint32_t  pmp_index,
Addr  this_addr 
)

pmpUpdateAddr updates the pmpaddr for a pmp entry and calls pmpUpdateRule to update the rule of corresponding pmp entry.

Parameters
pmp_indexpmp entry index.
this_addrvalue to be written to pmpaddr.

Definition at line 216 of file pmp.cc.

References DPRINTF, gem5::MipsISA::index, pmpEntries, pmpTable, and pmpUpdateRule().

◆ pmpUpdateCfg()

void gem5::PMP::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 corresponding pmp entry.

Parameters
pmp_indexpmp entry index.
this_cfgvalue to be written to pmpcfg.

Definition at line 154 of file pmp.cc.

References DPRINTF, PMP_LOCK, pmpTable, pmpUpdateRule(), and warn_if.

◆ pmpUpdateRule()

void gem5::PMP::pmpUpdateRule ( uint32_t  pmp_index)
private

pmpUpdateRule updates the pmp rule for a given pmp entry depending on the value of pmpaddr and pmpcfg for that entry.

Parameters
pmp_indexpmp entry index.

Definition at line 167 of file pmp.cc.

References gem5::ArmISA::i, numRules, PMP_NA4, PMP_NAPOT, PMP_OFF, PMP_TOR, pmpDecodeNapot(), pmpEntries, pmpGetAField(), and pmpTable.

Referenced by pmpUpdateAddr(), and pmpUpdateCfg().

◆ shouldCheckPMP()

bool gem5::PMP::shouldCheckPMP ( RiscvISA::PrivilegeMode  pmode,
BaseMMU::Mode  mode,
ThreadContext tc 
)
private

This function is called during a memory access to determine if the pmp table should be consulted for this access.

Parameters
pmodecurrent privilege mode of execution (U, S, M).
modemode of request (read, write, execute).
tcthread context.
Returns
true or false.

Definition at line 231 of file pmp.cc.

References gem5::BaseMMU::Execute, gem5::RiscvISA::MISCREG_STATUS, gem5::ArmISA::mode, gem5::RiscvISA::PRV_M, gem5::ThreadContext::readMiscRegNoEffect(), and gem5::ArmISA::status.

Referenced by pmpCheck().

Member Data Documentation

◆ numRules

int gem5::PMP::numRules
private

variable to keep track of active number of rules any time

Definition at line 92 of file pmp.hh.

Referenced by pmpCheck(), and pmpUpdateRule().

◆ PMP_EXEC

const uint8_t gem5::PMP::PMP_EXEC = 1 << 2
private

pmpcfg address range execute permission mask

Definition at line 86 of file pmp.hh.

Referenced by pmpCheck().

◆ PMP_LOCK

const uint8_t gem5::PMP::PMP_LOCK = 1 << 7
private

pmpcfg address range locked mask

Definition at line 89 of file pmp.hh.

Referenced by pmpUpdateCfg().

◆ PMP_READ

const uint8_t gem5::PMP::PMP_READ = 1 << 0
private

pmpcfg address range read permission mask

Definition at line 80 of file pmp.hh.

Referenced by pmpCheck().

◆ PMP_WRITE

const uint8_t gem5::PMP::PMP_WRITE = 1 << 1
private

pmpcfg address range write permission mask

Definition at line 83 of file pmp.hh.

Referenced by pmpCheck().

◆ pmpEntries

int gem5::PMP::pmpEntries
private

maximum number of entries in the pmp table

Definition at line 61 of file pmp.hh.

Referenced by PMP(), pmpUpdateAddr(), and pmpUpdateRule().

◆ pmpTable

std::vector<PmpEntry> gem5::PMP::pmpTable
private

a table of pmp entries

Definition at line 106 of file pmp.hh.

Referenced by PMP(), pmpCheck(), pmpUpdateAddr(), pmpUpdateCfg(), and pmpUpdateRule().


The documentation for this class was generated from the following files:

Generated on Wed Dec 21 2022 10:23:11 for gem5 by doxygen 1.9.1