gem5 v24.0.0.0
Loading...
Searching...
No Matches
gem5::RiscvISA::PMP Class Reference

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

#include <pmp.hh>

Inheritance diagram for gem5::RiscvISA::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, PrivilegeMode pmode, ThreadContext *tc, Addr vaddr=0)
 pmpCheck checks if a particular memory access is allowed based on the pmp rules.
 
bool 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.
 
bool 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.
 
void pmpReset ()
 pmpReset reset when reset signal in trigger from CPU.
 
- 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.
 
virtual void loadState (CheckpointIn &cp)
 loadState() is called on each SimObject when restoring from a checkpoint.
 
virtual void initState ()
 initState() is called on each SimObject when not restoring from a checkpoint.
 
virtual void regProbePoints ()
 Register probe points for this object.
 
virtual void regProbeListeners ()
 Register probe listeners for this object.
 
ProbeManagergetProbeManager ()
 Get the probe manager for this object.
 
virtual PortgetPort (const std::string &if_name, PortID idx=InvalidPortID)
 Get a port with a given name and index.
 
virtual void startup ()
 startup() is the final initialization call before simulation.
 
DrainState drain () override
 Provide a default implementation of the drain interface for objects that don't need draining.
 
virtual void memWriteback ()
 Write back dirty buffers to memory using functional writes.
 
virtual void memInvalidate ()
 Invalidate the contents of memory buffers.
 
void serialize (CheckpointOut &cp) const override
 Serialize an object.
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object.
 
- 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.
 
void setCurTick (Tick newVal)
 
 EventManager (EventManager &em)
 Event manger manages events in the event queue.
 
 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.
 
void serializeSection (CheckpointOut &cp, const std::string &name) const
 
void unserializeSection (CheckpointIn &cp, const char *name)
 Unserialize an a child object.
 
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.
 
virtual void notifyFork ()
 Notify a child process of a fork.
 
- Public Member Functions inherited from gem5::statistics::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group.
 
virtual ~Group ()
 
virtual void regStats ()
 Callback to set stat parameters.
 
virtual void resetStats ()
 Callback to reset stats.
 
virtual void preDumpStats ()
 Callback before stats are dumped.
 
void addStat (statistics::Info *info)
 Register a stat with this group.
 
const std::map< std::string, Group * > & getStatGroups () const
 Get all child groups associated with this object.
 
const std::vector< Info * > & getStats () const
 Get all stats associated with this object.
 
void addStatGroup (const char *name, Group *block)
 Add a stat block as a child of this block.
 
const InforesolveStat (std::string name) const
 Resolve a stat by its name within this group.
 
void mergeStatGroup (Group *block)
 Merge the contents (stats & children) of a block to this block.
 
 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 (PrivilegeMode pmode, ThreadContext *tc)
 This function is called during a memory access to determine if the pmp table should be consulted for this access.
 
Fault createAddrfault (Addr vaddr, BaseMMU::Mode mode)
 createAddrfault creates an address fault if the pmp checks fail to pass for a given access.
 
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.
 
uint8_t pmpGetAField (uint8_t cfg)
 pmpGetAField extracts the A field (address matching mode) from an input pmpcfg register
 
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).
 

Private Attributes

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

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

Detailed Description

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

Todo
Add statistics and debug prints.

Definition at line 57 of file pmp.hh.

Member Enumeration Documentation

◆ pmpAmatch

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 75 of file pmp.hh.

Constructor & Destructor Documentation

◆ PMP()

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

Definition at line 50 of file pmp.cc.

References pmpEntries, and pmpTable.

Member Function Documentation

◆ createAddrfault()

Fault gem5::RiscvISA::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 128 of file pmp.cc.

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

Referenced by pmpCheck().

◆ PARAMS()

gem5::RiscvISA::PMP::PARAMS ( PMP )

◆ pmpCheck()

Fault gem5::RiscvISA::PMP::pmpCheck ( const RequestPtr & req,
BaseMMU::Mode mode,
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 memory (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 60 of file pmp.cc.

References gem5::AddrRange::contains(), createAddrfault(), DPRINTF, gem5::BaseMMU::Execute, gem5::RiscvISA::i, gem5::RiscvISA::mode, gem5::NoFault, PMP_EXEC, PMP_LOCK, PMP_OFF, PMP_READ, PMP_WRITE, pmpGetAField(), pmpTable, gem5::RiscvISA::PRV_M, gem5::BaseMMU::Read, shouldCheckPMP(), gem5::RiscvISA::vaddr, and gem5::BaseMMU::Write.

◆ pmpDecodeNapot()

AddrRange gem5::RiscvISA::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 285 of file pmp.cc.

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

Referenced by pmpUpdateRule().

◆ pmpGetAField()

uint8_t gem5::RiscvISA::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 143 of file pmp.cc.

References gem5::RiscvISA::a.

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

◆ pmpReset()

void gem5::RiscvISA::PMP::pmpReset ( )

pmpReset reset when reset signal in trigger from CPU.

Definition at line 229 of file pmp.cc.

References gem5::RiscvISA::i, PMP_A_MASK, PMP_LOCK, pmpTable, and pmpUpdateRule().

◆ pmpUpdateAddr()

bool gem5::RiscvISA::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.
Returns
true if update pmpaddri success

Definition at line 238 of file pmp.cc.

References DPRINTF, gem5::RiscvISA::index, PMP_LOCK, PMP_TOR, pmpEntries, pmpGetAField(), pmpTable, and pmpUpdateRule().

◆ pmpUpdateCfg()

bool gem5::RiscvISA::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.
Returns
true if update pmpicfg success

Definition at line 152 of file pmp.cc.

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

◆ pmpUpdateRule()

void gem5::RiscvISA::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 174 of file pmp.cc.

References DPRINTF, hasLockEntry, gem5::RiscvISA::i, numRules, PMP_LOCK, PMP_NA4, PMP_NAPOT, PMP_OFF, PMP_TOR, pmpDecodeNapot(), pmpEntries, pmpGetAField(), and pmpTable.

Referenced by pmpReset(), pmpUpdateAddr(), and pmpUpdateCfg().

◆ shouldCheckPMP()

bool gem5::RiscvISA::PMP::shouldCheckPMP ( PrivilegeMode pmode,
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 memory (U, S, M).
tcthread context.
Returns
true or false.

Definition at line 275 of file pmp.cc.

References hasLockEntry, numRules, and gem5::RiscvISA::PRV_M.

Referenced by pmpCheck().

Member Data Documentation

◆ hasLockEntry

bool gem5::RiscvISA::PMP::hasLockEntry
private

variable to keep track of any lock of entry

Definition at line 102 of file pmp.hh.

Referenced by pmpUpdateRule(), and shouldCheckPMP().

◆ numRules

int gem5::RiscvISA::PMP::numRules
private

variable to keep track of active number of rules any time

Definition at line 99 of file pmp.hh.

Referenced by pmpUpdateRule(), and shouldCheckPMP().

◆ PMP_A_MASK

const uint8_t gem5::RiscvISA::PMP::PMP_A_MASK = 3 << 3
private

pmpcfg A field mask

Definition at line 93 of file pmp.hh.

Referenced by pmpReset().

◆ PMP_EXEC

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

pmpcfg address range execute permission mask

Definition at line 90 of file pmp.hh.

Referenced by pmpCheck().

◆ PMP_LOCK

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

pmpcfg address range locked mask

Definition at line 96 of file pmp.hh.

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

◆ PMP_READ

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

pmpcfg address range read permission mask

Definition at line 84 of file pmp.hh.

Referenced by pmpCheck().

◆ PMP_WRITE

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

pmpcfg address range write permission mask

Definition at line 87 of file pmp.hh.

Referenced by pmpCheck().

◆ pmpEntries

int gem5::RiscvISA::PMP::pmpEntries
private

maximum number of entries in the pmp table

Definition at line 65 of file pmp.hh.

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

◆ pmpTable

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

a table of pmp entries

Definition at line 116 of file pmp.hh.

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


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

Generated on Tue Jun 18 2024 16:24:21 for gem5 by doxygen 1.11.0