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  * Copyright (c) 2007-2008 The Florida State University
5  * Copyright (c) 2009 The University of Edinburgh
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met: redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer;
12  * redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution;
15  * neither the name of the copyright holders nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Authors: Nathan Binkert
32  * Steve Reinhardt
33  * Jaidev Patwardhan
34  * Stephen Hines
35  * Timothy M. Jones
36  */
37 
38 #include "arch/power/tlb.hh"
39 
40 #include <string>
41 #include <vector>
42 
43 #include "arch/power/faults.hh"
44 #include "arch/power/pagetable.hh"
45 #include "arch/power/utility.hh"
46 #include "base/inifile.hh"
47 #include "base/str.hh"
48 #include "base/trace.hh"
49 #include "cpu/thread_context.hh"
50 #include "debug/Power.hh"
51 #include "debug/TLB.hh"
52 #include "mem/page_table.hh"
53 #include "params/PowerTLB.hh"
54 #include "sim/full_system.hh"
55 #include "sim/process.hh"
56 
57 using namespace std;
58 using namespace PowerISA;
59 
61 //
62 // POWER TLB
63 //
64 
65 #define MODE2MASK(X) (1 << (X))
66 
67 TLB::TLB(const Params *p)
68  : BaseTLB(p), size(p->size), nlu(0)
69 {
70  table = new PowerISA::PTE[size];
71  memset(table, 0, sizeof(PowerISA::PTE[size]));
72  smallPages = 0;
73 }
74 
76 {
77  if (table)
78  delete [] table;
79 }
80 
81 // look up an entry in the TLB
83 TLB::lookup(Addr vpn, uint8_t asn) const
84 {
85  // assume not found...
86  PowerISA::PTE *retval = NULL;
87  PageTable::const_iterator i = lookupTable.find(vpn);
88  if (i != lookupTable.end()) {
89  while (i->first == vpn) {
90  int index = i->second;
91  PowerISA::PTE *pte = &table[index];
92  Addr Mask = pte->Mask;
93  Addr InvMask = ~Mask;
94  Addr VPN = pte->VPN;
95  if (((vpn & InvMask) == (VPN & InvMask))
96  && (pte->G || (asn == pte->asid))) {
97 
98  // We have a VPN + ASID Match
99  retval = pte;
100  break;
101  }
102  ++i;
103  }
104  }
105 
106  DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
107  retval ? "hit" : "miss", retval ? retval->PFN1 : 0);
108  return retval;
109 }
110 
112 TLB::getEntry(unsigned Index) const
113 {
114  // Make sure that Index is valid
115  assert(Index<size);
116  return &table[Index];
117 }
118 
119 int
120 TLB::probeEntry(Addr vpn,uint8_t asn) const
121 {
122  // assume not found...
123  int Ind = -1;
124  PageTable::const_iterator i = lookupTable.find(vpn);
125  if (i != lookupTable.end()) {
126  while (i->first == vpn) {
127  int index = i->second;
128  PowerISA::PTE *pte = &table[index];
129  Addr Mask = pte->Mask;
130  Addr InvMask = ~Mask;
131  Addr VPN = pte->VPN;
132  if (((vpn & InvMask) == (VPN & InvMask))
133  && (pte->G || (asn == pte->asid))) {
134 
135  // We have a VPN + ASID Match
136  Ind = index;
137  break;
138  }
139  ++i;
140  }
141  }
142 
143  DPRINTF(Power, "VPN: %x, asid: %d, Result of TLBP: %d\n", vpn, asn, Ind);
144  return Ind;
145 }
146 
147 inline Fault
149 {
150  Addr VAddrUncacheable = 0xA0000000;
151  if ((req->getVaddr() & VAddrUncacheable) == VAddrUncacheable) {
152 
153  // mark request as uncacheable
155  }
156  return NoFault;
157 }
158 
159 void
160 TLB::insertAt(PowerISA::PTE &pte, unsigned Index, int _smallPages)
161 {
162  smallPages=_smallPages;
163  if (Index > size){
164  warn("Attempted to write at index (%d) beyond TLB size (%d)",
165  Index, size);
166  } else {
167 
168  // Update TLB
169  if (table[Index].V0 || table[Index].V1) {
170 
171  // Previous entry is valid
172  PageTable::iterator i = lookupTable.find(table[Index].VPN);
173  lookupTable.erase(i);
174  }
175  table[Index]=pte;
176 
177  // Update fast lookup table
178  lookupTable.insert(make_pair(table[Index].VPN, Index));
179  }
180 }
181 
182 // insert a new TLB entry
183 void
185 {
186  fatal("TLB Insert not yet implemented\n");
187 }
188 
189 void
191 {
192  DPRINTF(TLB, "flushAll\n");
193  memset(table, 0, sizeof(PowerISA::PTE[size]));
194  lookupTable.clear();
195  nlu = 0;
196 }
197 
198 void
200 {
203 
204  for (int i = 0; i < size; i++) {
205  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
206  table[i].serialize(cp);
207  }
208 }
209 
210 void
212 {
215 
216  for (int i = 0; i < size; i++) {
217  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
218  if (table[i].V0 || table[i].V1) {
219  lookupTable.insert(make_pair(table[i].VPN, i));
220  }
221  }
222 }
223 
224 void
226 {
228 
229  read_hits
230  .name(name() + ".read_hits")
231  .desc("DTB read hits")
232  ;
233 
235  .name(name() + ".read_misses")
236  .desc("DTB read misses")
237  ;
238 
239 
241  .name(name() + ".read_accesses")
242  .desc("DTB read accesses")
243  ;
244 
245  write_hits
246  .name(name() + ".write_hits")
247  .desc("DTB write hits")
248  ;
249 
251  .name(name() + ".write_misses")
252  .desc("DTB write misses")
253  ;
254 
255 
257  .name(name() + ".write_accesses")
258  .desc("DTB write accesses")
259  ;
260 
261  hits
262  .name(name() + ".hits")
263  .desc("DTB hits")
264  ;
265 
266  misses
267  .name(name() + ".misses")
268  .desc("DTB misses")
269  ;
270 
271  accesses
272  .name(name() + ".accesses")
273  .desc("DTB accesses")
274  ;
275 
279 }
280 
281 Fault
283 {
284  // Instruction accesses must be word-aligned
285  if (req->getVaddr() & 0x3) {
286  DPRINTF(TLB, "Alignment Fault on %#x, size = %d\n", req->getVaddr(),
287  req->getSize());
288  return std::make_shared<AlignmentFault>();
289  }
290 
291  Process * p = tc->getProcessPtr();
292 
293  Fault fault = p->pTable->translate(req);
294  if (fault != NoFault)
295  return fault;
296 
297  return NoFault;
298 }
299 
300 Fault
302 {
303  Process * p = tc->getProcessPtr();
304 
305  Fault fault = p->pTable->translate(req);
306  if (fault != NoFault)
307  return fault;
308 
309  return NoFault;
310 }
311 
312 Fault
314 {
315  if (FullSystem)
316  fatal("translate atomic not yet implemented in full system mode.\n");
317 
318  if (mode == Execute)
319  return translateInst(req, tc);
320  else
321  return translateData(req, tc, mode == Write);
322 }
323 
324 void
326  Translation *translation, Mode mode)
327 {
328  assert(translation);
329  translation->finish(translateAtomic(req, tc, mode), req, tc, mode);
330 }
331 
332 Fault
334 {
335  panic("Not implemented\n");
336  return NoFault;
337 }
338 
339 Fault
341 {
342  return NoFault;
343 }
344 
346 TLB::index(bool advance)
347 {
348  PowerISA::PTE *pte = &table[nlu];
349 
350  if (advance)
351  nextnlu();
352 
353  return *pte;
354 }
355 
357 PowerTLBParams::create()
358 {
359  return new PowerISA::TLB(this);
360 }
#define DPRINTF(x,...)
Definition: trace.hh:212
Stats::Scalar read_misses
Definition: tlb.hh:120
decltype(nullptr) constexpr NoFault
Definition: types.hh:189
Fault translateFunctional(RequestPtr req, ThreadContext *tc, Mode mode)
Stub function for CheckerCPU compilation support.
Definition: tlb.cc:333
Fault translateInst(RequestPtr req, ThreadContext *tc)
Definition: tlb.cc:282
Bitfield< 7 > i
Definition: miscregs.hh:1378
#define panic(...)
Definition: misc.hh:153
void insertAt(PowerISA::PTE &pte, unsigned Index, int _smallPages)
Definition: tlb.cc:160
int smallPages
Definition: tlb.hh:141
void serialize(CheckpointOut &cp) const
Definition: pagetable.cc:46
Stats::Scalar write_accesses
Definition: tlb.hh:126
PowerISA::PTE & index(bool advance=true)
Definition: tlb.cc:346
ip6_addr_t addr
Definition: inet.hh:335
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
virtual Process * getProcessPtr()=0
PowerTLBParams Params
Definition: tlb.hh:132
Stats::Scalar read_accesses
Definition: tlb.hh:122
Stats::Scalar read_hits
Definition: tlb.hh:119
void insert(Addr vaddr, PowerISA::PTE &pte)
Definition: tlb.cc:184
Bitfield< 4, 0 > mode
Definition: miscregs.hh:1385
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...
Stats::Formula hits
Definition: tlb.hh:127
Fault finalizePhysical(RequestPtr req, ThreadContext *tc, Mode mode) const
Definition: tlb.cc:340
#define warn(...)
Definition: misc.hh:219
Definition: tlb.hh:53
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
uint8_t asid
Definition: pagetable.hh:120
void nextnlu()
Definition: tlb.hh:110
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:173
The request is to an uncacheable address.
Definition: request.hh:114
#define fatal(...)
Definition: misc.hh:163
void regStats() override
Register statistics for this object.
Definition: tlb.cc:225
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:199
int nlu
Definition: tlb.hh:107
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Declaration of IniFile object.
Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode)
Definition: tlb.cc:313
PageTableBase * pTable
Definition: process.hh:178
PowerISA::PTE * table
Definition: tlb.hh:105
Stats::Scalar write_hits
Definition: tlb.hh:123
Stats::Formula accesses
Definition: tlb.hh:129
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
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
void translateTiming(RequestPtr req, ThreadContext *tc, Translation *translation, Mode mode)
Definition: tlb.cc:325
PowerISA::PTE * getEntry(unsigned) const
Definition: tlb.cc:112
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.
static Fault checkCacheability(RequestPtr &req)
Definition: tlb.cc:148
std::ostream CheckpointOut
Definition: serialize.hh:67
PageTable lookupTable
Definition: tlb.hh:103
Addr getVaddr() const
Definition: request.hh:616
Fault translateData(RequestPtr req, ThreadContext *tc, bool write)
Definition: tlb.cc:301
PowerISA::PTE * lookup(Addr vpn, uint8_t asn) const
Definition: tlb.cc:83
The request is required to be strictly ordered by CPU models and is non-speculative.
Definition: request.hh:124
Stats::Scalar write_misses
Definition: tlb.hh:124
int size
Definition: tlb.hh:106
Stats::Formula misses
Definition: tlb.hh:128
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 unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:211
unsigned getSize() const
Definition: request.hh:552
int probeEntry(Addr vpn, uint8_t) const
Definition: tlb.cc:120
Scoped checkpoint section helper class.
Definition: serialize.hh:240
virtual ~TLB()
Definition: tlb.cc:75
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
void flushAll() override
Remove all entries from the TLB.
Definition: tlb.cc:190

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