tlb.hh revision 4997
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; } 644967Sacolyte@umich.edu PTE *lookup(Addr vpn, uint8_t asn); 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 934960Sgblack@eecs.umich.edu PTE *PTECache[3]; 944960Sgblack@eecs.umich.edu inline void flushCache() { memset(PTECache, 0, 3 * sizeof(PTE*)); } 954967Sacolyte@umich.edu inline PTE* updateCache(PTE *pte) { 964967Sacolyte@umich.edu PTECache[2] = PTECache[1]; 974967Sacolyte@umich.edu PTECache[1] = PTECache[0]; 984967Sacolyte@umich.edu PTECache[0] = pte; 994967Sacolyte@umich.edu return pte; 1004967Sacolyte@umich.edu } 1013453Sgblack@eecs.umich.edu }; 1022SN/A 1033453Sgblack@eecs.umich.edu class ITB : public TLB 1043453Sgblack@eecs.umich.edu { 1053453Sgblack@eecs.umich.edu protected: 1063453Sgblack@eecs.umich.edu mutable Stats::Scalar<> hits; 1073453Sgblack@eecs.umich.edu mutable Stats::Scalar<> misses; 1083453Sgblack@eecs.umich.edu mutable Stats::Scalar<> acv; 1093453Sgblack@eecs.umich.edu mutable Stats::Formula accesses; 1102SN/A 1113453Sgblack@eecs.umich.edu public: 1123453Sgblack@eecs.umich.edu ITB(const std::string &name, int size); 1133453Sgblack@eecs.umich.edu virtual void regStats(); 1142SN/A 1154967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc); 1163453Sgblack@eecs.umich.edu }; 1172SN/A 1183453Sgblack@eecs.umich.edu class DTB : public TLB 1193453Sgblack@eecs.umich.edu { 1203453Sgblack@eecs.umich.edu protected: 1213453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_hits; 1223453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_misses; 1233453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_acv; 1243453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_accesses; 1253453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_hits; 1263453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_misses; 1273453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_acv; 1283453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_accesses; 1293453Sgblack@eecs.umich.edu Stats::Formula hits; 1303453Sgblack@eecs.umich.edu Stats::Formula misses; 1313453Sgblack@eecs.umich.edu Stats::Formula acv; 1323453Sgblack@eecs.umich.edu Stats::Formula accesses; 1332SN/A 1343453Sgblack@eecs.umich.edu public: 1353453Sgblack@eecs.umich.edu DTB(const std::string &name, int size); 1363453Sgblack@eecs.umich.edu virtual void regStats(); 1373453Sgblack@eecs.umich.edu 1384967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc, bool write); 1393453Sgblack@eecs.umich.edu }; 1403453Sgblack@eecs.umich.edu} 1412SN/A 1422SN/A#endif // __ALPHA_MEMORY_HH__ 143