55#include "debug/Checkpoint.hh"
56#include "debug/LLSC.hh"
57#include "debug/MatRegs.hh"
58#include "debug/RiscvMisc.hh"
59#include "debug/VecRegs.hh"
62#include "params/RiscvISA.hh"
71[[maybe_unused]]
const std::array<const char *, NUM_MISCREGS>
MiscRegNames = {{
283 "VLEN should be greater or equal",
284 "than ELEN. Ch. 2RISC-V vector spec.");
286 inform(
"RVV enabled, VLEN = %d bits, ELEN = %d bits",
338 misa.rvi = misa.rvm = misa.rva = misa.rvf = misa.rvd = misa.rvc = 1;
347 misa.rvu = misa.rvn = 1;
350 misa.rvs = misa.rvu = 1;
353 misa.rvs = misa.rvu = misa.rvn = 1;
356 panic(
"Privilege mode set config should not reach here");
399 if (hpmcounter < 0 || hpmcounter > 31)
400 panic(
"Illegal HPM counter %d\n", hpmcounter);
415 return (
miscRegFile[counteren] & (1ULL << (hpmcounter))) > 0;
423 DPRINTF(RiscvMisc,
"Reading MiscReg %s (%d): %#x.\n",
433 return tc->contextId();
436 DPRINTF(RiscvMisc,
"Cycle counter at: %llu.\n",
437 tc->getCpuPtr()->curCycle());
438 return static_cast<RegVal>(
tc->getCpuPtr()->curCycle());
440 warn(
"Cycle counter disabled.\n");
445 DPRINTF(RiscvMisc,
"Cycle counter at: %llu.\n",
446 tc->getCpuPtr()->curCycle());
449 warn(
"Cycle counter disabled.\n");
454 DPRINTF(RiscvMisc,
"Wall-clock counter at: %llu.\n",
458 warn(
"Wall clock disabled.\n");
463 DPRINTF(RiscvMisc,
"Wall-clock counter at: %llu.\n",
467 warn(
"Wall clock disabled.\n");
472 DPRINTF(RiscvMisc,
"Instruction counter at: %llu.\n",
473 tc->getCpuPtr()->totalInsts());
474 return static_cast<RegVal>(
tc->getCpuPtr()->totalInsts());
476 warn(
"Instruction counter disabled.\n");
481 DPRINTF(RiscvMisc,
"Instruction counter at: %llu.\n",
482 tc->getCpuPtr()->totalInsts());
485 warn(
"Instruction counter disabled.\n");
491 tc->getCpuPtr()->getInterruptController(
tc->threadId()));
508 tc->getCpuPtr()->getInterruptController(
tc->threadId()));
622 switch(nstatus.mnpp) {
628 nstatus.mnpp =
PRV_S;
654 DPRINTF(RiscvMisc,
"HPM counter %d: %llu.\n",
656 return tc->getCpuPtr()->curCycle();
664 DPRINTF(RiscvMisc,
"HPM counter %d: %llu.\n",
681 DPRINTF(RiscvMisc,
"Setting MiscReg %s (%d) to %#x.\n",
729 for (
int i=0;
i < regSize;
i++) {
731 uint8_t cfg_val = (
val >> (8*
i)) & 0xff;
738 bool result = mmu->getPMP()->pmpUpdateCfg(pmp_index,cfg_val);
740 res |= ((
RegVal)cfg_val << (8*
i));
742 res |= (old_val & (0xFF << (8*
i)));
757 if (mmu->getPMP()->pmpUpdateAddr(pmp_index,
val)) {
778 tc->getCpuPtr()->getInterruptController(
tc->threadId()));
803 tc->getCpuPtr()->getInterruptController(
tc->threadId()));
828 if (new_val.mode != AddrXlateMode::BARE &&
829 new_val.mode != AddrXlateMode::SV39)
830 new_val.mode = cur_val.mode;
837 SENVCFG panic_mask = 0;
840 SENVCFG wpri_mask = 0;
841 wpri_mask.wpri_1 = ~wpri_mask.wpri_1;
842 wpri_mask.wpri_2 = ~wpri_mask.wpri_2;
843 wpri_mask.wpri_3 = ~wpri_mask.wpri_3;
845 if ((panic_mask &
val) != 0) {
846 panic(
"Tried to write to an unimplemented bitfield in the "
847 "senvcfg CSR!\nThe attempted write was:\n %" PRIu64
"\n",
864 MISA new_misa = (MISA)
val;
867 if (new_misa.rvc == 0 &&
870 new_misa.rvc = new_misa.rvc | cur_misa.rvc;
875 new_misa.rvn = cur_misa.rvn;
876 new_misa.rvs = cur_misa.rvs;
877 new_misa.rvu = cur_misa.rvu;
954 NSTATUS nstatus =
val;
976 DPRINTF(Checkpoint,
"Serializing Riscv Misc Registers\n");
983 DPRINTF(Checkpoint,
"Unserializing Riscv Misc Registers\n");
995 DPRINTF(LLSC,
"Locked snoop on address %x.\n", snoop_addr);
996 if ((load_reservation_addr & cacheBlockMask) == snoop_addr)
1006 load_reservation_addr = req->getPaddr();
1007 DPRINTF(LLSC,
"[cid:%d]: Reserved address %x.\n",
1008 req->contextId(), req->getPaddr());
1022 DPRINTF(LLSC,
"[cid:%d]: load_reservation_addrs empty? %s.\n",
1024 lr_addr_empty ?
"yes" :
"no");
1025 if (!lr_addr_empty) {
1026 DPRINTF(LLSC,
"[cid:%d]: addr = %x.\n", req->contextId(),
1027 req->getPaddr() & cacheBlockMask);
1028 DPRINTF(LLSC,
"[cid:%d]: last locked addr = %x.\n", req->contextId(),
1029 load_reservation_addr & cacheBlockMask);
1031 if (lr_addr_empty ||
1032 (load_reservation_addr & cacheBlockMask)
1033 != ((req->getPaddr() & cacheBlockMask))) {
1034 req->setExtraData(0);
1035 int stCondFailures =
tc->readStCondFailures();
1036 tc->setStCondFailures(++stCondFailures);
1038 warn(
"%i: context %d: %d consecutive SC failures.\n",
1039 curTick(),
tc->contextId(), stCondFailures);
1047 if (req->isUncacheable()) {
1048 req->setExtraData(2);
1054 DPRINTF(LLSC,
"[cid:%d]: SC success! Current locked addr = %x.\n",
1055 req->contextId(), load_reservation_addr & cacheBlockMask);
1062 tc->getCpuPtr()->wakeup(
tc->threadId());
1076 auto vec =
tc->readMiscRegNoEffect(idx);
1078 if (intr &&
bits(
vec, 1, 0) == 1)
1091 return os <<
"PRV_U";
1093 return os <<
"PRV_S";
1095 return os <<
"PRV_M";
1097 return os <<
"PRV_<invalid>";
void serialize(CheckpointOut &cp) const override
Serialize an object.
BaseISA(const SimObjectParams &p, const std::string &name)
virtual std::string name() const
const bool _wfiResumeOnPending
The WFI instruction can halt the execution of a hart.
void setMiscReg(RegIndex idx, RegVal val) override
void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override
RegVal readMiscReg(RegIndex idx) override
void globalClearExclusive() override
void serialize(CheckpointOut &cp) const override
Serialize an object.
void resetThread() override
PrivilegeModeSet _privilegeModeSet
The combination of privilege modes in Privilege Levels section of RISC-V privileged spec.
Addr rvSext(Addr addr) const
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
RegVal readMiscRegNoEffect(RegIndex idx) const override
bool hpmCounterEnabled(int counter) const
unsigned elen
Length of each vector element in bits.
void copyRegsFrom(ThreadContext *src) override
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
unsigned vlen
Length of each vector register in bits.
bool getEnableRvv() const
bool _enableSmrnmi
Resumable non-maskable interrupt Set true to make NMI recoverable.
std::vector< RegVal > miscRegFile
bool inUserMode() const override
void unserialize(CheckpointIn &cp) override
Unserialize an object.
const Addr INVALID_RESERVATION_ADDR
bool _enableZcd
Enable Zcd extensions.
virtual Addr getFaultHandlerAddr(RegIndex idx, uint64_t cause, bool intr) const
unsigned getVecLenInBytes()
std::unordered_map< int, Addr > load_reservation_addrs
PrivilegeModeSet getPrivilegeModeSet()
void handleLockedRead(const RequestPtr &req) override
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal getReg(const RegId ®) const
virtual const PCStateBase & pcState() const =0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
constexpr T mbits(T val, unsigned first, unsigned last)
Mask off the given bits in place like bits() but without shifting.
#define panic(...)
This implements a cprintf based panic() function.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
#define UNSERIALIZE_CONTAINER(member)
#define SERIALIZE_CONTAINER(member)
constexpr RegClass matRegClass
constexpr RegClass vecElemClass
constexpr RegClass vecPredRegClass
constexpr RegClass ccRegClass
const RegVal SIDELEG_MASK[enums::Num_PrivilegeModeSet]
constexpr enums::RiscvType RV32
constexpr RegClass floatRegClass(FloatRegClass, FloatRegClassName, float_reg::NumRegs, debug::FloatRegs)
gem5::VecRegContainer< MaxVecLenInBytes > VecRegContainer
const RegVal MIP_MASK[enums::Num_PrivilegeModeSet]
const RegVal SSTATUS_MASKS[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
const RegVal STATUS_VS_MASK
const RegVal STATUS_SXL_MASK
const RegVal STATUS_UXL_MASK
const RegVal USTATUS_MASKS[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
const RegVal SIP_MASK[enums::Num_PrivilegeModeSet]
constexpr RegClass intRegClass(IntRegClass, IntRegClassName, int_reg::NumRegs, debug::IntRegs)
const std::array< const char *, NUM_MISCREGS > MiscRegNames
constexpr RegClass vecRegClass
constexpr enums::RiscvType RV64
const RegVal MI_MASK[enums::Num_PrivilegeModeSet]
const RegVal MIDELEG_MASK[enums::Num_PrivilegeModeSet]
const RegVal MSTATUS_MASKS[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
constexpr RegClass miscRegClass(MiscRegClass, MiscRegClassName, NUM_MISCREGS, debug::MiscRegs)
Copyright (c) 2024 Arm Limited All rights reserved.
std::shared_ptr< Request > RequestPtr
constexpr char CCRegClassName[]
constexpr char VecPredRegClassName[]
Tick curTick()
The universal simulation clock.
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
constexpr char MatRegClassName[]
@ MatRegClass
Matrix Register.
@ CCRegClass
Condition-code register.
@ VecElemClass
Vector Register Native Elem lane.
constexpr char VecElemClassName[]
Declaration of the Packet class.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
std::ostream & operator<<(std::ostream &os, gem5::RiscvISA::PrivilegeMode pm)