tlb.hh revision 5543
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" 445034Smilesck@eecs.umich.edu#include "params/AlphaDTB.hh" 455034Smilesck@eecs.umich.edu#include "params/AlphaITB.hh" 462984Sgblack@eecs.umich.edu#include "sim/faults.hh" 475358Sgblack@eecs.umich.edu#include "sim/tlb.hh" 482SN/A 492680Sktlim@umich.educlass ThreadContext; 502SN/A 513453Sgblack@eecs.umich.edunamespace AlphaISA 522SN/A{ 535004Sgblack@eecs.umich.edu class TlbEntry; 542SN/A 555358Sgblack@eecs.umich.edu class TLB : public BaseTLB 563453Sgblack@eecs.umich.edu { 573453Sgblack@eecs.umich.edu protected: 583453Sgblack@eecs.umich.edu typedef std::multimap<Addr, int> PageTable; 595004Sgblack@eecs.umich.edu PageTable lookupTable; // Quick lookup into page table 602SN/A 615004Sgblack@eecs.umich.edu TlbEntry *table; // the Page Table 625004Sgblack@eecs.umich.edu int size; // TLB Size 635004Sgblack@eecs.umich.edu int nlu; // not last used entry (for replacement) 642SN/A 653453Sgblack@eecs.umich.edu void nextnlu() { if (++nlu >= size) nlu = 0; } 665004Sgblack@eecs.umich.edu TlbEntry *lookup(Addr vpn, uint8_t asn); 672SN/A 683453Sgblack@eecs.umich.edu public: 695034Smilesck@eecs.umich.edu typedef AlphaTLBParams Params; 705034Smilesck@eecs.umich.edu TLB(const Params *p); 713453Sgblack@eecs.umich.edu virtual ~TLB(); 722SN/A 733453Sgblack@eecs.umich.edu int getsize() const { return size; } 742SN/A 755004Sgblack@eecs.umich.edu TlbEntry &index(bool advance = true); 765004Sgblack@eecs.umich.edu void insert(Addr vaddr, TlbEntry &entry); 772SN/A 783453Sgblack@eecs.umich.edu void flushAll(); 793453Sgblack@eecs.umich.edu void flushProcesses(); 803453Sgblack@eecs.umich.edu void flushAddr(Addr addr, uint8_t asn); 812SN/A 825358Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 835358Sgblack@eecs.umich.edu { 845358Sgblack@eecs.umich.edu assert(asn < (1 << 8)); 855358Sgblack@eecs.umich.edu flushAddr(vaddr, asn); 865358Sgblack@eecs.umich.edu } 875358Sgblack@eecs.umich.edu 883453Sgblack@eecs.umich.edu // static helper functions... really EV5 VM traits 893453Sgblack@eecs.umich.edu static bool validVirtualAddress(Addr vaddr) { 903453Sgblack@eecs.umich.edu // unimplemented bits must be all 0 or all 1 913453Sgblack@eecs.umich.edu Addr unimplBits = vaddr & EV5::VAddrUnImplMask; 923453Sgblack@eecs.umich.edu return (unimplBits == 0) || (unimplBits == EV5::VAddrUnImplMask); 933453Sgblack@eecs.umich.edu } 942SN/A 955532Ssaidi@eecs.umich.edu static Fault checkCacheability(RequestPtr &req, bool itb = false); 962SN/A 973453Sgblack@eecs.umich.edu // Checkpointing 983453Sgblack@eecs.umich.edu virtual void serialize(std::ostream &os); 993453Sgblack@eecs.umich.edu virtual void unserialize(Checkpoint *cp, const std::string §ion); 1004957Sacolyte@umich.edu 1014957Sacolyte@umich.edu // Most recently used page table entries 1025004Sgblack@eecs.umich.edu TlbEntry *EntryCache[3]; 1035004Sgblack@eecs.umich.edu inline void flushCache() 1045004Sgblack@eecs.umich.edu { 1055004Sgblack@eecs.umich.edu memset(EntryCache, 0, 3 * sizeof(TlbEntry*)); 1065004Sgblack@eecs.umich.edu } 1075004Sgblack@eecs.umich.edu 1085004Sgblack@eecs.umich.edu inline TlbEntry* updateCache(TlbEntry *entry) { 1095004Sgblack@eecs.umich.edu EntryCache[2] = EntryCache[1]; 1105004Sgblack@eecs.umich.edu EntryCache[1] = EntryCache[0]; 1115004Sgblack@eecs.umich.edu EntryCache[0] = entry; 1125004Sgblack@eecs.umich.edu return entry; 1134967Sacolyte@umich.edu } 1143453Sgblack@eecs.umich.edu }; 1152SN/A 1163453Sgblack@eecs.umich.edu class ITB : public TLB 1173453Sgblack@eecs.umich.edu { 1183453Sgblack@eecs.umich.edu protected: 1193453Sgblack@eecs.umich.edu mutable Stats::Scalar<> hits; 1203453Sgblack@eecs.umich.edu mutable Stats::Scalar<> misses; 1213453Sgblack@eecs.umich.edu mutable Stats::Scalar<> acv; 1223453Sgblack@eecs.umich.edu mutable Stats::Formula accesses; 1232SN/A 1243453Sgblack@eecs.umich.edu public: 1255034Smilesck@eecs.umich.edu typedef AlphaITBParams Params; 1265034Smilesck@eecs.umich.edu ITB(const Params *p); 1273453Sgblack@eecs.umich.edu virtual void regStats(); 1282SN/A 1294967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc); 1303453Sgblack@eecs.umich.edu }; 1312SN/A 1323453Sgblack@eecs.umich.edu class DTB : public TLB 1333453Sgblack@eecs.umich.edu { 1343453Sgblack@eecs.umich.edu protected: 1353453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_hits; 1363453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_misses; 1373453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_acv; 1383453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_accesses; 1393453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_hits; 1403453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_misses; 1413453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_acv; 1423453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_accesses; 1433453Sgblack@eecs.umich.edu Stats::Formula hits; 1443453Sgblack@eecs.umich.edu Stats::Formula misses; 1453453Sgblack@eecs.umich.edu Stats::Formula acv; 1463453Sgblack@eecs.umich.edu Stats::Formula accesses; 1472SN/A 1483453Sgblack@eecs.umich.edu public: 1495034Smilesck@eecs.umich.edu typedef AlphaDTBParams Params; 1505034Smilesck@eecs.umich.edu DTB(const Params *p); 1513453Sgblack@eecs.umich.edu virtual void regStats(); 1523453Sgblack@eecs.umich.edu 1534967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc, bool write); 1543453Sgblack@eecs.umich.edu }; 1553453Sgblack@eecs.umich.edu} 1562SN/A 1572SN/A#endif // __ALPHA_MEMORY_HH__ 158