tlb.cc (8925:97f06a79b6f5) tlb.cc (8953:488d45aeb672)
1/*
2 * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 46 unchanged lines hidden (view full) ---

55#include "mem/packet_access.hh"
56#include "mem/page_table.hh"
57#include "mem/request.hh"
58#include "sim/full_system.hh"
59#include "sim/process.hh"
60
61namespace X86ISA {
62
1/*
2 * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 46 unchanged lines hidden (view full) ---

55#include "mem/packet_access.hh"
56#include "mem/page_table.hh"
57#include "mem/request.hh"
58#include "sim/full_system.hh"
59#include "sim/process.hh"
60
61namespace X86ISA {
62
63TLB::TLB(const Params *p) : BaseTLB(p), configAddress(0), size(p->size)
63TLB::TLB(const Params *p) : BaseTLB(p), configAddress(0), size(p->size),
64 lruSeq(0)
64{
65{
66 if (!size)
67 fatal("TLBs must have a non-zero size.\n");
65 tlb = new TlbEntry[size];
66 std::memset(tlb, 0, sizeof(TlbEntry) * size);
67
68 tlb = new TlbEntry[size];
69 std::memset(tlb, 0, sizeof(TlbEntry) * size);
70
68 for (int x = 0; x < size; x++)
71 for (int x = 0; x < size; x++) {
72 tlb[x].trieHandle = NULL;
69 freeList.push_back(&tlb[x]);
73 freeList.push_back(&tlb[x]);
74 }
70
71 walker = p->walker;
72 walker->setTLB(this);
73}
74
75
76 walker = p->walker;
77 walker->setTLB(this);
78}
79
80void
81TLB::evictLRU()
82{
83 // Find the entry with the lowest (and hence least recently updated)
84 // sequence number.
85
86 unsigned lru = 0;
87 for (unsigned i = 1; i < size; i++) {
88 if (tlb[i].lruSeq < tlb[lru].lruSeq)
89 lru = i;
90 }
91
92 assert(tlb[lru].trieHandle);
93 trie.remove(tlb[lru].trieHandle);
94 tlb[lru].trieHandle = NULL;
95 freeList.push_back(&tlb[lru]);
96}
97
75TlbEntry *
76TLB::insert(Addr vpn, TlbEntry &entry)
77{
78 //TODO Deal with conflicting entries
79
80 TlbEntry *newEntry = NULL;
98TlbEntry *
99TLB::insert(Addr vpn, TlbEntry &entry)
100{
101 //TODO Deal with conflicting entries
102
103 TlbEntry *newEntry = NULL;
81 if (!freeList.empty()) {
82 newEntry = freeList.front();
83 freeList.pop_front();
84 } else {
85 newEntry = entryList.back();
86 entryList.pop_back();
87 }
104 if (freeList.empty())
105 evictLRU();
106 newEntry = freeList.front();
107 freeList.pop_front();
108
88 *newEntry = entry;
109 *newEntry = entry;
110 newEntry->lruSeq = nextSeq();
89 newEntry->vaddr = vpn;
111 newEntry->vaddr = vpn;
90 entryList.push_front(newEntry);
112 newEntry->trieHandle =
113 trie.insert(vpn, TlbEntryTrie::MaxBits - entry.logBytes, newEntry);
91 return newEntry;
92}
93
114 return newEntry;
115}
116
94TLB::EntryList::iterator
95TLB::lookupIt(Addr va, bool update_lru)
96{
97 //TODO make this smarter at some point
98 EntryList::iterator entry;
99 for (entry = entryList.begin(); entry != entryList.end(); entry++) {
100 if ((*entry)->vaddr <= va && (*entry)->vaddr + (*entry)->size > va) {
101 DPRINTF(TLB, "Matched vaddr %#x to entry starting at %#x "
102 "with size %#x.\n", va, (*entry)->vaddr, (*entry)->size);
103 if (update_lru) {
104 entryList.push_front(*entry);
105 entryList.erase(entry);
106 entry = entryList.begin();
107 }
108 break;
109 }
110 }
111 return entry;
112}
113
114TlbEntry *
115TLB::lookup(Addr va, bool update_lru)
116{
117TlbEntry *
118TLB::lookup(Addr va, bool update_lru)
119{
117 EntryList::iterator entry = lookupIt(va, update_lru);
118 if (entry == entryList.end())
119 return NULL;
120 else
121 return *entry;
120 TlbEntry *entry = trie.lookup(va);
121 if (entry && update_lru)
122 entry->lruSeq = nextSeq();
123 return entry;
122}
123
124void
125TLB::invalidateAll()
126{
127 DPRINTF(TLB, "Invalidating all entries.\n");
124}
125
126void
127TLB::invalidateAll()
128{
129 DPRINTF(TLB, "Invalidating all entries.\n");
128 while (!entryList.empty()) {
129 TlbEntry *entry = entryList.front();
130 entryList.pop_front();
131 freeList.push_back(entry);
130 for (unsigned i = 0; i < size; i++) {
131 if (tlb[i].trieHandle) {
132 trie.remove(tlb[i].trieHandle);
133 tlb[i].trieHandle = NULL;
134 freeList.push_back(&tlb[i]);
135 }
132 }
133}
134
135void
136TLB::setConfigAddress(uint32_t addr)
137{
138 configAddress = addr;
139}
140
141void
142TLB::invalidateNonGlobal()
143{
144 DPRINTF(TLB, "Invalidating all non global entries.\n");
136 }
137}
138
139void
140TLB::setConfigAddress(uint32_t addr)
141{
142 configAddress = addr;
143}
144
145void
146TLB::invalidateNonGlobal()
147{
148 DPRINTF(TLB, "Invalidating all non global entries.\n");
145 EntryList::iterator entryIt;
146 for (entryIt = entryList.begin(); entryIt != entryList.end();) {
147 if (!(*entryIt)->global) {
148 freeList.push_back(*entryIt);
149 entryList.erase(entryIt++);
150 } else {
151 entryIt++;
149 for (unsigned i = 0; i < size; i++) {
150 if (tlb[i].trieHandle && !tlb[i].global) {
151 trie.remove(tlb[i].trieHandle);
152 tlb[i].trieHandle = NULL;
153 freeList.push_back(&tlb[i]);
152 }
153 }
154}
155
156void
157TLB::demapPage(Addr va, uint64_t asn)
158{
154 }
155 }
156}
157
158void
159TLB::demapPage(Addr va, uint64_t asn)
160{
159 EntryList::iterator entry = lookupIt(va, false);
160 if (entry != entryList.end()) {
161 freeList.push_back(*entry);
162 entryList.erase(entry);
161 TlbEntry *entry = trie.lookup(va);
162 if (entry) {
163 trie.remove(entry->trieHandle);
164 entry->trieHandle = NULL;
165 freeList.push_back(entry);
163 }
164}
165
166Fault
167TLB::translateInt(RequestPtr req, ThreadContext *tc)
168{
169 DPRINTF(TLB, "Addresses references internal memory.\n");
170 Addr vaddr = req->getVaddr();

--- 169 unchanged lines hidden (view full) ---

340 return new PageFault(vaddr, true, mode, inUser, false);
341 }
342 if (storeCheck && badWrite) {
343 // This would fault if this were a write, so return a page
344 // fault that reflects that happening.
345 return new PageFault(vaddr, true, Write, inUser, false);
346 }
347
166 }
167}
168
169Fault
170TLB::translateInt(RequestPtr req, ThreadContext *tc)
171{
172 DPRINTF(TLB, "Addresses references internal memory.\n");
173 Addr vaddr = req->getVaddr();

--- 169 unchanged lines hidden (view full) ---

343 return new PageFault(vaddr, true, mode, inUser, false);
344 }
345 if (storeCheck && badWrite) {
346 // This would fault if this were a write, so return a page
347 // fault that reflects that happening.
348 return new PageFault(vaddr, true, Write, inUser, false);
349 }
350
348 Addr paddr = entry->paddr | (vaddr & (entry->size-1));
351 Addr paddr = entry->paddr | (vaddr & mask(entry->logBytes));
349 DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, paddr);
350 req->setPaddr(paddr);
351 if (entry->uncacheable)
352 req->setFlags(Request::UNCACHEABLE);
353 } else {
354 //Use the address which already has segmentation applied.
355 DPRINTF(TLB, "Paging disabled.\n");
356 DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, vaddr);

--- 90 unchanged lines hidden ---
352 DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, paddr);
353 req->setPaddr(paddr);
354 if (entry->uncacheable)
355 req->setFlags(Request::UNCACHEABLE);
356 } else {
357 //Use the address which already has segmentation applied.
358 DPRINTF(TLB, "Paging disabled.\n");
359 DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, vaddr);

--- 90 unchanged lines hidden ---