tlb.hh revision 4957
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 352SN/A#include <map> 362SN/A 372432SN/A#include "arch/alpha/ev5.hh" 381147SN/A#include "arch/alpha/isa_traits.hh" 393453Sgblack@eecs.umich.edu#include "arch/alpha/pagetable.hh" 402984Sgblack@eecs.umich.edu#include "arch/alpha/utility.hh" 412984Sgblack@eecs.umich.edu#include "arch/alpha/vtophys.hh" 421147SN/A#include "base/statistics.hh" 432517SN/A#include "mem/request.hh" 442984Sgblack@eecs.umich.edu#include "sim/faults.hh" 4556SN/A#include "sim/sim_object.hh" 462SN/A 472680Sktlim@umich.educlass ThreadContext; 482SN/A 493453Sgblack@eecs.umich.edunamespace AlphaISA 502SN/A{ 513453Sgblack@eecs.umich.edu class PTE; 522SN/A 533453Sgblack@eecs.umich.edu class TLB : public SimObject 543453Sgblack@eecs.umich.edu { 553453Sgblack@eecs.umich.edu protected: 563453Sgblack@eecs.umich.edu typedef std::multimap<Addr, int> PageTable; 573453Sgblack@eecs.umich.edu PageTable lookupTable; // Quick lookup into page table 582SN/A 593453Sgblack@eecs.umich.edu PTE *table; // the Page Table 603453Sgblack@eecs.umich.edu int size; // TLB Size 613453Sgblack@eecs.umich.edu int nlu; // not last used entry (for replacement) 622SN/A 633453Sgblack@eecs.umich.edu void nextnlu() { if (++nlu >= size) nlu = 0; } 643453Sgblack@eecs.umich.edu PTE *lookup(Addr vpn, uint8_t asn) const; 652SN/A 663453Sgblack@eecs.umich.edu public: 673453Sgblack@eecs.umich.edu TLB(const std::string &name, int size); 683453Sgblack@eecs.umich.edu virtual ~TLB(); 692SN/A 703453Sgblack@eecs.umich.edu int getsize() const { return size; } 712SN/A 723453Sgblack@eecs.umich.edu PTE &index(bool advance = true); 733453Sgblack@eecs.umich.edu void insert(Addr vaddr, PTE &pte); 742SN/A 753453Sgblack@eecs.umich.edu void flushAll(); 763453Sgblack@eecs.umich.edu void flushProcesses(); 773453Sgblack@eecs.umich.edu void flushAddr(Addr addr, uint8_t asn); 782SN/A 793453Sgblack@eecs.umich.edu // static helper functions... really EV5 VM traits 803453Sgblack@eecs.umich.edu static bool validVirtualAddress(Addr vaddr) { 813453Sgblack@eecs.umich.edu // unimplemented bits must be all 0 or all 1 823453Sgblack@eecs.umich.edu Addr unimplBits = vaddr & EV5::VAddrUnImplMask; 833453Sgblack@eecs.umich.edu return (unimplBits == 0) || (unimplBits == EV5::VAddrUnImplMask); 843453Sgblack@eecs.umich.edu } 852SN/A 863453Sgblack@eecs.umich.edu static Fault checkCacheability(RequestPtr &req); 872SN/A 883453Sgblack@eecs.umich.edu // Checkpointing 893453Sgblack@eecs.umich.edu virtual void serialize(std::ostream &os); 903453Sgblack@eecs.umich.edu virtual void unserialize(Checkpoint *cp, const std::string §ion); 914957Sacolyte@umich.edu 924957Sacolyte@umich.edu // Most recently used page table entries 934957Sacolyte@umich.edu PTE *PTECache[2]; 944957Sacolyte@umich.edu inline void flushCache() { memset(PTECache, 0, 2 * sizeof(PTE*)); } 953453Sgblack@eecs.umich.edu }; 962SN/A 973453Sgblack@eecs.umich.edu class ITB : public TLB 983453Sgblack@eecs.umich.edu { 993453Sgblack@eecs.umich.edu protected: 1003453Sgblack@eecs.umich.edu mutable Stats::Scalar<> hits; 1013453Sgblack@eecs.umich.edu mutable Stats::Scalar<> misses; 1023453Sgblack@eecs.umich.edu mutable Stats::Scalar<> acv; 1033453Sgblack@eecs.umich.edu mutable Stats::Formula accesses; 1042SN/A 1053453Sgblack@eecs.umich.edu public: 1063453Sgblack@eecs.umich.edu ITB(const std::string &name, int size); 1073453Sgblack@eecs.umich.edu virtual void regStats(); 1082SN/A 1093453Sgblack@eecs.umich.edu Fault translate(RequestPtr &req, ThreadContext *tc) const; 1103453Sgblack@eecs.umich.edu }; 1112SN/A 1123453Sgblack@eecs.umich.edu class DTB : public TLB 1133453Sgblack@eecs.umich.edu { 1143453Sgblack@eecs.umich.edu protected: 1153453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_hits; 1163453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_misses; 1173453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_acv; 1183453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_accesses; 1193453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_hits; 1203453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_misses; 1213453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_acv; 1223453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_accesses; 1233453Sgblack@eecs.umich.edu Stats::Formula hits; 1243453Sgblack@eecs.umich.edu Stats::Formula misses; 1253453Sgblack@eecs.umich.edu Stats::Formula acv; 1263453Sgblack@eecs.umich.edu Stats::Formula accesses; 1272SN/A 1283453Sgblack@eecs.umich.edu public: 1293453Sgblack@eecs.umich.edu DTB(const std::string &name, int size); 1303453Sgblack@eecs.umich.edu virtual void regStats(); 1313453Sgblack@eecs.umich.edu 1323453Sgblack@eecs.umich.edu Fault translate(RequestPtr &req, ThreadContext *tc, bool write) const; 1333453Sgblack@eecs.umich.edu }; 1343453Sgblack@eecs.umich.edu} 1352SN/A 1362SN/A#endif // __ALPHA_MEMORY_HH__ 137