tlb.hh revision 5532:d8ab33f5ff9a
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302SN/A */ 312SN/A 322SN/A#ifndef __ALPHA_MEMORY_HH__ 332SN/A#define __ALPHA_MEMORY_HH__ 342SN/A 355218Ssaidi@eecs.umich.edu#include <map> 361717SN/A 372680Sktlim@umich.edu#include "arch/alpha/ev5.hh" 3856SN/A#include "arch/alpha/isa_traits.hh" 3956SN/A#include "arch/alpha/pagetable.hh" 402SN/A#include "arch/alpha/utility.hh" 412SN/A#include "arch/alpha/vtophys.hh" 422SN/A#include "base/statistics.hh" 435034Smilesck@eecs.umich.edu#include "mem/request.hh" 445034Smilesck@eecs.umich.edu#include "params/AlphaDTB.hh" 452SN/A#include "params/AlphaITB.hh" 462SN/A#include "sim/faults.hh" 47295SN/A#include "sim/tlb.hh" 48295SN/A 49295SN/Aclass ThreadContext; 505218Ssaidi@eecs.umich.edu 514103Ssaidi@eecs.umich.edunamespace AlphaISA 525218Ssaidi@eecs.umich.edu{ 535218Ssaidi@eecs.umich.edu class TlbEntry; 54295SN/A 55295SN/A class TLB : public BaseTLB 56295SN/A { 57295SN/A protected: 58295SN/A typedef std::multimap<Addr, int> PageTable; 595218Ssaidi@eecs.umich.edu PageTable lookupTable; // Quick lookup into page table 604103Ssaidi@eecs.umich.edu 615218Ssaidi@eecs.umich.edu TlbEntry *table; // the Page Table 625218Ssaidi@eecs.umich.edu int size; // TLB Size 63295SN/A int nlu; // not last used entry (for replacement) 64295SN/A 654762Snate@binkert.org void nextnlu() { if (++nlu >= size) nlu = 0; } 664762Snate@binkert.org TlbEntry *lookup(Addr vpn, uint8_t asn); 672SN/A 685034Smilesck@eecs.umich.edu public: 692SN/A typedef AlphaTLBParams Params; 70 TLB(const Params *p); 71 virtual ~TLB(); 72 73 int getsize() const { return size; } 74 75 TlbEntry &index(bool advance = true); 76 void insert(Addr vaddr, TlbEntry &entry); 77 78 void flushAll(); 79 void flushProcesses(); 80 void flushAddr(Addr addr, uint8_t asn); 81 82 void demapPage(Addr vaddr, uint64_t asn) 83 { 84 assert(asn < (1 << 8)); 85 flushAddr(vaddr, asn); 86 } 87 88 // static helper functions... really EV5 VM traits 89 static bool validVirtualAddress(Addr vaddr) { 90 // unimplemented bits must be all 0 or all 1 91 Addr unimplBits = vaddr & EV5::VAddrUnImplMask; 92 return (unimplBits == 0) || (unimplBits == EV5::VAddrUnImplMask); 93 } 94 95 static Fault checkCacheability(RequestPtr &req, bool itb = false); 96 97 // Checkpointing 98 virtual void serialize(std::ostream &os); 99 virtual void unserialize(Checkpoint *cp, const std::string §ion); 100 101 // Most recently used page table entries 102 TlbEntry *EntryCache[3]; 103 inline void flushCache() 104 { 105 memset(EntryCache, 0, 3 * sizeof(TlbEntry*)); 106 } 107 108 inline TlbEntry* updateCache(TlbEntry *entry) { 109 EntryCache[2] = EntryCache[1]; 110 EntryCache[1] = EntryCache[0]; 111 EntryCache[0] = entry; 112 return entry; 113 } 114 }; 115 116 class ITB : public TLB 117 { 118 protected: 119 mutable Stats::Scalar<> hits; 120 mutable Stats::Scalar<> misses; 121 mutable Stats::Scalar<> acv; 122 mutable Stats::Formula accesses; 123 124 public: 125 typedef AlphaITBParams Params; 126 ITB(const Params *p); 127 virtual void regStats(); 128 129 Fault translate(RequestPtr &req, ThreadContext *tc); 130 }; 131 132 class DTB : public TLB 133 { 134 protected: 135 mutable Stats::Scalar<> read_hits; 136 mutable Stats::Scalar<> read_misses; 137 mutable Stats::Scalar<> read_acv; 138 mutable Stats::Scalar<> read_accesses; 139 mutable Stats::Scalar<> write_hits; 140 mutable Stats::Scalar<> write_misses; 141 mutable Stats::Scalar<> write_acv; 142 mutable Stats::Scalar<> write_accesses; 143 Stats::Formula hits; 144 Stats::Formula misses; 145 Stats::Formula acv; 146 Stats::Formula accesses; 147 148 public: 149 typedef AlphaDTBParams Params; 150 DTB(const Params *p); 151 virtual void regStats(); 152 153 Fault translate(RequestPtr &req, ThreadContext *tc, bool write); 154 }; 155} 156 157#endif // __ALPHA_MEMORY_HH__ 158