tlb.hh revision 5891
12221SN/A/*
22221SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
32221SN/A * Copyright (c) 2007 MIPS Technologies, Inc.
42221SN/A * All rights reserved.
52221SN/A *
62221SN/A * Redistribution and use in source and binary forms, with or without
72221SN/A * modification, are permitted provided that the following conditions are
82221SN/A * met: redistributions of source code must retain the above copyright
92221SN/A * notice, this list of conditions and the following disclaimer;
102221SN/A * redistributions in binary form must reproduce the above copyright
112221SN/A * notice, this list of conditions and the following disclaimer in the
122221SN/A * documentation and/or other materials provided with the distribution;
132221SN/A * neither the name of the copyright holders nor the names of its
142221SN/A * contributors may be used to endorse or promote products derived from
152221SN/A * this software without specific prior written permission.
162221SN/A *
172221SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182221SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192221SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202221SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212221SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222221SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232221SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242221SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252221SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262221SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272665Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
302221SN/A *          Steve Reinhardt
312221SN/A *          Jaidev Patwardhan
323415Sgblack@eecs.umich.edu *          Korey Sewell
333415Sgblack@eecs.umich.edu */
342223SN/A
353415Sgblack@eecs.umich.edu#ifndef __ARCH_MIPS_TLB_HH__
363578Sgblack@eecs.umich.edu#define __ARCH_MIPS_TLB_HH__
373415Sgblack@eecs.umich.edu
383415Sgblack@eecs.umich.edu#include <map>
393523Sgblack@eecs.umich.edu
403415Sgblack@eecs.umich.edu#include "arch/mips/isa_traits.hh"
412680Sktlim@umich.edu#include "arch/mips/utility.hh"
422800Ssaidi@eecs.umich.edu#include "arch/mips/vtophys.hh"
433523Sgblack@eecs.umich.edu#include "arch/mips/pagetable.hh"
443415Sgblack@eecs.umich.edu#include "base/statistics.hh"
452800Ssaidi@eecs.umich.edu#include "mem/request.hh"
462800Ssaidi@eecs.umich.edu#include "params/MipsDTB.hh"
472221SN/A#include "params/MipsITB.hh"
483415Sgblack@eecs.umich.edu#include "sim/faults.hh"
493415Sgblack@eecs.umich.edu#include "sim/tlb.hh"
502223SN/A#include "sim/sim_object.hh"
512221SN/A
522221SN/Aclass ThreadContext;
533573Sgblack@eecs.umich.edu
543576Sgblack@eecs.umich.edu/* MIPS does not distinguish between a DTLB and an ITLB -> unified TLB
553576Sgblack@eecs.umich.edu   However, to maintain compatibility with other architectures, we'll
562221SN/A   simply create an ITLB and DTLB that will point to the real TLB */
573573Sgblack@eecs.umich.edunamespace MipsISA {
583576Sgblack@eecs.umich.edu
593576Sgblack@eecs.umich.edu// WARN: This particular TLB entry is not necessarily conformed to MIPS ISA
602221SN/Astruct TlbEntry
613573Sgblack@eecs.umich.edu{
623576Sgblack@eecs.umich.edu    Addr _pageStart;
633576Sgblack@eecs.umich.edu    TlbEntry() {}
642221SN/A    TlbEntry(Addr asn, Addr vaddr, Addr paddr) : _pageStart(paddr) {}
653573Sgblack@eecs.umich.edu
663576Sgblack@eecs.umich.edu    Addr pageStart()
673576Sgblack@eecs.umich.edu    {
682221SN/A        return _pageStart;
693573Sgblack@eecs.umich.edu    }
703576Sgblack@eecs.umich.edu
713576Sgblack@eecs.umich.edu    void
722221SN/A    updateVaddr(Addr new_vaddr) {}
733573Sgblack@eecs.umich.edu
743576Sgblack@eecs.umich.edu    void serialize(std::ostream &os)
753576Sgblack@eecs.umich.edu    {
762221SN/A        SERIALIZE_SCALAR(_pageStart);
773573Sgblack@eecs.umich.edu    }
783576Sgblack@eecs.umich.edu
793576Sgblack@eecs.umich.edu    void unserialize(Checkpoint *cp, const std::string &section)
803576Sgblack@eecs.umich.edu    {
813576Sgblack@eecs.umich.edu        UNSERIALIZE_SCALAR(_pageStart);
823576Sgblack@eecs.umich.edu    }
833576Sgblack@eecs.umich.edu
843576Sgblack@eecs.umich.edu};
852221SN/A
863573Sgblack@eecs.umich.educlass TLB : public BaseTLB
873576Sgblack@eecs.umich.edu{
883576Sgblack@eecs.umich.edu  protected:
892221SN/A    typedef std::multimap<Addr, int> PageTable;
903573Sgblack@eecs.umich.edu    PageTable lookupTable;      // Quick lookup into page table
913576Sgblack@eecs.umich.edu
923576Sgblack@eecs.umich.edu    MipsISA::PTE *table;        // the Page Table
932221SN/A    int size;                   // TLB Size
943573Sgblack@eecs.umich.edu    int nlu;                    // not last used entry (for replacement)
953576Sgblack@eecs.umich.edu
963576Sgblack@eecs.umich.edu    void nextnlu() { if (++nlu >= size) nlu = 0; }
973576Sgblack@eecs.umich.edu    MipsISA::PTE *lookup(Addr vpn, uint8_t asn) const;
983576Sgblack@eecs.umich.edu
993576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> read_hits;
1003576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> read_misses;
1013576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> read_acv;
1023576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> read_accesses;
1033576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> write_hits;
1043576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> write_misses;
1053576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> write_acv;
1063576Sgblack@eecs.umich.edu    mutable Stats::Scalar<> write_accesses;
1072221SN/A    Stats::Formula hits;
1083573Sgblack@eecs.umich.edu    Stats::Formula misses;
1093576Sgblack@eecs.umich.edu    Stats::Formula invalids;
1103576Sgblack@eecs.umich.edu    Stats::Formula accesses;
1112221SN/A
1123573Sgblack@eecs.umich.edu  public:
1133576Sgblack@eecs.umich.edu    typedef MipsTLBParams Params;
1143576Sgblack@eecs.umich.edu    TLB(const Params *p);
1152221SN/A
1163573Sgblack@eecs.umich.edu    int probeEntry(Addr vpn,uint8_t) const;
1173576Sgblack@eecs.umich.edu    MipsISA::PTE *getEntry(unsigned) const;
1183576Sgblack@eecs.umich.edu    virtual ~TLB();
1192221SN/A    int smallPages;
1203573Sgblack@eecs.umich.edu    int getsize() const { return size; }
1213576Sgblack@eecs.umich.edu
1223576Sgblack@eecs.umich.edu    MipsISA::PTE &index(bool advance = true);
1232221SN/A    void insert(Addr vaddr, MipsISA::PTE &pte);
1243573Sgblack@eecs.umich.edu    void insertAt(MipsISA::PTE &pte, unsigned Index, int _smallPages);
1253576Sgblack@eecs.umich.edu    void flushAll();
1263576Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
1272221SN/A    {
1283573Sgblack@eecs.umich.edu        panic("demapPage unimplemented.\n");
1293576Sgblack@eecs.umich.edu    }
1303576Sgblack@eecs.umich.edu
1312223SN/A    // static helper functions... really
1323573Sgblack@eecs.umich.edu    static bool validVirtualAddress(Addr vaddr);
1333576Sgblack@eecs.umich.edu
1343576Sgblack@eecs.umich.edu    static Fault checkCacheability(RequestPtr &req);
1352223SN/A
1363573Sgblack@eecs.umich.edu    // Checkpointing
1373576Sgblack@eecs.umich.edu    void serialize(std::ostream &os);
1383576Sgblack@eecs.umich.edu    void unserialize(Checkpoint *cp, const std::string &section);
1392223SN/A
1403573Sgblack@eecs.umich.edu    void regStats();
1413576Sgblack@eecs.umich.edu};
1423576Sgblack@eecs.umich.edu
1432223SN/Aclass ITB : public TLB {
1443573Sgblack@eecs.umich.edu  public:
1453576Sgblack@eecs.umich.edu    typedef MipsTLBParams Params;
1463576Sgblack@eecs.umich.edu    ITB(const Params *p);
1473576Sgblack@eecs.umich.edu
1483576Sgblack@eecs.umich.edu    Fault translateAtomic(RequestPtr &req, ThreadContext *tc);
1493576Sgblack@eecs.umich.edu};
1503576Sgblack@eecs.umich.edu
1513576Sgblack@eecs.umich.educlass DTB : public TLB {
1522223SN/A  public:
1533573Sgblack@eecs.umich.edu    typedef MipsTLBParams Params;
1543576Sgblack@eecs.umich.edu    DTB(const Params *p);
1553576Sgblack@eecs.umich.edu
1562223SN/A    Fault translateAtomic(RequestPtr &req, ThreadContext *tc,
1573573Sgblack@eecs.umich.edu            bool write = false);
1583576Sgblack@eecs.umich.edu};
1593576Sgblack@eecs.umich.edu
1602223SN/Aclass UTB : public ITB, public DTB {
1613573Sgblack@eecs.umich.edu  public:
1623576Sgblack@eecs.umich.edu    typedef MipsTLBParams Params;
1633576Sgblack@eecs.umich.edu    UTB(const Params *p);
1642223SN/A
1653573Sgblack@eecs.umich.edu};
1663576Sgblack@eecs.umich.edu
1673576Sgblack@eecs.umich.edu}
1682223SN/A
1693573Sgblack@eecs.umich.edu
1703576Sgblack@eecs.umich.edu
1713576Sgblack@eecs.umich.edu#endif // __MIPS_MEMORY_HH__
1722223SN/A