tlb.hh revision 7294
13520Sgblack@eecs.umich.edu/*
23520Sgblack@eecs.umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
33520Sgblack@eecs.umich.edu * Copyright (c) 2007 MIPS Technologies, Inc.
43520Sgblack@eecs.umich.edu * All rights reserved.
53520Sgblack@eecs.umich.edu *
63520Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
73520Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
83520Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
93520Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
103520Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
113520Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
123520Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
133520Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
143520Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
153520Sgblack@eecs.umich.edu * this software without specific prior written permission.
163520Sgblack@eecs.umich.edu *
173520Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
183520Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
193520Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
203520Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
213520Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
223520Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
233520Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243520Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
253520Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
263520Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
273520Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283520Sgblack@eecs.umich.edu *
293520Sgblack@eecs.umich.edu * Authors: Nathan Binkert
303520Sgblack@eecs.umich.edu *          Steve Reinhardt
313520Sgblack@eecs.umich.edu *          Jaidev Patwardhan
323520Sgblack@eecs.umich.edu *          Korey Sewell
333520Sgblack@eecs.umich.edu */
343520Sgblack@eecs.umich.edu
353520Sgblack@eecs.umich.edu#ifndef __ARCH_MIPS_TLB_HH__
363520Sgblack@eecs.umich.edu#define __ARCH_MIPS_TLB_HH__
374103Ssaidi@eecs.umich.edu
385647Sgblack@eecs.umich.edu#include <map>
393520Sgblack@eecs.umich.edu
408232Snate@binkert.org#include "arch/mips/isa_traits.hh"
418232Snate@binkert.org#include "arch/mips/utility.hh"
425647Sgblack@eecs.umich.edu#include "arch/mips/vtophys.hh"
435647Sgblack@eecs.umich.edu#include "arch/mips/pagetable.hh"
443520Sgblack@eecs.umich.edu#include "base/statistics.hh"
455565Snate@binkert.org#include "mem/request.hh"
465565Snate@binkert.org#include "params/MipsTLB.hh"
475647Sgblack@eecs.umich.edu#include "sim/faults.hh"
483520Sgblack@eecs.umich.edu#include "sim/tlb.hh"
495565Snate@binkert.org#include "sim/sim_object.hh"
505565Snate@binkert.org
515565Snate@binkert.orgclass ThreadContext;
525565Snate@binkert.org
535810Sgblack@eecs.umich.edu/* MIPS does not distinguish between a DTLB and an ITLB -> unified TLB
545565Snate@binkert.org   However, to maintain compatibility with other architectures, we'll
555565Snate@binkert.org   simply create an ITLB and DTLB that will point to the real TLB */
565565Snate@binkert.orgnamespace MipsISA {
575565Snate@binkert.org
585565Snate@binkert.org// WARN: This particular TLB entry is not necessarily conformed to MIPS ISA
595565Snate@binkert.orgstruct TlbEntry
605647Sgblack@eecs.umich.edu{
615647Sgblack@eecs.umich.edu    Addr _pageStart;
625647Sgblack@eecs.umich.edu    TlbEntry() {}
635647Sgblack@eecs.umich.edu    TlbEntry(Addr asn, Addr vaddr, Addr paddr) : _pageStart(paddr) {}
645647Sgblack@eecs.umich.edu
655647Sgblack@eecs.umich.edu    Addr pageStart()
665647Sgblack@eecs.umich.edu    {
675647Sgblack@eecs.umich.edu        return _pageStart;
685810Sgblack@eecs.umich.edu    }
693520Sgblack@eecs.umich.edu
705565Snate@binkert.org    void
715565Snate@binkert.org    updateVaddr(Addr new_vaddr) {}
725565Snate@binkert.org
735565Snate@binkert.org    void serialize(std::ostream &os)
743520Sgblack@eecs.umich.edu    {
755565Snate@binkert.org        SERIALIZE_SCALAR(_pageStart);
765810Sgblack@eecs.umich.edu    }
775810Sgblack@eecs.umich.edu
785810Sgblack@eecs.umich.edu    void unserialize(Checkpoint *cp, const std::string &section)
795810Sgblack@eecs.umich.edu    {
805810Sgblack@eecs.umich.edu        UNSERIALIZE_SCALAR(_pageStart);
815810Sgblack@eecs.umich.edu    }
825565Snate@binkert.org
835565Snate@binkert.org};
845565Snate@binkert.org
853520Sgblack@eecs.umich.educlass TLB : public BaseTLB
865565Snate@binkert.org{
875565Snate@binkert.org  protected:
883520Sgblack@eecs.umich.edu    typedef std::multimap<Addr, int> PageTable;
895565Snate@binkert.org    PageTable lookupTable;      // Quick lookup into page table
905565Snate@binkert.org
913520Sgblack@eecs.umich.edu    MipsISA::PTE *table;        // the Page Table
925565Snate@binkert.org    int size;                   // TLB Size
935565Snate@binkert.org    int nlu;                    // not last used entry (for replacement)
945565Snate@binkert.org
953520Sgblack@eecs.umich.edu    void nextnlu() { if (++nlu >= size) nlu = 0; }
965565Snate@binkert.org    MipsISA::PTE *lookup(Addr vpn, uint8_t asn) const;
975565Snate@binkert.org
985565Snate@binkert.org    mutable Stats::Scalar read_hits;
995565Snate@binkert.org    mutable Stats::Scalar read_misses;
1003520Sgblack@eecs.umich.edu    mutable Stats::Scalar read_acv;
1015568Snate@binkert.org    mutable Stats::Scalar read_accesses;
1025565Snate@binkert.org    mutable Stats::Scalar write_hits;
1033520Sgblack@eecs.umich.edu    mutable Stats::Scalar write_misses;
1045565Snate@binkert.org    mutable Stats::Scalar write_acv;
1055565Snate@binkert.org    mutable Stats::Scalar write_accesses;
1063520Sgblack@eecs.umich.edu    Stats::Formula hits;
1075565Snate@binkert.org    Stats::Formula misses;
1085565Snate@binkert.org    Stats::Formula invalids;
1095565Snate@binkert.org    Stats::Formula accesses;
1105565Snate@binkert.org
1113520Sgblack@eecs.umich.edu  public:
1125565Snate@binkert.org    typedef MipsTLBParams Params;
1135704Snate@binkert.org    TLB(const Params *p);
1145565Snate@binkert.org
1155565Snate@binkert.org    int probeEntry(Addr vpn,uint8_t) const;
1163520Sgblack@eecs.umich.edu    MipsISA::PTE *getEntry(unsigned) const;
1175565Snate@binkert.org    virtual ~TLB();
1185565Snate@binkert.org    int smallPages;
1195565Snate@binkert.org    int getsize() const { return size; }
1203520Sgblack@eecs.umich.edu
1215565Snate@binkert.org    MipsISA::PTE &index(bool advance = true);
1225565Snate@binkert.org    void insert(Addr vaddr, MipsISA::PTE &pte);
1235565Snate@binkert.org    void insertAt(MipsISA::PTE &pte, unsigned Index, int _smallPages);
1245565Snate@binkert.org    void flushAll();
1255565Snate@binkert.org    void demapPage(Addr vaddr, uint64_t asn)
1265565Snate@binkert.org    {
1273520Sgblack@eecs.umich.edu        panic("demapPage unimplemented.\n");
1285565Snate@binkert.org    }
1295565Snate@binkert.org
1305565Snate@binkert.org    // static helper functions... really
1315565Snate@binkert.org    static bool validVirtualAddress(Addr vaddr);
1325565Snate@binkert.org
1335565Snate@binkert.org    static Fault checkCacheability(RequestPtr &req);
1343520Sgblack@eecs.umich.edu
1355565Snate@binkert.org    // Checkpointing
1365704Snate@binkert.org    void serialize(std::ostream &os);
1375565Snate@binkert.org    void unserialize(Checkpoint *cp, const std::string &section);
1387720Sgblack@eecs.umich.edu
1395565Snate@binkert.org    void regStats();
1403520Sgblack@eecs.umich.edu
1415565Snate@binkert.org    Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode);
1425565Snate@binkert.org    void translateTiming(RequestPtr req, ThreadContext *tc,
1435565Snate@binkert.org            Translation *translation, Mode mode);
1446227Snate@binkert.org
1456227Snate@binkert.org  private:
1463521Sgblack@eecs.umich.edu    Fault translateInst(RequestPtr req, ThreadContext *tc);
1475565Snate@binkert.org    Fault translateData(RequestPtr req, ThreadContext *tc, bool write);
1485565Snate@binkert.org};
1493520Sgblack@eecs.umich.edu
1505565Snate@binkert.org}
1516227Snate@binkert.org
1525565Snate@binkert.org
1535565Snate@binkert.org
1545565Snate@binkert.org#endif // __MIPS_MEMORY_HH__
1555565Snate@binkert.org