54#include "debug/Checkpoint.hh"
55#include "debug/LLSC.hh"
56#include "debug/MatRegs.hh"
57#include "debug/RiscvMisc.hh"
58#include "debug/VecRegs.hh"
61#include "params/RiscvISA.hh"
70[[maybe_unused]]
const std::array<const char *, NUM_MISCREGS>
MiscRegNames = {{
260 _rvType(
p.riscv_type), enableRvv(
p.enable_rvv), vlen(
p.vlen), elen(
p.elen),
261 _privilegeModeSet(
p.privilege_mode_set)
273 "VLEN should be greater or equal",
274 "than ELEN. Ch. 2RISC-V vector spec.");
276 inform(
"RVV enabled, VLEN = %d bits, ELEN = %d bits",
328 misa.rvi = misa.rvm = misa.rva = misa.rvf = misa.rvd = misa.rvc = 1;
337 misa.rvu = misa.rvn = 1;
340 misa.rvs = misa.rvu = 1;
343 misa.rvs = misa.rvu = misa.rvn = 1;
346 panic(
"Privilege mode set config should not reach here");
390 if (hpmcounter < 0 || hpmcounter > 31)
391 panic(
"Illegal HPM counter %d\n", hpmcounter);
406 return (
miscRegFile[counteren] & (1ULL << (hpmcounter))) > 0;
414 DPRINTF(RiscvMisc,
"Reading MiscReg %s (%d): %#x.\n",
427 DPRINTF(RiscvMisc,
"Cycle counter at: %llu.\n",
431 warn(
"Cycle counter disabled.\n");
436 DPRINTF(RiscvMisc,
"Cycle counter at: %llu.\n",
440 warn(
"Cycle counter disabled.\n");
445 DPRINTF(RiscvMisc,
"Wall-clock counter at: %llu.\n",
449 warn(
"Wall clock disabled.\n");
454 DPRINTF(RiscvMisc,
"Wall-clock counter at: %llu.\n",
458 warn(
"Wall clock disabled.\n");
463 DPRINTF(RiscvMisc,
"Instruction counter at: %llu.\n",
467 warn(
"Instruction counter disabled.\n");
472 DPRINTF(RiscvMisc,
"Instruction counter at: %llu.\n",
476 warn(
"Instruction counter disabled.\n");
616 DPRINTF(RiscvMisc,
"HPM counter %d: %llu.\n",
626 DPRINTF(RiscvMisc,
"HPM counter %d: %llu.\n",
643 DPRINTF(RiscvMisc,
"Setting MiscReg %s (%d) to %#x.\n",
691 for (
int i=0;
i < regSize;
i++) {
693 uint8_t cfg_val = (
val >> (8*
i)) & 0xff;
700 bool result = mmu->getPMP()->pmpUpdateCfg(pmp_index,cfg_val);
702 res |= ((
RegVal)cfg_val << (8*
i));
704 res |= (old_val & (0xFF << (8*
i)));
719 if (mmu->getPMP()->pmpUpdateAddr(pmp_index,
val)) {
775 if (new_val.mode != AddrXlateMode::BARE &&
776 new_val.mode != AddrXlateMode::SV39)
777 new_val.mode = cur_val.mode;
791 MISA new_misa = (MISA)
val;
794 if (new_misa.rvc == 0 &&
797 new_misa.rvc = new_misa.rvc | cur_misa.rvc;
802 new_misa.rvn = cur_misa.rvn;
803 new_misa.rvs = cur_misa.rvs;
804 new_misa.rvu = cur_misa.rvu;
819 val &= ~STATUS_VS_MASK;
890 DPRINTF(Checkpoint,
"Serializing Riscv Misc Registers\n");
897 DPRINTF(Checkpoint,
"Unserializing Riscv Misc Registers\n");
909 DPRINTF(LLSC,
"Locked snoop on address %x.\n", snoop_addr);
910 if ((load_reservation_addr & cacheBlockMask) == snoop_addr)
920 load_reservation_addr = req->getPaddr();
921 DPRINTF(LLSC,
"[cid:%d]: Reserved address %x.\n",
922 req->contextId(), req->getPaddr());
936 DPRINTF(LLSC,
"[cid:%d]: load_reservation_addrs empty? %s.\n",
938 lr_addr_empty ?
"yes" :
"no");
939 if (!lr_addr_empty) {
940 DPRINTF(LLSC,
"[cid:%d]: addr = %x.\n", req->contextId(),
941 req->getPaddr() & cacheBlockMask);
942 DPRINTF(LLSC,
"[cid:%d]: last locked addr = %x.\n", req->contextId(),
943 load_reservation_addr & cacheBlockMask);
946 (load_reservation_addr & cacheBlockMask)
947 != ((req->getPaddr() & cacheBlockMask))) {
948 req->setExtraData(0);
952 warn(
"%i: context %d: %d consecutive SC failures.\n",
961 if (req->isUncacheable()) {
962 req->setExtraData(2);
968 DPRINTF(LLSC,
"[cid:%d]: SC success! Current locked addr = %x.\n",
969 req->contextId(), load_reservation_addr & cacheBlockMask);
992 if (intr &&
bits(
vec, 1, 0) == 1)
1005 return os <<
"PRV_U";
1007 return os <<
"PRV_S";
1009 return os <<
"PRV_M";
1011 return os <<
"PRV_<invalid>";
BaseInterrupts * getInterruptController(ThreadID tid)
virtual Counter totalInsts() const =0
virtual void wakeup(ThreadID tid)=0
void serialize(CheckpointOut &cp) const override
Serialize an object.
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
virtual std::string name() const
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
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
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
RegVal readMiscRegNoEffect(RegIndex idx) const override
bool hpmCounterEnabled(int counter) const
void copyRegsFrom(ThreadContext *src) override
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
bool getEnableRvv() const
std::vector< RegVal > miscRegFile
bool inUserMode() const override
void unserialize(CheckpointIn &cp) override
Unserialize an object.
const Addr INVALID_RESERVATION_ADDR
virtual Addr getFaultHandlerAddr(RegIndex idx, uint64_t cause, bool intr) const
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 void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
virtual BaseCPU * getCpuPtr()=0
virtual void setReg(const RegId ®, RegVal val)
virtual void setStCondFailures(unsigned sc_failures)=0
virtual unsigned readStCondFailures() const =0
virtual const PCStateBase & pcState() const =0
virtual int threadId() const =0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
virtual BaseMMU * getMMUPtr()=0
virtual ContextID contextId() const =0
Vector Register Abstraction This generic class is the model in a particularization of MVC,...
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 intRegClass
constexpr RegClass vecPredRegClass
constexpr RegClass ccRegClass
constexpr RegClass miscRegClass
const RegVal UI_MASK[enums::Num_PrivilegeModeSet]
const RegVal SI_MASK[enums::Num_PrivilegeModeSet]
constexpr enums::RiscvType RV32
const RegVal SSTATUS_MASKS[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
const RegVal STATUS_SXL_MASK
const RegVal STATUS_UXL_MASK
const RegVal USTATUS_MASKS[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
const std::array< const char *, NUM_MISCREGS > MiscRegNames
constexpr RegClass vecRegClass
constexpr enums::RiscvType RV64
const RegVal MI_MASK[enums::Num_PrivilegeModeSet]
const RegVal MSTATUS_MASKS[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
constexpr RegClass floatRegClass
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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)