tlb.cc (4762:c94e103c83ad) tlb.cc (4957:f858d0b8ef99)
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 50 unchanged lines hidden (view full) ---

59
60#define MODE2MASK(X) (1 << (X))
61
62TLB::TLB(const string &name, int s)
63 : SimObject(name), size(s), nlu(0)
64{
65 table = new PTE[size];
66 memset(table, 0, sizeof(PTE[size]));
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 50 unchanged lines hidden (view full) ---

59
60#define MODE2MASK(X) (1 << (X))
61
62TLB::TLB(const string &name, int s)
63 : SimObject(name), size(s), nlu(0)
64{
65 table = new PTE[size];
66 memset(table, 0, sizeof(PTE[size]));
67 flushCache();
67}
68
69TLB::~TLB()
70{
71 if (table)
72 delete [] table;
73}
74
75// look up an entry in the TLB
76PTE *
77TLB::lookup(Addr vpn, uint8_t asn) const
78{
79 // assume not found...
80 PTE *retval = NULL;
81
68}
69
70TLB::~TLB()
71{
72 if (table)
73 delete [] table;
74}
75
76// look up an entry in the TLB
77PTE *
78TLB::lookup(Addr vpn, uint8_t asn) const
79{
80 // assume not found...
81 PTE *retval = NULL;
82
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];
87 assert(pte->valid);
88 if (vpn == pte->tag && (pte->asma || pte->asn == asn)) {
89 retval = pte;
90 break;
91 }
83 if (PTECache[0] && vpn == PTECache[0]->tag &&
84 (PTECache[0]->asma || PTECache[0]->asn == asn))
85 retval = PTECache[0];
86 else if (PTECache[1] && vpn == PTECache[1]->tag &&
87 (PTECache[1]->asma || PTECache[1]->asn == asn))
88 retval = PTECache[1];
89 else if (PTECache[2] && vpn == PTECache[2]->tag &&
90 (PTECache[2]->asma || PTECache[2]->asn == asn))
91 retval = PTECache[2];
92 else {
93 PageTable::const_iterator i = lookupTable.find(vpn);
94 if (i != lookupTable.end()) {
95 while (i->first == vpn) {
96 int index = i->second;
97 PTE *pte = &table[index];
98 assert(pte->valid);
99 if (vpn == pte->tag && (pte->asma || pte->asn == asn)) {
100 retval = pte;
101 break;
102 }
92
103
93 ++i;
104 ++i;
105 }
94 }
95 }
96
97 DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
98 retval ? "hit" : "miss", retval ? retval->ppn : 0);
99 return retval;
100}
101

--- 35 unchanged lines hidden (view full) ---

137 return NoFault;
138}
139
140
141// insert a new TLB entry
142void
143TLB::insert(Addr addr, PTE &pte)
144{
106 }
107 }
108
109 DPRINTF(TLB, "lookup %#x, asn %#x -> %s ppn %#x\n", vpn, (int)asn,
110 retval ? "hit" : "miss", retval ? retval->ppn : 0);
111 return retval;
112}
113

--- 35 unchanged lines hidden (view full) ---

149 return NoFault;
150}
151
152
153// insert a new TLB entry
154void
155TLB::insert(Addr addr, PTE &pte)
156{
157 flushCache();
145 VAddr vaddr = addr;
146 if (table[nlu].valid) {
147 Addr oldvpn = table[nlu].tag;
148 PageTable::iterator i = lookupTable.find(oldvpn);
149
150 if (i == lookupTable.end())
151 panic("TLB entry not found in lookupTable");
152

--- 20 unchanged lines hidden (view full) ---

173 nextnlu();
174}
175
176void
177TLB::flushAll()
178{
179 DPRINTF(TLB, "flushAll\n");
180 memset(table, 0, sizeof(PTE[size]));
158 VAddr vaddr = addr;
159 if (table[nlu].valid) {
160 Addr oldvpn = table[nlu].tag;
161 PageTable::iterator i = lookupTable.find(oldvpn);
162
163 if (i == lookupTable.end())
164 panic("TLB entry not found in lookupTable");
165

--- 20 unchanged lines hidden (view full) ---

186 nextnlu();
187}
188
189void
190TLB::flushAll()
191{
192 DPRINTF(TLB, "flushAll\n");
193 memset(table, 0, sizeof(PTE[size]));
194 flushCache();
181 lookupTable.clear();
182 nlu = 0;
183}
184
185void
186TLB::flushProcesses()
187{
195 lookupTable.clear();
196 nlu = 0;
197}
198
199void
200TLB::flushProcesses()
201{
202 flushCache();
188 PageTable::iterator i = lookupTable.begin();
189 PageTable::iterator end = lookupTable.end();
190 while (i != end) {
191 int index = i->second;
192 PTE *pte = &table[index];
193 assert(pte->valid);
194
195 // we can't increment i after we erase it, so save a copy and

--- 7 unchanged lines hidden (view full) ---

203 lookupTable.erase(cur);
204 }
205 }
206}
207
208void
209TLB::flushAddr(Addr addr, uint8_t asn)
210{
203 PageTable::iterator i = lookupTable.begin();
204 PageTable::iterator end = lookupTable.end();
205 while (i != end) {
206 int index = i->second;
207 PTE *pte = &table[index];
208 assert(pte->valid);
209
210 // we can't increment i after we erase it, so save a copy and

--- 7 unchanged lines hidden (view full) ---

218 lookupTable.erase(cur);
219 }
220 }
221}
222
223void
224TLB::flushAddr(Addr addr, uint8_t asn)
225{
226 flushCache();
211 VAddr vaddr = addr;
212
213 PageTable::iterator i = lookupTable.find(vaddr.vpn());
214 if (i == lookupTable.end())
215 return;
216
217 while (i != lookupTable.end() && i->first == vaddr.vpn()) {
218 int index = i->second;

--- 396 unchanged lines hidden ---
227 VAddr vaddr = addr;
228
229 PageTable::iterator i = lookupTable.find(vaddr.vpn());
230 if (i == lookupTable.end())
231 return;
232
233 while (i != lookupTable.end() && i->first == vaddr.vpn()) {
234 int index = i->second;

--- 396 unchanged lines hidden ---