2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * Copyright (c) 2007 MIPS Technologies, Inc.
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.
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.
29 * Authors: Nathan Binkert
39 #include "arch/mips/faults.hh"
40 #include "arch/mips/pagetable.hh"
41 #include "arch/mips/pra_constants.hh"
42 #include "arch/mips/tlb.hh"
43 #include "arch/mips/utility.hh"
44 #include "base/inifile.hh"
45 #include "base/str.hh"
46 #include "base/trace.hh"
47 #include "cpu/thread_context.hh"
48 #include "debug/MipsPRA.hh"
49 #include "debug/TLB.hh"
50 #include "mem/page_table.hh"
51 #include "params/MipsTLB.hh"
52 #include "sim/process.hh"
55 using namespace MipsISA
;
57 ///////////////////////////////////////////////////////////////////////
62 TLB::TLB(const Params
*p
)
63 : BaseTLB(p
), size(p
->size
), nlu(0)
65 table
= new PTE
[size
];
66 memset(table
, 0, sizeof(PTE
[size
]));
76 // look up an entry in the TLB
78 TLB::lookup(Addr vpn
, uint8_t asn
) const
80 // assume not found...
82 PageTable::const_iterator i
= lookupTable
.find(vpn
);
83 if (i
!= lookupTable
.end()) {
84 while (i
->first
== vpn
) {
85 int index
= i
->second
;
86 PTE
*pte
= &table
[index
];
88 /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
89 Addr Mask
= pte
->Mask
;
92 if (((vpn
& InvMask
) == (VPN
& InvMask
)) &&
93 (pte
->G
|| (asn
== pte
->asid
))) {
94 // We have a VPN + ASID Match
102 DPRINTF(TLB
, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn
, (int)asn
,
103 retval
? "hit" : "miss", retval
? retval
->PFN1
: 0);
108 TLB::getEntry(unsigned Index
) const
110 // Make sure that Index is valid
112 return &table
[Index
];
116 TLB::probeEntry(Addr vpn
, uint8_t asn
) const
118 // assume not found...
120 PageTable::const_iterator i
= lookupTable
.find(vpn
);
121 if (i
!= lookupTable
.end()) {
122 while (i
->first
== vpn
) {
123 int index
= i
->second
;
124 PTE
*pte
= &table
[index
];
126 /* 1KB TLB Lookup code - from MIPS ARM Volume III - Rev. 2.50 */
127 Addr Mask
= pte
->Mask
;
128 Addr InvMask
= ~Mask
;
130 if (((vpn
& InvMask
) == (VPN
& InvMask
)) &&
131 (pte
->G
|| (asn
== pte
->asid
))) {
132 // We have a VPN + ASID Match
139 DPRINTF(MipsPRA
,"VPN: %x, asid: %d, Result of TLBP: %d\n",vpn
,asn
,Ind
);
144 TLB::checkCacheability(RequestPtr
&req
)
146 Addr VAddrUncacheable
= 0xA0000000;
147 // In MIPS, cacheability is controlled by certain bits of the virtual
148 // address or by the TLB entry
149 if ((req
->getVaddr() & VAddrUncacheable
) == VAddrUncacheable
) {
150 // mark request as uncacheable
151 req
->setFlags(Request::UNCACHEABLE
);
157 TLB::insertAt(PTE
&pte
, unsigned Index
, int _smallPages
)
159 smallPages
= _smallPages
;
161 warn("Attempted to write at index (%d) beyond TLB size (%d)",
165 DPRINTF(TLB
, "TLB[%d]: %x %x %x %x\n",
166 Index
, pte
.Mask
<< 11,
167 ((pte
.VPN
<< 11) | pte
.asid
),
168 ((pte
.PFN0
<< 6) | (pte
.C0
<< 3) |
169 (pte
.D0
<< 2) | (pte
.V0
<<1) | pte
.G
),
170 ((pte
.PFN1
<<6) | (pte
.C1
<< 3) |
171 (pte
.D1
<< 2) | (pte
.V1
<<1) | pte
.G
));
172 if (table
[Index
].V0
|| table
[Index
].V1
) {
173 // Previous entry is valid
174 PageTable::iterator i
= lookupTable
.find(table
[Index
].VPN
);
175 lookupTable
.erase(i
);
178 // Update fast lookup table
179 lookupTable
.insert(make_pair(table
[Index
].VPN
, Index
));
183 // insert a new TLB entry
185 TLB::insert(Addr addr
, PTE
&pte
)
187 fatal("TLB Insert not yet implemented\n");
193 DPRINTF(TLB
, "flushAll\n");
194 memset(table
, 0, sizeof(PTE
[size
]));
200 TLB::serialize(ostream
&os
)
202 SERIALIZE_SCALAR(size
);
203 SERIALIZE_SCALAR(nlu
);
205 for (int i
= 0; i
< size
; i
++) {
206 nameOut(os
, csprintf("%s.PTE%d", name(), i
));
207 table
[i
].serialize(os
);
212 TLB::unserialize(Checkpoint
*cp
, const string
§ion
)
214 UNSERIALIZE_SCALAR(size
);
215 UNSERIALIZE_SCALAR(nlu
);
217 for (int i
= 0; i
< size
; i
++) {
218 table
[i
].unserialize(cp
, csprintf("%s.PTE%d", section
, i
));
219 if (table
[i
].V0
|| table
[i
].V1
) {
220 lookupTable
.insert(make_pair(table
[i
].VPN
, i
));
229 .name(name() + ".read_hits")
230 .desc("DTB read hits")
234 .name(name() + ".read_misses")
235 .desc("DTB read misses")
240 .name(name() + ".read_accesses")
241 .desc("DTB read accesses")
245 .name(name() + ".write_hits")
246 .desc("DTB write hits")
250 .name(name() + ".write_misses")
251 .desc("DTB write misses")
256 .name(name() + ".write_accesses")
257 .desc("DTB write accesses")
261 .name(name() + ".hits")
266 .name(name() + ".misses")
271 .name(name() + ".accesses")
272 .desc("DTB accesses")
275 hits
= read_hits
+ write_hits
;
276 misses
= read_misses
+ write_misses
;
277 accesses
= read_accesses
+ write_accesses
;
281 TLB::translateInst(RequestPtr req
, ThreadContext
*tc
)
284 panic("translateInst not implemented in MIPS.\n");
286 Process
* p
= tc
->getProcessPtr();
288 Fault fault
= p
->pTable
->translate(req
);
289 if (fault
!= NoFault
)
296 TLB::translateData(RequestPtr req
, ThreadContext
*tc
, bool write
)
299 panic("translateData not implemented in MIPS.\n");
301 Process
* p
= tc
->getProcessPtr();
303 Fault fault
= p
->pTable
->translate(req
);
304 if (fault
!= NoFault
)
311 TLB::translateAtomic(RequestPtr req
, ThreadContext
*tc
, Mode mode
)
314 return translateInst(req
, tc
);
316 return translateData(req
, tc
, mode
== Write
);
320 TLB::translateTiming(RequestPtr req
, ThreadContext
*tc
,
321 Translation
*translation
, Mode mode
)
324 translation
->finish(translateAtomic(req
, tc
, mode
), req
, tc
, mode
);
328 TLB::translateFunctional(RequestPtr req
, ThreadContext
*tc
, Mode mode
)
330 panic("Not implemented\n");
335 TLB::finalizePhysical(RequestPtr req
, ThreadContext
*tc
, Mode mode
) const
342 TLB::index(bool advance
)
344 PTE
*pte
= &table
[nlu
];
353 MipsTLBParams::create()
355 return new TLB(this);