54 #include "debug/TLB.hh"
67 fatal(
"TLBs must have a non-zero size.\n");
69 for (
int x = 0;
x <
size;
x++) {
70 tlb[
x].trieHandle = NULL;
85 for (
unsigned i = 1;
i <
size;
i++) {
92 tlb[lru].trieHandle = NULL;
102 assert(newEntry->vaddr == vpn);
114 newEntry->vaddr = vpn;
115 newEntry->trieHandle =
124 if (entry && update_lru)
133 for (
unsigned i = 0;
i <
size;
i++) {
136 tlb[
i].trieHandle = NULL;
151 DPRINTF(
TLB,
"Invalidating all non global entries.\n");
152 for (
unsigned i = 0;
i <
size;
i++) {
155 tlb[
i].trieHandle = NULL;
167 entry->trieHandle = NULL;
175 DPRINTF(
TLB,
"Addresses references internal memory.\n");
179 panic(
"CPUID memory space not yet implemented!\n");
186 return std::make_shared<GeneralProtection>(0);
200 assert(!(IOPort & ~0xFFFF));
201 if (IOPort == 0xCF8 && req->
getSize() == 4) {
204 }
else if ((IOPort & ~
mask(2)) == 0xCFC) {
208 if (
bits(configAddress, 31, 31)) {
210 mbits(configAddress, 30, 2) |
221 panic(
"Access to unrecognized internal address space %#x.\n",
231 AddrRange m5opRange(0xFFFF0000, 0xFFFFFFFF);
240 LocalApicBase localApicBase =
243 (localApicBase.base + 1) *
PageBytes - 1);
260 paddr - apicRange.
start()));
269 Mode mode,
bool &delayedResponse,
bool timing)
275 delayedResponse =
false;
284 DPRINTF(
TLB,
"Translating vaddr %#x.\n", vaddr);
292 if (m5Reg.mode != LongMode) {
293 DPRINTF(
TLB,
"Not in long mode. Checking segment protection.\n");
298 return std::make_shared<GeneralProtection>(0);
302 if (!attr.writable && (mode ==
Write || storeCheck))
303 return std::make_shared<GeneralProtection>(0);
304 if (!attr.readable && mode ==
Read)
305 return std::make_shared<GeneralProtection>(0);
306 expandDown = attr.expandDown;
312 unsigned logSize = sizeOverride ? (unsigned)m5Reg.altAddr
313 : (
unsigned)m5Reg.defAddr;
314 int size = (1 << logSize) * 8;
318 DPRINTF(
TLB,
"Checking an expand down segment.\n");
319 warn_once(
"Expand down segments are untested.\n");
320 if (offset <= limit || endOffset <= limit)
321 return std::make_shared<GeneralProtection>(0);
323 if (offset > limit || endOffset > limit)
324 return std::make_shared<GeneralProtection>(0);
338 if (timing || fault !=
NoFault) {
340 delayedResponse =
true;
347 "address %#x at pc %#x.\n",
352 bool success = p->pTable->lookup(vaddr, newEntry);
353 if (!success && mode !=
Execute) {
355 if (p->fixupStackFault(vaddr)) {
357 success = p->pTable->lookup(vaddr, newEntry);
361 return std::make_shared<PageFault>(
vaddr,
true,
mode,
364 Addr alignedVaddr = p->pTable->pageAlign(vaddr);
365 DPRINTF(
TLB,
"Mapping %#x to %#x\n", alignedVaddr,
366 newEntry.pageStart());
367 entry =
insert(alignedVaddr, newEntry);
374 "doing protection checks.\n", entry->paddr);
376 bool inUser = (m5Reg.cpl == 3 &&
379 bool badWrite = (!entry->writable && (inUser || cr0.wp));
380 if ((inUser && !entry->user) || (mode ==
Write && badWrite)) {
384 return std::make_shared<PageFault>(
vaddr,
true,
mode, inUser,
387 if (storeCheck && badWrite) {
390 return std::make_shared<PageFault>(
vaddr,
true,
Write, inUser,
394 Addr paddr = entry->paddr | (vaddr &
mask(entry->logBytes));
395 DPRINTF(
TLB,
"Translated %#x -> %#x.\n", vaddr, paddr);
397 if (entry->uncacheable)
402 DPRINTF(
TLB,
"Translated %#x -> %#x.\n", vaddr, vaddr);
408 DPRINTF(
TLB,
"Translated %#x -> %#x.\n", vaddr, vaddr);
418 bool delayedResponse;
419 return TLB::translate(req, tc, NULL, mode, delayedResponse,
false);
426 bool delayedResponse;
429 TLB::translate(req, tc, translation, mode, delayedResponse,
true);
430 if (!delayedResponse)
431 translation->
finish(fault, req, tc, mode);
437 panic(
"Not implemented\n");
456 for (uint32_t
x = 0;
x <
size;
x++) {
458 tlb[
x].serializeSection(cp,
csprintf(
"Entry%d", _count++));
469 fatal(
"TLB size less than the one in checkpoint!");
474 for (uint32_t
x = 0;
x < _size;
x++) {
478 newEntry->unserializeSection(cp,
csprintf(
"Entry%d",
x));
479 newEntry->trieHandle =
trie.
insert(newEntry->vaddr,
493 X86TLBParams::create()
const Addr PhysAddrPrefixPciConfig
Handle insert(Key key, unsigned width, Value *val)
Method which inserts a key/value pair into the trie.
virtual Addr instAddr()=0
decltype(nullptr) constexpr NoFault
Addr start() const
Get the start address of the range.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void setConfigAddress(uint32_t addr)
std::vector< TlbEntry > tlb
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
static const unsigned MaxBits
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
virtual Process * getProcessPtr()=0
const Addr IntAddrPrefixCPUID
bool contains(const Addr &a) const
Determine if the range contains an address.
Bitfield< 14 > expandDown
ThreadContext is the external interface to all thread state for anything outside of the CPU...
BaseMasterPort * getMasterPort() override
Get the table walker master port.
TlbEntry * insert(Addr vpn, TlbEntry &entry)
const Addr IntAddrPrefixMask
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Addr iprAddressPseudoInst(uint8_t func, uint8_t subfunc)
Generate a generic IPR address that emulates a pseudo inst.
#define UNSERIALIZE_SCALAR(scalar)
std::string csprintf(const char *format, const Args &...args)
static MiscRegIndex MISCREG_SEG_ATTR(int index)
static MiscRegIndex MISCREG_SEG_LIMIT(int index)
Value * lookup(Key key)
Method which looks up the Value corresponding to a particular key.
The request is to an uncacheable address.
Fault start(ThreadContext *_tc, BaseTLB::Translation *translation, RequestPtr req, BaseTLB::Mode mode)
TlbEntry(Addr asn, Addr _vaddr, Addr _paddr, bool uncacheable, bool read_only)
Fault translate(RequestPtr req, ThreadContext *tc, Translation *translation, Mode mode, bool &delayedResponse, bool timing)
Fault translateInt(RequestPtr req, ThreadContext *tc)
const Addr IntAddrPrefixMSR
TlbEntryTrie::Handle trieHandle
static MiscRegIndex MISCREG_SEG_SEL(int index)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
const Request::FlagsType M5_VAR_USED SegmentFlagMask
const Addr IntAddrPrefixIO
#define SERIALIZE_SCALAR(scalar)
bool msrAddrToIndex(MiscRegIndex ®Num, Addr addr)
Find and return the misc reg corresponding to an MSR address.
void flushAll() override
Remove all entries from the TLB.
Flags getFlags()
Accessor for flags.
Value * remove(Handle handle)
Method to delete a value from the trie.
TlbEntry * lookup(Addr va, bool update_lru=true)
Declarations of a non-full system Page Table.
static MiscRegIndex MISCREG_SEG_BASE(int index)
void translateTiming(RequestPtr req, ThreadContext *tc, Translation *translation, Mode mode)
BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a master port with a given name and index.
Fault translateFunctional(RequestPtr req, ThreadContext *tc, Mode mode)
Stub function for compilation support of CheckerCPU.
std::ostream CheckpointOut
EndBitUnion(PageTableEntry) struct TlbEntry Addr vaddr
void serialize(CheckpointOut &cp) const override
Serialize an object.
void demapPage(Addr va, uint64_t asn) override
ISA-generic helper functions for memory mapped IPR accesses.
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
virtual int contextId() const =0
The request is required to be strictly ordered by CPU models and is non-speculative.
const Addr PhysAddrPrefixIO
T mbits(T val, int first, int last)
Mask off the given bits in place like bits() but without shifting.
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
This request is to a memory mapped register.
The request should be handled by the generic IPR code (only valid together with MMAPPED_IPR) ...
static Addr x86LocalAPICAddress(const uint8_t id, const uint16_t addr)
void setPaddr(Addr paddr)
Set just the physical address.
Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode)
virtual void finish(const Fault &fault, RequestPtr req, ThreadContext *tc, Mode mode)=0
void setFlags(Flags flags)
Note that unlike other accessors, this function sets specific flags (ORs them in); it does not assign...
std::shared_ptr< FaultBase > Fault
Fault finalizePhysical(RequestPtr req, ThreadContext *tc, Mode mode) const
Do post-translation physical address finalization.