tlb.hh revision 5004
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{ 515004Sgblack@eecs.umich.edu class TlbEntry; 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; 575004Sgblack@eecs.umich.edu PageTable lookupTable; // Quick lookup into page table 582SN/A 595004Sgblack@eecs.umich.edu TlbEntry *table; // the Page Table 605004Sgblack@eecs.umich.edu int size; // TLB Size 615004Sgblack@eecs.umich.edu int nlu; // not last used entry (for replacement) 622SN/A 633453Sgblack@eecs.umich.edu void nextnlu() { if (++nlu >= size) nlu = 0; } 645004Sgblack@eecs.umich.edu TlbEntry *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 725004Sgblack@eecs.umich.edu TlbEntry &index(bool advance = true); 735004Sgblack@eecs.umich.edu void insert(Addr vaddr, TlbEntry &entry); 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 935004Sgblack@eecs.umich.edu TlbEntry *EntryCache[3]; 945004Sgblack@eecs.umich.edu inline void flushCache() 955004Sgblack@eecs.umich.edu { 965004Sgblack@eecs.umich.edu memset(EntryCache, 0, 3 * sizeof(TlbEntry*)); 975004Sgblack@eecs.umich.edu } 985004Sgblack@eecs.umich.edu 995004Sgblack@eecs.umich.edu inline TlbEntry* updateCache(TlbEntry *entry) { 1005004Sgblack@eecs.umich.edu EntryCache[2] = EntryCache[1]; 1015004Sgblack@eecs.umich.edu EntryCache[1] = EntryCache[0]; 1025004Sgblack@eecs.umich.edu EntryCache[0] = entry; 1035004Sgblack@eecs.umich.edu return entry; 1044967Sacolyte@umich.edu } 1053453Sgblack@eecs.umich.edu }; 1062SN/A 1073453Sgblack@eecs.umich.edu class ITB : public TLB 1083453Sgblack@eecs.umich.edu { 1093453Sgblack@eecs.umich.edu protected: 1103453Sgblack@eecs.umich.edu mutable Stats::Scalar<> hits; 1113453Sgblack@eecs.umich.edu mutable Stats::Scalar<> misses; 1123453Sgblack@eecs.umich.edu mutable Stats::Scalar<> acv; 1133453Sgblack@eecs.umich.edu mutable Stats::Formula accesses; 1142SN/A 1153453Sgblack@eecs.umich.edu public: 1163453Sgblack@eecs.umich.edu ITB(const std::string &name, int size); 1173453Sgblack@eecs.umich.edu virtual void regStats(); 1182SN/A 1194967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc); 1203453Sgblack@eecs.umich.edu }; 1212SN/A 1223453Sgblack@eecs.umich.edu class DTB : public TLB 1233453Sgblack@eecs.umich.edu { 1243453Sgblack@eecs.umich.edu protected: 1253453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_hits; 1263453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_misses; 1273453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_acv; 1283453Sgblack@eecs.umich.edu mutable Stats::Scalar<> read_accesses; 1293453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_hits; 1303453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_misses; 1313453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_acv; 1323453Sgblack@eecs.umich.edu mutable Stats::Scalar<> write_accesses; 1333453Sgblack@eecs.umich.edu Stats::Formula hits; 1343453Sgblack@eecs.umich.edu Stats::Formula misses; 1353453Sgblack@eecs.umich.edu Stats::Formula acv; 1363453Sgblack@eecs.umich.edu Stats::Formula accesses; 1372SN/A 1383453Sgblack@eecs.umich.edu public: 1393453Sgblack@eecs.umich.edu DTB(const std::string &name, int size); 1403453Sgblack@eecs.umich.edu virtual void regStats(); 1413453Sgblack@eecs.umich.edu 1424967Sacolyte@umich.edu Fault translate(RequestPtr &req, ThreadContext *tc, bool write); 1433453Sgblack@eecs.umich.edu }; 1443453Sgblack@eecs.umich.edu} 1452SN/A 1462SN/A#endif // __ALPHA_MEMORY_HH__ 147