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(); |
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 |
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 } |
103 |
104 ++i; 105 } |
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(); |
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(); |
195 lookupTable.clear(); 196 nlu = 0; 197} 198 199void 200TLB::flushProcesses() 201{ |
202 flushCache(); |
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(); |
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 --- |