tlb.hh revision 5222
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" 4756SN/A#include "sim/sim_object.hh" 482SN/A 492680Sktlim@umich.educlass ThreadContext; 502SN/A 513453Sgblack@eecs.umich.edunamespace AlphaISA 522SN/A{ 535004Sgblack@eecs.umich.edu class TlbEntry; 542SN/A 553453Sgblack@eecs.umich.edu class TLB : public SimObject 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 823453Sgblack@eecs.umich.edu // static helper functions... really EV5 VM traits 833453Sgblack@eecs.umich.edu static bool validVirtualAddress(Addr vaddr) { 843453Sgblack@eecs.umich.edu // unimplemented bits must be all 0 or all 1 853453Sgblack@eecs.umich.edu Addr unimplBits = vaddr & EV5::VAddrUnImplMask; 863453Sgblack@eecs.umich.edu return (unimplBits == 0) || (unimplBits == EV5::VAddrUnImplMask); 873453Sgblack@eecs.umich.edu } 882SN/A 893453Sgblack@eecs.umich.edu static Fault checkCacheability(RequestPtr &req); 902SN/A 913453Sgblack@eecs.umich.edu // Checkpointing 923453Sgblack@eecs.umich.edu virtual void serialize(std::ostream &os); 933453Sgblack@eecs.umich.edu virtual void unserialize(Checkpoint *cp, const std::string §ion); 944957Sacolyte@umich.edu 954957Sacolyte@umich.edu // Most recently used page table entries 965004Sgblack@eecs.umich.edu TlbEntry *EntryCache[3]; 975004Sgblack@eecs.umich.edu inline void flushCache() 985004Sgblack@eecs.umich.edu { 995004Sgblack@eecs.umich.edu memset(EntryCache, 0, 3 * sizeof(TlbEntry*)); 1005004Sgblack@eecs.umich.edu } 1015004Sgblack@eecs.umich.edu 1025004Sgblack@eecs.umich.edu inline TlbEntry* updateCache(TlbEntry *entry) { 1035004Sgblack@eecs.umich.edu EntryCache[2] = EntryCache[1]; 1045004Sgblack@eecs.umich.edu EntryCache[1] = EntryCache[0]; 1055004Sgblack@eecs.umich.edu EntryCache[0] = entry; 1065004Sgblack@eecs.umich.edu return entry; 1074967Sacolyte@umich.edu } 1083453Sgblack@eecs.umich.edu }; 1092SN/A 1103453Sgblack@eecs.umich.edu class ITB : public TLB 1113453Sgblack@eecs.umich.edu { 1123453Sgblack@eecs.umich.edu protected: 1133453Sgblack@eecs.umich.edu mutable Stats::Scalar<> hits; 1143453Sgblack@eecs.umich.edu mutable Stats::Scalar<> misses; 1153453Sgblack@eecs.umich.edu mutable Stats::Scalar<> acv; 1163453Sgblack@eecs.umich.edu mutable Stats::Formula accesses; 1172SN/A 1183453Sgblack@eecs.umich.edu public: 1195034Smilesck@eecs.umich.edu typedef AlphaITBParams Params; 1205034Smilesck@eecs.umich.edu ITB(const Params *p); 1213453Sgblack@eecs.umich.edu virtual void regStats(); 1222SN/A 1234967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc); 1243453Sgblack@eecs.umich.edu }; 1252SN/A 1263453Sgblack@eecs.umich.edu class DTB : public TLB 1273453Sgblack@eecs.umich.edu { 1283453Sgblack@eecs.umich.edu protected: 1293453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_hits; 1303453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_misses; 1313453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_acv; 1323453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_accesses; 1333453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_hits; 1343453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_misses; 1353453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_acv; 1363453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_accesses; 1373453Sgblack@eecs.umich.edu Stats::Formula hits; 1383453Sgblack@eecs.umich.edu Stats::Formula misses; 1393453Sgblack@eecs.umich.edu Stats::Formula acv; 1403453Sgblack@eecs.umich.edu Stats::Formula accesses; 1412SN/A 1423453Sgblack@eecs.umich.edu public: 1435034Smilesck@eecs.umich.edu typedef AlphaDTBParams Params; 1445034Smilesck@eecs.umich.edu DTB(const Params *p); 1453453Sgblack@eecs.umich.edu virtual void regStats(); 1463453Sgblack@eecs.umich.edu 1474967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc, bool write); 1483453Sgblack@eecs.umich.edu }; 1493453Sgblack@eecs.umich.edu} 1502SN/A 1512SN/A#endif // __ALPHA_MEMORY_HH__ 152