61 #include "etiss/jit/ReturnCode.h"
68 MMU::MMU(
bool hw_ptw, std::string name,
bool pid_enabled)
70 , mmu_control_reg_val_(0)
73 , pid_enabled_(pid_enabled)
74 , hw_page_table_walker_(hw_ptw)
76 tlb_ = std::shared_ptr<etiss::mm::TLB<0>>(
new TLB<0>());
104 std::pair<uint32_t, uint32_t> page_offset_bitfield =
109 uint32_t page_offset_msb_pos = page_offset_bitfield.first;
111 uint32_t ppn_msb_pos = ppn_bitfield.first;
114 uint64_t vpn = vma >> (page_offset_msb_pos + 1);
118 vpn |=
pid_ << (ppn_msb_pos + 1);
127 if ((fault =
tlb_->Lookup(vpn, &pte_buf)))
137 uint64_t offset_mask = (1 << (page_offset_msb_pos + 1)) - 1;
138 *pma_buf = (pte_buf.
GetPPN() << (page_offset_msb_pos + 1)) | (vma & offset_mask);
146 std::map<uint64_t, PTE *>::iterator itr =
tlb_entry_map_.find(*pma_buf);
161 tlb_->AddPTE(vpn, pte);
168 if (0 == control_reg_val_)
193 cout <<
"------------MMU Details-----------" << endl;
194 cout <<
"MMU name : " <<
name_ << endl;
195 cout <<
"MMU enabled: " << std::boolalpha <<
mmu_enabled_ << endl;
196 cout <<
"PID enabled: " << std::boolalpha <<
pid_enabled_ << endl;
198 cout <<
"Current PID : 0x" << std::hex <<
pid_ << endl;
227 return handled_fault;
234 return etiss::RETURNCODE::LOAD_PAGEFAULT;
236 return etiss::RETURNCODE::STORE_PAGEFAULT;
238 return etiss::RETURNCODE::INSTR_PAGEFAULT;
252 using namespace etiss;
262 "etiss::CPUCore::execute(). this should not happen and indicates a faultiy "
263 "CPUArch (or Plugin) implementation. This function may have been called "
264 "indirectly from ETISS_signalChangedRegisterValue()");
267 auto mmu = core->
getMMU();
269 mmu->SignalMMU(mmu_signal_);
defines main cpu core interface
void ETISS_SIGNAL_MMU(ETISS_CPU *cpu, etiss_uint64 mmu_signal_)
Modeling hardware memory management for virtual memory -> physical memory translation and protection.
#define DEFAULT_PAGE_TABLE_WALKER
#define REGISTER_PAGE_FAULT_HANDLER(fault, handler)
#define HANDLE_PAGE_FAULT(fault, mmu, vma, access)
static __inline__ uint32_t
static __inline__ uint64_t
static __inline__ int32_t
CPUCore is responsible for the simulation of a CPU core in ETISS.
virtual std::shared_ptr< etiss::mm::MMU > getMMU()
Get the Memory Management Unit(MMU) of this CPUCore instance.
int32_t AddTLBEntry(const uint64_t vfn, const PTE &pte)
virtual int32_t GetPid(uint64_t control_reg_val_)
virtual bool CheckPrivilegedMode()=0
MMU is enabled in certain mode.
std::string GetName() const
MMU(bool hw_ptw, std::string name, bool pid_enabled)
MMU ctor.
virtual int32_t WalkPageTable(uint64_t, MM_ACCESS)
Page table walking is required to translate virtual address to physical address if TLB miss occurs.
const bool hw_page_table_walker_
void SignalMMU(uint64_t control_reg_val_)
Whenever the MMU control register changes, the MMU has to be notified with the updated control regist...
void UpdatePid(uint32_t new_pid)
std::shared_ptr< etiss::mm::TLB< 0 > > tlb_
virtual int32_t CheckProtection(const PTE &, MM_ACCESS access)=0
Memory protection is architecture-dependent, which should be implemented with architecture model.
virtual void UpdatePTEFlags(PTE &, MM_ACCESS)
Reserved for some MMU that might update PTE when translating.
void AddTLBEntryMap(uint64_t phy_addr_, PTE &pte)
Keep a record of mapping between cached PTE with its physical address.
uint64_t mmu_control_reg_val_
bool HasPageTableWalker()
virtual int32_t Translate(const uint64_t vma, uint64_t *const pma_buf, MM_ACCESS access, uint64_t data=0)
Conduct the actual translation according to the format set by PTEFormatBuilder.
void Init(ETISS_CPU *cpu, ETISS_System *system)
Initialize the MMU, when DMMUWrapper is wrapping the MMU.
void Dump()
Dump the details of the MMU, when page fault cannot be handled.
std::map< uint64_t, PTE * > tlb_entry_map_
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
int32_t tlb_miss_handler(int32_t fault, MMU *mmu, uint64_t vma, MM_ACCESS access)
MM_EXPORT const int32_t TLBMISS
MM_EXPORT const int32_t NOERROR
MM_EXPORT const int32_t PTEOVERLAP
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
void log(Verbosity level, std::string msg)
write log message at the given level.
basic cpu state structure needed for execution of any cpu architecture.
void * _etiss_private_handle_
private helper handle for plugins
memory access and time synchronization functions.