53 #include "debug/TLB.hh" 62 :
BaseTLB(p), configAddress(0), size(p->size),
63 tlb(size), lruSeq(0), m5opRange(p->
system->m5opRange())
66 fatal(
"TLBs must have a non-zero size.\n");
68 for (
int x = 0;
x <
size;
x++) {
69 tlb[
x].trieHandle = NULL;
84 for (
unsigned i = 1;
i <
size;
i++) {
89 assert(
tlb[lru].trieHandle);
91 tlb[lru].trieHandle = NULL;
101 assert(newEntry->
vaddr == vpn);
113 newEntry->
vaddr = vpn;
123 if (entry && update_lru)
132 for (
unsigned i = 0;
i <
size;
i++) {
133 if (
tlb[
i].trieHandle) {
135 tlb[
i].trieHandle = NULL;
150 DPRINTF(
TLB,
"Invalidating all non global entries.\n");
151 for (
unsigned i = 0;
i <
size;
i++) {
152 if (
tlb[
i].trieHandle && !
tlb[
i].global) {
154 tlb[
i].trieHandle = NULL;
174 DPRINTF(
TLB,
"Addresses references internal memory.\n");
178 panic(
"CPUID memory space not yet implemented!\n");
185 return std::make_shared<GeneralProtection>(0);
199 assert(!(IOPort & ~0xFFFF));
200 if (IOPort == 0xCF8 && req->getSize() == 4) {
203 }
else if ((IOPort & ~
mask(2)) == 0xCFC) {
207 if (
bits(configAddress, 31, 31)) {
209 mbits(configAddress, 30, 2) |
220 panic(
"Access to unrecognized internal address space %#x.\n",
229 Addr paddr = req->getPaddr();
235 LocalApicBase localApicBase =
255 paddr - apicRange.
start()));
265 Mode mode,
bool &delayedResponse,
bool timing)
271 delayedResponse =
false;
280 DPRINTF(
TLB,
"Translating vaddr %#x.\n", vaddr);
288 if (m5Reg.mode != LongMode) {
289 DPRINTF(
TLB,
"Not in long mode. Checking segment protection.\n");
294 return std::make_shared<GeneralProtection>(0);
298 if (!attr.writable && (mode ==
Write || storeCheck))
299 return std::make_shared<GeneralProtection>(0);
300 if (!attr.readable && mode ==
Read)
301 return std::make_shared<GeneralProtection>(0);
302 expandDown = attr.expandDown;
308 unsigned logSize = sizeOverride ? (unsigned)m5Reg.altAddr
309 : (
unsigned)m5Reg.defAddr;
310 int size = (1 << logSize) * 8;
312 Addr endOffset = offset + req->getSize() - 1;
314 DPRINTF(
TLB,
"Checking an expand down segment.\n");
315 warn_once(
"Expand down segments are untested.\n");
316 if (offset <= limit || endOffset <= limit)
317 return std::make_shared<GeneralProtection>(0);
319 if (offset > limit || endOffset > limit)
320 return std::make_shared<GeneralProtection>(0);
338 "address %#x at pc %#x.\n",
347 if (timing || fault !=
NoFault) {
349 delayedResponse =
true;
366 return std::make_shared<PageFault>(
vaddr,
true,
mode,
370 DPRINTF(
TLB,
"Mapping %#x to %#x\n", alignedVaddr,
382 "doing protection checks.\n", entry->
paddr);
384 bool inUser = (m5Reg.cpl == 3 &&
387 bool badWrite = (!entry->
writable && (inUser || cr0.wp));
388 if ((inUser && !entry->
user) || (mode ==
Write && badWrite)) {
392 return std::make_shared<PageFault>(
vaddr,
true,
mode, inUser,
395 if (storeCheck && badWrite) {
398 return std::make_shared<PageFault>(
vaddr,
true,
Write, inUser,
403 DPRINTF(
TLB,
"Translated %#x -> %#x.\n", vaddr, paddr);
404 req->setPaddr(paddr);
410 DPRINTF(
TLB,
"Translated %#x -> %#x.\n", vaddr, vaddr);
411 req->setPaddr(vaddr);
416 DPRINTF(
TLB,
"Translated %#x -> %#x.\n", vaddr, vaddr);
417 req->setPaddr(vaddr);
426 bool delayedResponse;
427 return TLB::translate(req, tc, NULL, mode, delayedResponse,
false);
434 bool delayedResponse;
437 TLB::translate(req, tc, translation, mode, delayedResponse,
true);
438 if (!delayedResponse)
439 translation->
finish(fault, req, tc, mode);
453 using namespace Stats;
457 .
desc(
"TLB accesses on read requests");
461 .
desc(
"TLB accesses on write requests");
465 .
desc(
"TLB misses on read requests");
469 .
desc(
"TLB misses on write requests");
482 for (uint32_t
x = 0;
x <
size;
x++) {
483 if (
tlb[
x].trieHandle != NULL)
484 tlb[
x].serializeSection(cp,
csprintf(
"Entry%d", _count++));
495 fatal(
"TLB size less than the one in checkpoint!");
500 for (uint32_t
x = 0;
x < _size;
x++) {
519 X86TLBParams::create()
#define panic(...)
This implements a cprintf based panic() function.
const Addr PhysAddrPrefixPciConfig
The request is to an uncacheable address.
Ports are used to interface objects to each other.
Handle insert(Key key, unsigned width, Value *val)
Method which inserts a key/value pair into the trie.
decltype(nullptr) constexpr NoFault
#define fatal(...)
This implements a cprintf based fatal() function.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void setConfigAddress(uint32_t addr)
Port * getTableWalkerPort() override
Get the table walker port.
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
std::vector< TlbEntry > tlb
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
bool contains(const Addr &a) const
Determine if the range contains an address.
std::shared_ptr< Request > RequestPtr
virtual void markDelayed()=0
Signal that the translation has been delayed due to a hw page table walk.
static const unsigned MaxBits
Fault start(ThreadContext *_tc, BaseTLB::Translation *translation, const RequestPtr &req, BaseTLB::Mode mode)
The request is required to be strictly ordered by CPU models and is non-speculative.
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
virtual Process * getProcessPtr()=0
virtual void regStats()
Callback to set stat parameters.
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Do post-translation physical address finalization.
const Addr IntAddrPrefixCPUID
Bitfield< 14 > expandDown
Fault translate(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode, bool &delayedResponse, bool timing)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
const Addr IntAddrPrefixMask
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
#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)
TlbEntryTrie::Handle trieHandle
void regStats() override
Callback to set stat parameters.
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Value * lookup(Key key)
Method which looks up the Value corresponding to a particular key.
const Addr IntAddrPrefixMSR
virtual void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, Mode mode)=0
This request is to a memory mapped register.
virtual Addr instAddr() const =0
static MiscRegIndex MISCREG_SEG_SEL(int index)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
virtual const std::string name() const
const Request::FlagsType M5_VAR_USED SegmentFlagMask
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
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.
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
bool fixupStackFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
Value * remove(Handle handle)
Method to delete a value from the trie.
BitfieldType< SegDescriptorLimit > limit
TlbEntry * lookup(Addr va, bool update_lru=true)
EmulationPageTable * pTable
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
Declarations of a non-full system Page Table.
static MiscRegIndex MISCREG_SEG_BASE(int index)
std::ostream CheckpointOut
void serialize(CheckpointOut &cp) const override
Serialize an object.
This is exposed globally, independent of the ISA.
Fault translateInt(const RequestPtr &req, ThreadContext *tc)
void demapPage(Addr va, uint64_t asn) override
virtual ContextID contextId() const =0
const Entry * lookup(Addr vaddr)
Lookup function.
const Addr PhysAddrPrefixIO
Addr start() const
Get the start address of the range.
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
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...
static Addr x86LocalAPICAddress(const uint8_t id, const uint16_t addr)
std::shared_ptr< FaultBase > Fault
TlbEntry * insert(Addr vpn, const TlbEntry &entry)