tlb.hh revision 6020
16019Shines@cs.fsu.edu/* 26019Shines@cs.fsu.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan 36019Shines@cs.fsu.edu * Copyright (c) 2007 MIPS Technologies, Inc. 46019Shines@cs.fsu.edu * Copyright (c) 2007-2008 The Florida State University 56019Shines@cs.fsu.edu * All rights reserved. 66019Shines@cs.fsu.edu * 76019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without 86019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are 96019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright 106019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer; 116019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright 126019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the 136019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution; 146019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its 156019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from 166019Shines@cs.fsu.edu * this software without specific prior written permission. 176019Shines@cs.fsu.edu * 186019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 196019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 206019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 216019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 226019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 236019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 246019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 256019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 266019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 276019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 286019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 296019Shines@cs.fsu.edu * 306019Shines@cs.fsu.edu * Authors: Nathan Binkert 316019Shines@cs.fsu.edu * Steve Reinhardt 326019Shines@cs.fsu.edu * Stephen Hines 336019Shines@cs.fsu.edu */ 346019Shines@cs.fsu.edu 356019Shines@cs.fsu.edu#ifndef __ARCH_ARM_TLB_HH__ 366019Shines@cs.fsu.edu#define __ARCH_ARM_TLB_HH__ 376019Shines@cs.fsu.edu 386019Shines@cs.fsu.edu#include <map> 396019Shines@cs.fsu.edu 406019Shines@cs.fsu.edu#include "arch/arm/isa_traits.hh" 416019Shines@cs.fsu.edu#include "arch/arm/utility.hh" 426019Shines@cs.fsu.edu#include "arch/arm/vtophys.hh" 436019Shines@cs.fsu.edu#include "arch/arm/pagetable.hh" 446019Shines@cs.fsu.edu#include "base/statistics.hh" 456019Shines@cs.fsu.edu#include "mem/request.hh" 466019Shines@cs.fsu.edu#include "params/ArmDTB.hh" 476019Shines@cs.fsu.edu#include "params/ArmITB.hh" 486019Shines@cs.fsu.edu#include "sim/faults.hh" 496019Shines@cs.fsu.edu#include "sim/tlb.hh" 506019Shines@cs.fsu.edu 516019Shines@cs.fsu.educlass ThreadContext; 526019Shines@cs.fsu.edu 536019Shines@cs.fsu.edu/* ARM does not distinguish between a DTLB and an ITLB -> unified TLB 546019Shines@cs.fsu.edu However, to maintain compatibility with other architectures, we'll 556019Shines@cs.fsu.edu simply create an ITLB and DTLB that will point to the real TLB */ 566019Shines@cs.fsu.edunamespace ArmISA { 576019Shines@cs.fsu.edu 586019Shines@cs.fsu.edu// WARN: This particular TLB entry is not necessarily conformed to ARM ISA 596019Shines@cs.fsu.edustruct TlbEntry 606019Shines@cs.fsu.edu{ 616019Shines@cs.fsu.edu Addr _pageStart; 626019Shines@cs.fsu.edu TlbEntry() {} 636019Shines@cs.fsu.edu TlbEntry(Addr asn, Addr vaddr, Addr paddr) : _pageStart(paddr) {} 646019Shines@cs.fsu.edu 656020Sgblack@eecs.umich.edu void 666020Sgblack@eecs.umich.edu updateVaddr(Addr new_vaddr) 676020Sgblack@eecs.umich.edu { 686020Sgblack@eecs.umich.edu panic("unimplemented"); 696020Sgblack@eecs.umich.edu } 706020Sgblack@eecs.umich.edu 716019Shines@cs.fsu.edu Addr pageStart() 726019Shines@cs.fsu.edu { 736019Shines@cs.fsu.edu return _pageStart; 746019Shines@cs.fsu.edu } 756019Shines@cs.fsu.edu 766019Shines@cs.fsu.edu void serialize(std::ostream &os) 776019Shines@cs.fsu.edu { 786019Shines@cs.fsu.edu SERIALIZE_SCALAR(_pageStart); 796019Shines@cs.fsu.edu } 806019Shines@cs.fsu.edu 816019Shines@cs.fsu.edu void unserialize(Checkpoint *cp, const std::string §ion) 826019Shines@cs.fsu.edu { 836019Shines@cs.fsu.edu UNSERIALIZE_SCALAR(_pageStart); 846019Shines@cs.fsu.edu } 856019Shines@cs.fsu.edu 866019Shines@cs.fsu.edu}; 876019Shines@cs.fsu.edu 886019Shines@cs.fsu.educlass TLB : public BaseTLB 896019Shines@cs.fsu.edu{ 906019Shines@cs.fsu.edu protected: 916019Shines@cs.fsu.edu typedef std::multimap<Addr, int> PageTable; 926019Shines@cs.fsu.edu PageTable lookupTable; // Quick lookup into page table 936019Shines@cs.fsu.edu 946019Shines@cs.fsu.edu ArmISA::PTE *table; // the Page Table 956019Shines@cs.fsu.edu int size; // TLB Size 966019Shines@cs.fsu.edu int nlu; // not last used entry (for replacement) 976019Shines@cs.fsu.edu 986019Shines@cs.fsu.edu void nextnlu() { if (++nlu >= size) nlu = 0; } 996019Shines@cs.fsu.edu ArmISA::PTE *lookup(Addr vpn, uint8_t asn) const; 1006019Shines@cs.fsu.edu 1016020Sgblack@eecs.umich.edu mutable Stats::Scalar read_hits; 1026020Sgblack@eecs.umich.edu mutable Stats::Scalar read_misses; 1036020Sgblack@eecs.umich.edu mutable Stats::Scalar read_acv; 1046020Sgblack@eecs.umich.edu mutable Stats::Scalar read_accesses; 1056020Sgblack@eecs.umich.edu mutable Stats::Scalar write_hits; 1066020Sgblack@eecs.umich.edu mutable Stats::Scalar write_misses; 1076020Sgblack@eecs.umich.edu mutable Stats::Scalar write_acv; 1086020Sgblack@eecs.umich.edu mutable Stats::Scalar write_accesses; 1096019Shines@cs.fsu.edu Stats::Formula hits; 1106019Shines@cs.fsu.edu Stats::Formula misses; 1116019Shines@cs.fsu.edu Stats::Formula invalids; 1126019Shines@cs.fsu.edu Stats::Formula accesses; 1136019Shines@cs.fsu.edu 1146019Shines@cs.fsu.edu public: 1156019Shines@cs.fsu.edu typedef ArmTLBParams Params; 1166019Shines@cs.fsu.edu TLB(const Params *p); 1176019Shines@cs.fsu.edu 1186019Shines@cs.fsu.edu int probeEntry(Addr vpn,uint8_t) const; 1196019Shines@cs.fsu.edu ArmISA::PTE *getEntry(unsigned) const; 1206019Shines@cs.fsu.edu virtual ~TLB(); 1216019Shines@cs.fsu.edu int smallPages; 1226019Shines@cs.fsu.edu int getsize() const { return size; } 1236019Shines@cs.fsu.edu 1246019Shines@cs.fsu.edu ArmISA::PTE &index(bool advance = true); 1256019Shines@cs.fsu.edu void insert(Addr vaddr, ArmISA::PTE &pte); 1266019Shines@cs.fsu.edu void insertAt(ArmISA::PTE &pte, unsigned Index, int _smallPages); 1276019Shines@cs.fsu.edu void flushAll(); 1286019Shines@cs.fsu.edu void demapPage(Addr vaddr, uint64_t asn) 1296019Shines@cs.fsu.edu { 1306019Shines@cs.fsu.edu panic("demapPage unimplemented.\n"); 1316019Shines@cs.fsu.edu } 1326019Shines@cs.fsu.edu 1336019Shines@cs.fsu.edu // static helper functions... really 1346019Shines@cs.fsu.edu static bool validVirtualAddress(Addr vaddr); 1356019Shines@cs.fsu.edu 1366019Shines@cs.fsu.edu static Fault checkCacheability(RequestPtr &req); 1376019Shines@cs.fsu.edu 1386019Shines@cs.fsu.edu // Checkpointing 1396019Shines@cs.fsu.edu void serialize(std::ostream &os); 1406019Shines@cs.fsu.edu void unserialize(Checkpoint *cp, const std::string §ion); 1416019Shines@cs.fsu.edu 1426019Shines@cs.fsu.edu void regStats(); 1436019Shines@cs.fsu.edu}; 1446019Shines@cs.fsu.edu 1456020Sgblack@eecs.umich.educlass ITB : public TLB 1466020Sgblack@eecs.umich.edu{ 1476019Shines@cs.fsu.edu public: 1486019Shines@cs.fsu.edu typedef ArmTLBParams Params; 1496019Shines@cs.fsu.edu ITB(const Params *p); 1506019Shines@cs.fsu.edu 1516020Sgblack@eecs.umich.edu Fault translateAtomic(RequestPtr req, ThreadContext *tc); 1526020Sgblack@eecs.umich.edu void translateTiming(RequestPtr req, ThreadContext *tc, 1536020Sgblack@eecs.umich.edu Translation *translation); 1546019Shines@cs.fsu.edu}; 1556019Shines@cs.fsu.edu 1566020Sgblack@eecs.umich.educlass DTB : public TLB 1576020Sgblack@eecs.umich.edu{ 1586019Shines@cs.fsu.edu public: 1596019Shines@cs.fsu.edu typedef ArmTLBParams Params; 1606019Shines@cs.fsu.edu DTB(const Params *p); 1616019Shines@cs.fsu.edu 1626020Sgblack@eecs.umich.edu Fault translateAtomic(RequestPtr req, ThreadContext *tc, bool write); 1636020Sgblack@eecs.umich.edu void translateTiming(RequestPtr req, ThreadContext *tc, 1646020Sgblack@eecs.umich.edu Translation *translation, bool write); 1656019Shines@cs.fsu.edu}; 1666019Shines@cs.fsu.edu 1676020Sgblack@eecs.umich.educlass UTB : public ITB, public DTB 1686020Sgblack@eecs.umich.edu{ 1696019Shines@cs.fsu.edu public: 1706019Shines@cs.fsu.edu typedef ArmTLBParams Params; 1716019Shines@cs.fsu.edu UTB(const Params *p); 1726019Shines@cs.fsu.edu 1736019Shines@cs.fsu.edu}; 1746019Shines@cs.fsu.edu 1756019Shines@cs.fsu.edu} 1766019Shines@cs.fsu.edu 1776019Shines@cs.fsu.edu#endif // __ARCH_ARM_TLB_HH__ 178