gem5 v24.0.0.0
Loading...
Searching...
No Matches
tlb.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * Copyright (c) 2007 MIPS Technologies, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "arch/mips/tlb.hh"
31
32#include <string>
33#include <vector>
34
35#include "arch/mips/faults.hh"
38#include "arch/mips/utility.hh"
39#include "base/inifile.hh"
40#include "base/str.hh"
41#include "base/trace.hh"
42#include "cpu/thread_context.hh"
43#include "debug/MipsPRA.hh"
44#include "debug/TLB.hh"
45#include "mem/page_table.hh"
46#include "params/MipsTLB.hh"
47#include "sim/process.hh"
48
49namespace gem5
50{
51
52using namespace MipsISA;
53
55//
56// MIPS TLB
57//
58
59TLB::TLB(const Params &p) : BaseTLB(p), size(p.size), nlu(0)
60{
61 table = new PTE[size];
62 memset(table, 0, sizeof(PTE[size]));
63 smallPages = 0;
64}
65
66TLB::~TLB()
67{
68 delete [] table;
69}
70
71// look up an entry in the TLB
72MipsISA::PTE *
73TLB::lookup(Addr vpn, uint8_t asn) const
74{
75 // assume not found...
76 PTE *retval = NULL;
77 PageTable::const_iterator i = lookupTable.find(vpn);
78 if (i != lookupTable.end()) {
79 while (i->first == vpn) {
80 int index = i->second;
81 PTE *pte = &table[index];
82
83 /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
84 Addr Mask = pte->Mask;
85 Addr InvMask = ~Mask;
86 Addr VPN = pte->VPN;
87 if (((vpn & InvMask) == (VPN & InvMask)) &&
88 (pte->G || (asn == pte->asid))) {
89 // We have a VPN + ASID Match
90 retval = pte;
91 break;
92 }
93 ++i;
94 }
95 }
96
97 DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
98 retval ? "hit" : "miss", retval ? retval->PFN1 : 0);
99 return retval;
100}
101
103TLB::getEntry(unsigned Index) const
104{
105 // Make sure that Index is valid
106 assert(Index<size);
107 return &table[Index];
108}
109
110int
111TLB::probeEntry(Addr vpn, uint8_t asn) const
112{
113 // assume not found...
114 int Ind = -1;
115 PageTable::const_iterator i = lookupTable.find(vpn);
116 if (i != lookupTable.end()) {
117 while (i->first == vpn) {
118 int index = i->second;
119 PTE *pte = &table[index];
120
121 /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
122 Addr Mask = pte->Mask;
123 Addr InvMask = ~Mask;
124 Addr VPN = pte->VPN;
125 if (((vpn & InvMask) == (VPN & InvMask)) &&
126 (pte->G || (asn == pte->asid))) {
127 // We have a VPN + ASID Match
128 Ind = index;
129 break;
130 }
131 ++i;
132 }
133 }
134 DPRINTF(MipsPRA,"VPN: %x, asid: %d, Result of TLBP: %d\n",vpn,asn,Ind);
135 return Ind;
136}
137
138inline Fault
139TLB::checkCacheability(const RequestPtr &req)
140{
141 Addr VAddrUncacheable = 0xA0000000;
142 // In MIPS, cacheability is controlled by certain bits of the virtual
143 // address or by the TLB entry
144 if ((req->getVaddr() & VAddrUncacheable) == VAddrUncacheable) {
145 // mark request as uncacheable
146 req->setFlags(Request::UNCACHEABLE | Request::STRICT_ORDER);
147 }
148 return NoFault;
149}
150
151void
152TLB::insertAt(PTE &pte, unsigned Index, int _smallPages)
153{
154 smallPages = _smallPages;
155 if (Index > size) {
156 warn("Attempted to write at index (%d) beyond TLB size (%d)",
157 Index, size);
158 } else {
159 // Update TLB
160 DPRINTF(TLB, "TLB[%d]: %x %x %x %x\n",
161 Index, pte.Mask << 11,
162 ((pte.VPN << 11) | pte.asid),
163 ((pte.PFN0 << 6) | (pte.C0 << 3) |
164 (pte.D0 << 2) | (pte.V0 <<1) | pte.G),
165 ((pte.PFN1 <<6) | (pte.C1 << 3) |
166 (pte.D1 << 2) | (pte.V1 <<1) | pte.G));
167 if (table[Index].V0 || table[Index].V1) {
168 // Previous entry is valid
169 PageTable::iterator i = lookupTable.find(table[Index].VPN);
170 lookupTable.erase(i);
171 }
172 table[Index]=pte;
173 // Update fast lookup table
174 lookupTable.insert(std::make_pair(table[Index].VPN, Index));
175 }
176}
177
178// insert a new TLB entry
179void
180TLB::insert(Addr addr, PTE &pte)
181{
182 fatal("TLB Insert not yet implemented\n");
183}
184
185void
186TLB::flushAll()
187{
188 DPRINTF(TLB, "flushAll\n");
189 memset(table, 0, sizeof(PTE[size]));
190 lookupTable.clear();
191 nlu = 0;
192}
193
194void
195TLB::serialize(CheckpointOut &cp) const
196{
197 SERIALIZE_SCALAR(size);
198 SERIALIZE_SCALAR(nlu);
199
200 for (int i = 0; i < size; i++) {
201 ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
202 table[i].serialize(cp);
203 }
204}
205
206void
207TLB::unserialize(CheckpointIn &cp)
208{
209 UNSERIALIZE_SCALAR(size);
211
212 for (int i = 0; i < size; i++) {
213 ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
214 table[i].unserialize(cp);
215 if (table[i].V0 || table[i].V1) {
216 lookupTable.insert(std::make_pair(table[i].VPN, i));
217 }
218 }
219}
220
221Fault
222TLB::translateAtomic(const RequestPtr &req, ThreadContext *tc,
223 BaseMMU::Mode mode)
224{
225 panic_if(FullSystem, "translateAtomic not implemented in full system.");
226 return tc->getProcessPtr()->pTable->translate(req);
227}
228
229void
230TLB::translateTiming(const RequestPtr &req, ThreadContext *tc,
231 BaseMMU::Translation *translation, BaseMMU::Mode mode)
232{
233 assert(translation);
234 translation->finish(translateAtomic(req, tc, mode), req, tc, mode);
235}
236
237Fault
238TLB::translateFunctional(const RequestPtr &req, ThreadContext *tc,
239 BaseMMU::Mode mode)
240{
241 panic_if(FullSystem, "translateAtomic not implemented in full system.");
242 return tc->getProcessPtr()->pTable->translate(req);
243}
244
245Fault
246TLB::finalizePhysical(const RequestPtr &req,
247 ThreadContext *tc, BaseMMU::Mode mode) const
248{
249 return NoFault;
250}
251
252
254TLB::index(bool advance)
255{
256 PTE *pte = &table[nlu];
257
258 if (advance)
259 nextnlu();
260
261 return *pte;
262}
263
264} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
TLB(const Params &p)
Definition tlb.cc:61
virtual void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode)=0
bool translate(Addr vaddr, Addr &paddr)
Translate function.
EmulationPageTable * pTable
Definition process.hh:184
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual Process * getProcessPtr()=0
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Declaration of IniFile object.
#define warn(...)
Definition logging.hh:256
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 30, 0 > index
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition root.cc:220
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
constexpr decltype(nullptr) NoFault
Definition types.hh:253
Declarations of a non-full system Page Table.
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0