gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Authors: Nathan Binkert
30  * Steve Reinhardt
31  * Jaidev Patwardhan
32  * Zhengxing Li
33  * Deyuan Guo
34  */
35 
36 #include "arch/mips/tlb.hh"
37 
38 #include <string>
39 #include <vector>
40 
41 #include "arch/mips/faults.hh"
42 #include "arch/mips/pagetable.hh"
44 #include "arch/mips/utility.hh"
45 #include "base/inifile.hh"
46 #include "base/str.hh"
47 #include "base/trace.hh"
48 #include "cpu/thread_context.hh"
49 #include "debug/MipsPRA.hh"
50 #include "debug/TLB.hh"
51 #include "mem/page_table.hh"
52 #include "params/MipsTLB.hh"
53 #include "sim/process.hh"
54 
55 using namespace std;
56 using namespace MipsISA;
57 
59 //
60 // MIPS TLB
61 //
62 
63 TLB::TLB(const Params *p)
64  : BaseTLB(p), size(p->size), nlu(0)
65 {
66  table = new PTE[size];
67  memset(table, 0, sizeof(PTE[size]));
68  smallPages = 0;
69 }
70 
72 {
73  if (table)
74  delete [] table;
75 }
76 
77 // look up an entry in the TLB
79 TLB::lookup(Addr vpn, uint8_t asn) const
80 {
81  // assume not found...
82  PTE *retval = NULL;
83  PageTable::const_iterator i = lookupTable.find(vpn);
84  if (i != lookupTable.end()) {
85  while (i->first == vpn) {
86  int index = i->second;
87  PTE *pte = &table[index];
88 
89  /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
90  Addr Mask = pte->Mask;
91  Addr InvMask = ~Mask;
92  Addr VPN = pte->VPN;
93  if (((vpn & InvMask) == (VPN & InvMask)) &&
94  (pte->G || (asn == pte->asid))) {
95  // We have a VPN + ASID Match
96  retval = pte;
97  break;
98  }
99  ++i;
100  }
101  }
102 
103  DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
104  retval ? "hit" : "miss", retval ? retval->PFN1 : 0);
105  return retval;
106 }
107 
109 TLB::getEntry(unsigned Index) const
110 {
111  // Make sure that Index is valid
112  assert(Index<size);
113  return &table[Index];
114 }
115 
116 int
117 TLB::probeEntry(Addr vpn, uint8_t asn) const
118 {
119  // assume not found...
120  int Ind = -1;
121  PageTable::const_iterator i = lookupTable.find(vpn);
122  if (i != lookupTable.end()) {
123  while (i->first == vpn) {
124  int index = i->second;
125  PTE *pte = &table[index];
126 
127  /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
128  Addr Mask = pte->Mask;
129  Addr InvMask = ~Mask;
130  Addr VPN = pte->VPN;
131  if (((vpn & InvMask) == (VPN & InvMask)) &&
132  (pte->G || (asn == pte->asid))) {
133  // We have a VPN + ASID Match
134  Ind = index;
135  break;
136  }
137  ++i;
138  }
139  }
140  DPRINTF(MipsPRA,"VPN: %x, asid: %d, Result of TLBP: %d\n",vpn,asn,Ind);
141  return Ind;
142 }
143 
144 inline Fault
146 {
147  Addr VAddrUncacheable = 0xA0000000;
148  // In MIPS, cacheability is controlled by certain bits of the virtual
149  // address or by the TLB entry
150  if ((req->getVaddr() & VAddrUncacheable) == VAddrUncacheable) {
151  // mark request as uncacheable
153  }
154  return NoFault;
155 }
156 
157 void
158 TLB::insertAt(PTE &pte, unsigned Index, int _smallPages)
159 {
160  smallPages = _smallPages;
161  if (Index > size) {
162  warn("Attempted to write at index (%d) beyond TLB size (%d)",
163  Index, size);
164  } else {
165  // Update TLB
166  DPRINTF(TLB, "TLB[%d]: %x %x %x %x\n",
167  Index, pte.Mask << 11,
168  ((pte.VPN << 11) | pte.asid),
169  ((pte.PFN0 << 6) | (pte.C0 << 3) |
170  (pte.D0 << 2) | (pte.V0 <<1) | pte.G),
171  ((pte.PFN1 <<6) | (pte.C1 << 3) |
172  (pte.D1 << 2) | (pte.V1 <<1) | pte.G));
173  if (table[Index].V0 || table[Index].V1) {
174  // Previous entry is valid
175  PageTable::iterator i = lookupTable.find(table[Index].VPN);
176  lookupTable.erase(i);
177  }
178  table[Index]=pte;
179  // Update fast lookup table
180  lookupTable.insert(make_pair(table[Index].VPN, Index));
181  }
182 }
183 
184 // insert a new TLB entry
185 void
187 {
188  fatal("TLB Insert not yet implemented\n");
189 }
190 
191 void
193 {
194  DPRINTF(TLB, "flushAll\n");
195  memset(table, 0, sizeof(PTE[size]));
196  lookupTable.clear();
197  nlu = 0;
198 }
199 
200 void
202 {
205 
206  for (int i = 0; i < size; i++) {
207  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
208  table[i].serialize(cp);
209  }
210 }
211 
212 void
214 {
217 
218  for (int i = 0; i < size; i++) {
219  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
220  table[i].unserialize(cp);
221  if (table[i].V0 || table[i].V1) {
222  lookupTable.insert(make_pair(table[i].VPN, i));
223  }
224  }
225 }
226 
227 void
229 {
231 
232  read_hits
233  .name(name() + ".read_hits")
234  .desc("DTB read hits")
235  ;
236 
238  .name(name() + ".read_misses")
239  .desc("DTB read misses")
240  ;
241 
242 
244  .name(name() + ".read_accesses")
245  .desc("DTB read accesses")
246  ;
247 
248  write_hits
249  .name(name() + ".write_hits")
250  .desc("DTB write hits")
251  ;
252 
254  .name(name() + ".write_misses")
255  .desc("DTB write misses")
256  ;
257 
258 
260  .name(name() + ".write_accesses")
261  .desc("DTB write accesses")
262  ;
263 
264  hits
265  .name(name() + ".hits")
266  .desc("DTB hits")
267  ;
268 
269  misses
270  .name(name() + ".misses")
271  .desc("DTB misses")
272  ;
273 
274  accesses
275  .name(name() + ".accesses")
276  .desc("DTB accesses")
277  ;
278 
282 }
283 
284 Fault
286 {
287  if (FullSystem)
288  panic("translateInst not implemented in MIPS.\n");
289 
290  Process * p = tc->getProcessPtr();
291 
292  Fault fault = p->pTable->translate(req);
293  if (fault != NoFault)
294  return fault;
295 
296  return NoFault;
297 }
298 
299 Fault
301 {
302  if (FullSystem)
303  panic("translateData not implemented in MIPS.\n");
304 
305  Process * p = tc->getProcessPtr();
306 
307  Fault fault = p->pTable->translate(req);
308  if (fault != NoFault)
309  return fault;
310 
311  return NoFault;
312 }
313 
314 Fault
316 {
317  if (mode == Execute)
318  return translateInst(req, tc);
319  else
320  return translateData(req, tc, mode == Write);
321 }
322 
323 void
325  Translation *translation, Mode mode)
326 {
327  assert(translation);
328  translation->finish(translateAtomic(req, tc, mode), req, tc, mode);
329 }
330 
331 Fault
333 {
334  panic("Not implemented\n");
335  return NoFault;
336 }
337 
338 Fault
340 {
341  return NoFault;
342 }
343 
344 
345 MipsISA::PTE &
346 TLB::index(bool advance)
347 {
348  PTE *pte = &table[nlu];
349 
350  if (advance)
351  nextnlu();
352 
353  return *pte;
354 }
355 
356 MipsISA::TLB *
357 MipsTLBParams::create()
358 {
359  return new TLB(this);
360 }
#define DPRINTF(x,...)
Definition: trace.hh:212
MipsISA::PTE & index(bool advance=true)
Definition: tlb.cc:346
decltype(nullptr) constexpr NoFault
Definition: types.hh:189
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:201
MipsISA::PTE * table
Definition: tlb.hh:63
Stats::Scalar read_hits
Definition: tlb.hh:70
#define panic(...)
Definition: misc.hh:153
MipsISA::PTE * lookup(Addr vpn, uint8_t asn) const
Definition: tlb.cc:79
int size
Definition: tlb.hh:64
void flushAll() override
Remove all entries from the TLB.
Definition: tlb.cc:192
ip6_addr_t addr
Definition: inet.hh:335
MipsISA::PTE * getEntry(unsigned) const
Definition: tlb.cc:109
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
virtual Process * getProcessPtr()=0
void regStats() override
Register statistics for this object.
Definition: tlb.cc:228
Stats::Formula hits
Definition: tlb.hh:78
virtual void regStats()
Register statistics for this object.
Definition: sim_object.cc:105
ThreadContext is the external interface to all thread state for anything outside of the CPU...
#define warn(...)
Definition: misc.hh:219
Definition: tlb.hh:53
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
int probeEntry(Addr vpn, uint8_t) const
Definition: tlb.cc:117
Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode)
Definition: tlb.cc:315
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
Stats::Scalar write_misses
Definition: tlb.hh:75
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:173
Stats::Scalar write_hits
Definition: tlb.hh:74
int nlu
Definition: tlb.hh:65
The request is to an uncacheable address.
Definition: request.hh:114
void serialize(CheckpointOut &cp) const
Definition: pagetable.cc:42
#define fatal(...)
Definition: misc.hh:163
void nextnlu()
Definition: tlb.hh:67
Fault translateData(RequestPtr req, ThreadContext *tc, bool write)
Definition: tlb.cc:300
Bitfield< 2 > i
uint8_t asid
Definition: pagetable.hh:52
virtual ~TLB()
Definition: tlb.cc:71
Fault translateFunctional(RequestPtr req, ThreadContext *tc, Mode mode)
Function stub for CheckerCPU compilation issues.
Definition: tlb.cc:332
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Declaration of IniFile object.
void unserialize(CheckpointIn &cp)
Definition: pagetable.cc:61
PageTableBase * pTable
Definition: process.hh:178
Stats::Scalar read_misses
Definition: tlb.hh:71
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
MipsTLBParams Params
Definition: tlb.hh:83
Mode
Definition: tlb.hh:61
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:254
int size()
Definition: pagetable.hh:146
virtual const std::string name() const
Definition: sim_object.hh:117
Declarations of a non-full system Page Table.
std::ostream CheckpointOut
Definition: serialize.hh:67
uint8_t C1
Definition: pagetable.hh:66
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:213
Addr getVaddr() const
Definition: request.hh:616
Bitfield< 11, 7 > mode
Definition: dt_constants.hh:97
Stats::Scalar read_accesses
Definition: tlb.hh:73
static Fault checkCacheability(RequestPtr &req)
Definition: tlb.cc:145
The request is required to be strictly ordered by CPU models and is non-speculative.
Definition: request.hh:124
Fault translateInst(RequestPtr req, ThreadContext *tc)
Definition: tlb.cc:285
void insertAt(MipsISA::PTE &pte, unsigned Index, int _smallPages)
Definition: tlb.cc:158
Fault finalizePhysical(RequestPtr req, ThreadContext *tc, Mode mode) const
Definition: tlb.cc:339
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:287
void translateTiming(RequestPtr req, ThreadContext *tc, Translation *translation, Mode mode)
Definition: tlb.cc:324
PageTable lookupTable
Definition: tlb.hh:61
Scoped checkpoint section helper class.
Definition: serialize.hh:240
Stats::Scalar write_accesses
Definition: tlb.hh:77
Bitfield< 0 > p
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...
Definition: request.hh:595
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
Stats::Formula accesses
Definition: tlb.hh:80
Stats::Formula misses
Definition: tlb.hh:79
void insert(Addr vaddr, MipsISA::PTE &pte)
Definition: tlb.cc:186
int smallPages
Definition: tlb.hh:92
uint8_t C0
Definition: pagetable.hh:60

Generated on Fri Jun 9 2017 13:03:36 for gem5 by doxygen 1.8.6