tlb.cc revision 5126:d3cdea5e0fb3
1/* 2 * Copyright (c) 2007 The Hewlett-Packard Development Company 3 * All rights reserved. 4 * 5 * Redistribution and use of this software in source and binary forms, 6 * with or without modification, are permitted provided that the 7 * following conditions are met: 8 * 9 * The software must be used only for Non-Commercial Use which means any 10 * use which is NOT directed to receiving any direct monetary 11 * compensation for, or commercial advantage from such use. Illustrative 12 * examples of non-commercial use are academic research, personal study, 13 * teaching, education and corporate research & development. 14 * Illustrative examples of commercial use are distributing products for 15 * commercial advantage and providing services using the software for 16 * commercial advantage. 17 * 18 * If you wish to use this software or functionality therein that may be 19 * covered by patents for commercial use, please contact: 20 * Director of Intellectual Property Licensing 21 * Office of Strategy and Technology 22 * Hewlett-Packard Company 23 * 1501 Page Mill Road 24 * Palo Alto, California 94304 25 * 26 * Redistributions of source code must retain the above copyright notice, 27 * this list of conditions and the following disclaimer. Redistributions 28 * in binary form must reproduce the above copyright notice, this list of 29 * conditions and the following disclaimer in the documentation and/or 30 * other materials provided with the distribution. Neither the name of 31 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 32 * contributors may be used to endorse or promote products derived from 33 * this software without specific prior written permission. No right of 34 * sublicense is granted herewith. Derivatives of the software and 35 * output created using the software may be prepared, but only for 36 * Non-Commercial Uses. Derivatives of the software may be shared with 37 * others provided: (i) the others agree to abide by the list of 38 * conditions herein which includes the Non-Commercial Use restrictions; 39 * and (ii) such Derivatives of the software include the above copyright 40 * notice to acknowledge the contribution from this software where 41 * applicable, this list of conditions and the disclaimer below. 42 * 43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 * 55 * Authors: Gabe Black 56 */ 57 58#include <cstring> 59 60#include "config/full_system.hh" 61 62#include "arch/x86/pagetable.hh" 63#include "arch/x86/tlb.hh" 64#include "base/bitfield.hh" 65#include "base/trace.hh" 66#include "cpu/thread_context.hh" 67#include "cpu/base.hh" 68#include "mem/packet_access.hh" 69#include "mem/request.hh" 70#include "sim/system.hh" 71 72namespace X86ISA { 73 74TLB::TLB(const Params *p) : SimObject(p), size(p->size) 75{ 76 tlb = new TlbEntry[size]; 77 std::memset(tlb, 0, sizeof(TlbEntry) * size); 78 79 for (int x = 0; x < size; x++) 80 freeList.push_back(&tlb[x]); 81} 82 83void 84TLB::insert(Addr vpn, TlbEntry &entry) 85{ 86 //TODO Deal with conflicting entries 87 88 TlbEntry *newEntry = NULL; 89 if (!freeList.empty()) { 90 newEntry = freeList.front(); 91 freeList.pop_front(); 92 } else { 93 newEntry = entryList.back(); 94 entryList.pop_back(); 95 } 96 *newEntry = entry; 97 newEntry->vaddr = vpn; 98 entryList.push_front(newEntry); 99} 100 101TlbEntry * 102TLB::lookup(Addr va, bool update_lru) 103{ 104 //TODO make this smarter at some point 105 EntryList::iterator entry; 106 for (entry = entryList.begin(); entry != entryList.end(); entry++) { 107 if ((*entry)->vaddr <= va && (*entry)->vaddr + (*entry)->size > va) { 108 DPRINTF(TLB, "Matched vaddr %#x to entry starting at %#x " 109 "with size %#x.\n", va, (*entry)->vaddr, (*entry)->size); 110 TlbEntry *e = *entry; 111 if (update_lru) { 112 entryList.erase(entry); 113 entryList.push_front(e); 114 } 115 return e; 116 } 117 } 118 return NULL; 119} 120 121void 122TLB::invalidateAll() 123{ 124} 125 126void 127TLB::invalidateNonGlobal() 128{ 129} 130 131void 132TLB::demapPage(Addr va) 133{ 134} 135 136Fault 137ITB::translate(RequestPtr &req, ThreadContext *tc) 138{ 139 Addr vaddr = req->getVaddr(); 140 // Check against the limit of the CS segment, and permissions. 141 // The vaddr already has the segment base applied. 142 TlbEntry *entry = lookup(vaddr); 143 if (!entry) { 144#if FULL_SYSTEM 145 return new FakeITLBFault(); 146#else 147 return new FakeITLBFault(vaddr); 148#endif 149 } else { 150 Addr paddr = entry->pageStart | (vaddr & mask(12)); 151 DPRINTF(TLB, "Translated %#x to %#x\n", vaddr, paddr); 152 req->setPaddr(paddr); 153 } 154 155 return NoFault; 156} 157 158Fault 159DTB::translate(RequestPtr &req, ThreadContext *tc, bool write) 160{ 161 Addr vaddr = req->getVaddr(); 162 uint32_t flags = req->getFlags(); 163 bool storeCheck = flags & StoreCheck; 164 int seg = flags & (mask(NUM_SEGMENTREGS)); 165 166 //XXX Junk code to surpress the warning 167 if (storeCheck) seg = seg; 168 169 // Check the limit of the segment "seg", and permissions. 170 // The vaddr already has the segment base applied. 171 TlbEntry *entry = lookup(vaddr); 172 if (!entry) { 173#if FULL_SYSTEM 174 return new FakeDTLBFault(); 175#else 176 return new FakeDTLBFault(vaddr); 177#endif 178 } else { 179 Addr paddr = entry->pageStart | (vaddr & mask(12)); 180 req->setPaddr(paddr); 181 } 182 return NoFault; 183}; 184 185#if FULL_SYSTEM 186 187Tick 188DTB::doMmuRegRead(ThreadContext *tc, Packet *pkt) 189{ 190 return tc->getCpuPtr()->ticks(1); 191} 192 193Tick 194DTB::doMmuRegWrite(ThreadContext *tc, Packet *pkt) 195{ 196 return tc->getCpuPtr()->ticks(1); 197} 198 199#endif 200 201void 202TLB::serialize(std::ostream &os) 203{ 204} 205 206void 207TLB::unserialize(Checkpoint *cp, const std::string §ion) 208{ 209} 210 211void 212DTB::serialize(std::ostream &os) 213{ 214 TLB::serialize(os); 215} 216 217void 218DTB::unserialize(Checkpoint *cp, const std::string §ion) 219{ 220 TLB::unserialize(cp, section); 221} 222 223/* end namespace X86ISA */ } 224 225X86ISA::ITB * 226X86ITBParams::create() 227{ 228 return new X86ISA::ITB(this); 229} 230 231X86ISA::DTB * 232X86DTBParams::create() 233{ 234 return new X86ISA::DTB(this); 235} 236