gem5  v20.1.0.0
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 std;
50 using namespace MipsISA;
51 
53 //
54 // MIPS TLB
55 //
56 
57 TLB::TLB(const Params *p)
58  : BaseTLB(p), size(p->size), nlu(0)
59 {
60  table = new PTE[size];
61  memset(table, 0, sizeof(PTE[size]));
62  smallPages = 0;
63 }
64 
66 {
67  delete [] table;
68 }
69 
70 // look up an entry in the TLB
72 TLB::lookup(Addr vpn, uint8_t asn) const
73 {
74  // assume not found...
75  PTE *retval = NULL;
76  PageTable::const_iterator i = lookupTable.find(vpn);
77  if (i != lookupTable.end()) {
78  while (i->first == vpn) {
79  int index = i->second;
80  PTE *pte = &table[index];
81 
82  /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
83  Addr Mask = pte->Mask;
84  Addr InvMask = ~Mask;
85  Addr VPN = pte->VPN;
86  if (((vpn & InvMask) == (VPN & InvMask)) &&
87  (pte->G || (asn == pte->asid))) {
88  // We have a VPN + ASID Match
89  retval = pte;
90  break;
91  }
92  ++i;
93  }
94  }
95 
96  DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
97  retval ? "hit" : "miss", retval ? retval->PFN1 : 0);
98  return retval;
99 }
100 
102 TLB::getEntry(unsigned Index) const
103 {
104  // Make sure that Index is valid
105  assert(Index<size);
106  return &table[Index];
107 }
108 
109 int
110 TLB::probeEntry(Addr vpn, uint8_t asn) const
111 {
112  // assume not found...
113  int Ind = -1;
114  PageTable::const_iterator i = lookupTable.find(vpn);
115  if (i != lookupTable.end()) {
116  while (i->first == vpn) {
117  int index = i->second;
118  PTE *pte = &table[index];
119 
120  /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
121  Addr Mask = pte->Mask;
122  Addr InvMask = ~Mask;
123  Addr VPN = pte->VPN;
124  if (((vpn & InvMask) == (VPN & InvMask)) &&
125  (pte->G || (asn == pte->asid))) {
126  // We have a VPN + ASID Match
127  Ind = index;
128  break;
129  }
130  ++i;
131  }
132  }
133  DPRINTF(MipsPRA,"VPN: %x, asid: %d, Result of TLBP: %d\n",vpn,asn,Ind);
134  return Ind;
135 }
136 
137 inline Fault
139 {
140  Addr VAddrUncacheable = 0xA0000000;
141  // In MIPS, cacheability is controlled by certain bits of the virtual
142  // address or by the TLB entry
143  if ((req->getVaddr() & VAddrUncacheable) == VAddrUncacheable) {
144  // mark request as uncacheable
146  }
147  return NoFault;
148 }
149 
150 void
151 TLB::insertAt(PTE &pte, unsigned Index, int _smallPages)
152 {
153  smallPages = _smallPages;
154  if (Index > size) {
155  warn("Attempted to write at index (%d) beyond TLB size (%d)",
156  Index, size);
157  } else {
158  // Update TLB
159  DPRINTF(TLB, "TLB[%d]: %x %x %x %x\n",
160  Index, pte.Mask << 11,
161  ((pte.VPN << 11) | pte.asid),
162  ((pte.PFN0 << 6) | (pte.C0 << 3) |
163  (pte.D0 << 2) | (pte.V0 <<1) | pte.G),
164  ((pte.PFN1 <<6) | (pte.C1 << 3) |
165  (pte.D1 << 2) | (pte.V1 <<1) | pte.G));
166  if (table[Index].V0 || table[Index].V1) {
167  // Previous entry is valid
168  PageTable::iterator i = lookupTable.find(table[Index].VPN);
169  lookupTable.erase(i);
170  }
171  table[Index]=pte;
172  // Update fast lookup table
173  lookupTable.insert(make_pair(table[Index].VPN, Index));
174  }
175 }
176 
177 // insert a new TLB entry
178 void
180 {
181  fatal("TLB Insert not yet implemented\n");
182 }
183 
184 void
186 {
187  DPRINTF(TLB, "flushAll\n");
188  memset(table, 0, sizeof(PTE[size]));
189  lookupTable.clear();
190  nlu = 0;
191 }
192 
193 void
195 {
198 
199  for (int i = 0; i < size; i++) {
200  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
201  table[i].serialize(cp);
202  }
203 }
204 
205 void
207 {
210 
211  for (int i = 0; i < size; i++) {
212  ScopedCheckpointSection sec(cp, csprintf("PTE%d", i));
213  table[i].unserialize(cp);
214  if (table[i].V0 || table[i].V1) {
215  lookupTable.insert(make_pair(table[i].VPN, i));
216  }
217  }
218 }
219 
220 Fault
222 {
223  panic_if(FullSystem, "translateAtomic not implemented in full system.");
224  return tc->getProcessPtr()->pTable->translate(req);
225 }
226 
227 void
229  Translation *translation, Mode mode)
230 {
231  assert(translation);
232  translation->finish(translateAtomic(req, tc, mode), req, tc, mode);
233 }
234 
235 Fault
237 {
238  panic_if(FullSystem, "translateAtomic not implemented in full system.");
239  return tc->getProcessPtr()->pTable->translate(req);
240 }
241 
242 Fault
244  ThreadContext *tc, Mode mode) const
245 {
246  return NoFault;
247 }
248 
249 
250 MipsISA::PTE &
251 TLB::index(bool advance)
252 {
253  PTE *pte = &table[nlu];
254 
255  if (advance)
256  nextnlu();
257 
258  return *pte;
259 }
260 
261 MipsISA::TLB *
262 MipsTLBParams::create()
263 {
264  return new TLB(this);
265 }
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:236
MipsISA::TLB::table
MipsISA::PTE * table
Definition: tlb.hh:57
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
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:251
faults.hh
pra_constants.hh
MipsISA::TLB::lookup
MipsISA::PTE * lookup(Addr vpn, uint8_t asn) const
Definition: tlb.cc:72
MipsISA::TLB::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:194
MipsISA::TLB::translateTiming
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition: tlb.cc:228
MipsISA::TLB::flushAll
void flushAll() override
Remove all entries from the TLB.
Definition: tlb.cc:185
BaseTLB::Mode
Mode
Definition: tlb.hh:57
tlb.hh
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:174
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
MipsISA::TLB::translateAtomic
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition: tlb.cc:221
MipsISA::TLB::getEntry
MipsISA::PTE * getEntry(unsigned) const
Definition: tlb.cc:102
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:132
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
Request::STRICT_ORDER
@ STRICT_ORDER
The request is required to be strictly ordered by CPU models and is non-speculative.
Definition: request.hh:124
MipsISA::PTE::VPN
Addr VPN
Definition: pagetable.hh:43
cp
Definition: cprintf.cc:40
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:234
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:240
MipsISA::PTE::V1
bool V1
Definition: pagetable.hh:57
process.hh
utility.hh
BaseTLB::Translation
Definition: tlb.hh:59
MipsISA::TLB::~TLB
virtual ~TLB()
Definition: tlb.cc:65
Request::UNCACHEABLE
@ UNCACHEABLE
The request is to an uncacheable address.
Definition: request.hh:114
inifile.hh
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Serializable::ScopedCheckpointSection
Definition: serialize.hh:175
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
MipsISA::TLB::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:206
MipsISA::mode
Bitfield< 11, 7 > mode
Definition: dt_constants.hh:95
MipsISA::PTE::unserialize
void unserialize(CheckpointIn &cp)
Definition: pagetable.cc:57
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
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
MipsISA::TLB::checkCacheability
static Fault checkCacheability(const RequestPtr &req)
Definition: tlb.cc:138
MipsISA::TLB::lookupTable
PageTable lookupTable
Definition: tlb.hh:55
addr
ip6_addr_t addr
Definition: inet.hh:423
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:151
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
MipsISA::TLB::probeEntry
int probeEntry(Addr vpn, uint8_t) const
Definition: tlb.cc:110
MipsISA::TLB::insert
void insert(Addr vaddr, MipsISA::PTE &pte)
Definition: tlb.cc:179
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:243
page_table.hh
CheckpointIn
Definition: serialize.hh:67
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 Wed Sep 30 2020 14:01:59 for gem5 by doxygen 1.8.17