gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
36 #include "arch/mips/pagetable.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 
49 using namespace MipsISA;
50 
52 //
53 // MIPS TLB
54 //
55 
56 TLB::TLB(const Params &p) : BaseTLB(p), size(p.size), nlu(0)
57 {
58  table = new PTE[size];
59  memset(table, 0, sizeof(PTE[size]));
60  smallPages = 0;
61 }
62 
64 {
65  delete [] table;
66 }
67 
68 // look up an entry in the TLB
70 TLB::lookup(Addr vpn, uint8_t asn) const
71 {
72  // assume not found...
73  PTE *retval = NULL;
74  PageTable::const_iterator i = lookupTable.find(vpn);
75  if (i != lookupTable.end()) {
76  while (i->first == vpn) {
77  int index = i->second;
78  PTE *pte = &table[index];
79 
80  /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
81  Addr Mask = pte->Mask;
82  Addr InvMask = ~Mask;
83  Addr VPN = pte->VPN;
84  if (((vpn & InvMask) == (VPN & InvMask)) &&
85  (pte->G || (asn == pte->asid))) {
86  // We have a VPN + ASID Match
87  retval = pte;
88  break;
89  }
90  ++i;
91  }
92  }
93 
94  DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
95  retval ? "hit" : "miss", retval ? retval->PFN1 : 0);
96  return retval;
97 }
98 
100 TLB::getEntry(unsigned Index) const
101 {
102  // Make sure that Index is valid
103  assert(Index<size);
104  return &table[Index];
105 }
106 
107 int
108 TLB::probeEntry(Addr vpn, uint8_t asn) const
109 {
110  // assume not found...
111  int Ind = -1;
112  PageTable::const_iterator i = lookupTable.find(vpn);
113  if (i != lookupTable.end()) {
114  while (i->first == vpn) {
115  int index = i->second;
116  PTE *pte = &table[index];
117 
118  /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
119  Addr Mask = pte->Mask;
120  Addr InvMask = ~Mask;
121  Addr VPN = pte->VPN;
122  if (((vpn & InvMask) == (VPN & InvMask)) &&
123  (pte->G || (asn == pte->asid))) {
124  // We have a VPN + ASID Match
125  Ind = index;
126  break;
127  }
128  ++i;
129  }
130  }
131  DPRINTF(MipsPRA,"VPN: %x, asid: %d, Result of TLBP: %d\n",vpn,asn,Ind);
132  return Ind;
133 }
134 
135 inline Fault
137 {
138  Addr VAddrUncacheable = 0xA0000000;
139  // In MIPS, cacheability is controlled by certain bits of the virtual
140  // address or by the TLB entry
141  if ((req->getVaddr() & VAddrUncacheable) == VAddrUncacheable) {
142  // mark request as uncacheable
144  }
145  return NoFault;
146 }
147 
148 void
149 TLB::insertAt(PTE &pte, unsigned Index, int _smallPages)
150 {
151  smallPages = _smallPages;
152  if (Index > size) {
153  warn("Attempted to write at index (%d) beyond TLB size (%d)",
154  Index, size);
155  } else {
156  // Update TLB
157  DPRINTF(TLB, "TLB[%d]: %x %x %x %x\n",
158  Index, pte.Mask << 11,
159  ((pte.VPN << 11) | pte.asid),
160  ((pte.PFN0 << 6) | (pte.C0 << 3) |
161  (pte.D0 << 2) | (pte.V0 <<1) | pte.G),
162  ((pte.PFN1 <<6) | (pte.C1 << 3) |
163  (pte.D1 << 2) | (pte.V1 <<1) | pte.G));
164  if (table[Index].V0 || table[Index].V1) {
165  // Previous entry is valid
166  PageTable::iterator i = lookupTable.find(table[Index].VPN);
167  lookupTable.erase(i);
168  }
169  table[Index]=pte;
170  // Update fast lookup table
171  lookupTable.insert(std::make_pair(table[Index].VPN, Index));
172  }
173 }
174 
175 // insert a new TLB entry
176 void
178 {
179  fatal("TLB Insert not yet implemented\n");
180 }
181 
182 void
184 {
185  DPRINTF(TLB, "flushAll\n");
186  memset(table, 0, sizeof(PTE[size]));
187  lookupTable.clear();
188  nlu = 0;
189 }
190 
191 void
193 {
196 
197  for (int i = 0; i < size; i++) {
198  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
199  table[i].serialize(cp);
200  }
201 }
202 
203 void
205 {
208 
209  for (int i = 0; i < size; i++) {
210  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
211  table[i].unserialize(cp);
212  if (table[i].V0 || table[i].V1) {
213  lookupTable.insert(std::make_pair(table[i].VPN, i));
214  }
215  }
216 }
217 
218 Fault
220 {
221  panic_if(FullSystem, "translateAtomic not implemented in full system.");
222  return tc->getProcessPtr()->pTable->translate(req);
223 }
224 
225 void
227  Translation *translation, Mode mode)
228 {
229  assert(translation);
230  translation->finish(translateAtomic(req, tc, mode), req, tc, mode);
231 }
232 
233 Fault
235 {
236  panic_if(FullSystem, "translateAtomic not implemented in full system.");
237  return tc->getProcessPtr()->pTable->translate(req);
238 }
239 
240 Fault
242  ThreadContext *tc, Mode mode) const
243 {
244  return NoFault;
245 }
246 
247 
248 MipsISA::PTE &
249 TLB::index(bool advance)
250 {
251  PTE *pte = &table[nlu];
252 
253  if (advance)
254  nextnlu();
255 
256  return *pte;
257 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
BaseTLB::Translation::finish
virtual void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, Mode mode)=0
MipsISA::TLB::size
int size
Definition: tlb.hh:58
warn
#define warn(...)
Definition: logging.hh:239
MipsISA::PTE::PFN1
Addr PFN1
Definition: pagetable.hh:55
MipsISA::TLB::translateFunctional
Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition: tlb.cc:234
MipsISA::TLB::table
MipsISA::PTE * table
Definition: tlb.hh:57
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:591
MipsISA::PTE::C0
uint8_t C0
Definition: pagetable.hh:52
MipsISA::PTE::Mask
Addr Mask
Definition: pagetable.hh:42
MipsISA::TLB::index
MipsISA::PTE & index(bool advance=true)
Definition: tlb.cc:249
faults.hh
pra_constants.hh
MipsISA::TLB::lookup
MipsISA::PTE * lookup(Addr vpn, uint8_t asn) const
Definition: tlb.cc:70
MipsISA::TLB::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:192
MipsISA::TLB::translateTiming
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition: tlb.cc:226
MipsISA::TLB::flushAll
void flushAll() override
Remove all entries from the TLB.
Definition: tlb.cc:183
BaseTLB::Mode
Mode
Definition: tlb.hh:57
tlb.hh
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:169
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:86
MipsISA::TLB::translateAtomic
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition: tlb.cc:219
MipsISA::TLB::getEntry
MipsISA::PTE * getEntry(unsigned) const
Definition: tlb.cc:100
MipsISA::PTE
Definition: pagetable.hh:40
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:204
ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
BaseTLB
Definition: tlb.hh:50
MipsISA
Definition: decoder.cc:31
MipsISA::PTE::PFN0
Addr PFN0
Definition: pagetable.hh:49
MipsISA::TLB
Definition: tlb.hh:51
str.hh
MipsISA::PTE::VPN
Addr VPN
Definition: pagetable.hh:43
cp
Definition: cprintf.cc:37
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
MipsISA::TLB::nextnlu
void nextnlu()
Definition: tlb.hh:61
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MipsISA::TLB::nlu
int nlu
Definition: tlb.hh:59
MipsISA::PTE::D1
bool D1
Definition: pagetable.hh:56
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:246
MipsISA::PTE::V1
bool V1
Definition: pagetable.hh:57
process.hh
Request::STRICT_ORDER
@ STRICT_ORDER
The request is required to be strictly ordered by CPU models and is non-speculative.
Definition: request.hh:128
utility.hh
BaseTLB::Translation
Definition: tlb.hh:59
MipsISA::TLB::~TLB
virtual ~TLB()
Definition: tlb.cc:63
inifile.hh
MipsISA::TLB::TLB
TLB(const Params &p)
Definition: tlb.cc:56
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:251
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
Serializable::ScopedCheckpointSection
Definition: serialize.hh:178
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:584
MipsISA::TLB::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:204
MipsISA::mode
Bitfield< 11, 7 > mode
Definition: dt_constants.hh:95
MipsISA::PTE::unserialize
void unserialize(CheckpointIn &cp)
Definition: pagetable.cc:57
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
MipsISA::TLB::Params
MipsTLBParams Params
Definition: tlb.hh:65
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
MipsISA::PTE::V0
bool V0
Definition: pagetable.hh:51
MipsISA::i
Bitfield< 2 > i
Definition: pra_constants.hh:276
MipsISA::PTE::C1
uint8_t C1
Definition: pagetable.hh:58
Request::UNCACHEABLE
@ UNCACHEABLE
The request is to an uncacheable address.
Definition: request.hh:118
MipsISA::TLB::checkCacheability
static Fault checkCacheability(const RequestPtr &req)
Definition: tlb.cc:136
MipsISA::TLB::lookupTable
PageTable lookupTable
Definition: tlb.hh:55
MipsISA::PTE::serialize
void serialize(CheckpointOut &cp) const
Definition: pagetable.cc:38
MipsISA::TLB::insertAt
void insertAt(MipsISA::PTE &pte, unsigned Index, int _smallPages)
Definition: tlb.cc:149
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
MipsISA::TLB::probeEntry
int probeEntry(Addr vpn, uint8_t) const
Definition: tlb.cc:108
MipsISA::TLB::insert
void insert(Addr vaddr, MipsISA::PTE &pte)
Definition: tlb.cc:177
trace.hh
MipsISA::PTE::asid
uint8_t asid
Definition: pagetable.hh:44
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MipsISA::TLB::finalizePhysical
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Do post-translation physical address finalization.
Definition: tlb.cc:241
page_table.hh
CheckpointIn
Definition: serialize.hh:68
MipsISA::PTE::D0
bool D0
Definition: pagetable.hh:50
EmulationPageTable::translate
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:140
MipsISA::PTE::G
bool G
Definition: pagetable.hh:46
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
thread_context.hh
pagetable.hh
MipsISA::TLB::smallPages
int smallPages
Definition: tlb.hh:74

Generated on Tue Jun 22 2021 15:28:20 for gem5 by doxygen 1.8.17