tlb.hh revision 6116:a5a97b04d796
112853Sgabeblack@google.com/*
212853Sgabeblack@google.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
312853Sgabeblack@google.com * Copyright (c) 2007 MIPS Technologies, Inc.
412853Sgabeblack@google.com * Copyright (c) 2007-2008 The Florida State University
512853Sgabeblack@google.com * All rights reserved.
612853Sgabeblack@google.com *
712853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
812853Sgabeblack@google.com * modification, are permitted provided that the following conditions are
912853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
1012853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1112853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1212853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1312853Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1412853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1512853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1612853Sgabeblack@google.com * this software without specific prior written permission.
1712853Sgabeblack@google.com *
1812853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1912853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2012853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2112853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2212853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2312853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2412853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2512853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2612853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2712853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2812853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2912853Sgabeblack@google.com *
3012853Sgabeblack@google.com * Authors: Nathan Binkert
3112853Sgabeblack@google.com *          Steve Reinhardt
3212853Sgabeblack@google.com *          Stephen Hines
3312853Sgabeblack@google.com */
3412853Sgabeblack@google.com
3512853Sgabeblack@google.com#ifndef __ARCH_ARM_TLB_HH__
3612853Sgabeblack@google.com#define __ARCH_ARM_TLB_HH__
3712853Sgabeblack@google.com
3812853Sgabeblack@google.com#include <map>
3912853Sgabeblack@google.com
4012853Sgabeblack@google.com#include "arch/arm/isa_traits.hh"
4112853Sgabeblack@google.com#include "arch/arm/utility.hh"
4212853Sgabeblack@google.com#include "arch/arm/vtophys.hh"
4312853Sgabeblack@google.com#include "arch/arm/pagetable.hh"
4412853Sgabeblack@google.com#include "base/statistics.hh"
4512853Sgabeblack@google.com#include "mem/request.hh"
4612853Sgabeblack@google.com#include "params/ArmTLB.hh"
4712853Sgabeblack@google.com#include "sim/faults.hh"
4812853Sgabeblack@google.com#include "sim/tlb.hh"
4912853Sgabeblack@google.com
5012853Sgabeblack@google.comclass ThreadContext;
5112853Sgabeblack@google.com
5212853Sgabeblack@google.com/* ARM does not distinguish between a DTLB and an ITLB -> unified TLB
5312853Sgabeblack@google.com   However, to maintain compatibility with other architectures, we'll
5412853Sgabeblack@google.com   simply create an ITLB and DTLB that will point to the real TLB */
5512853Sgabeblack@google.comnamespace ArmISA {
5612853Sgabeblack@google.com
5712853Sgabeblack@google.com// WARN: This particular TLB entry is not necessarily conformed to ARM ISA
5812853Sgabeblack@google.comstruct TlbEntry
5912853Sgabeblack@google.com{
6012853Sgabeblack@google.com    Addr _pageStart;
6112853Sgabeblack@google.com    TlbEntry() {}
6212853Sgabeblack@google.com    TlbEntry(Addr asn, Addr vaddr, Addr paddr) : _pageStart(paddr) {}
6312853Sgabeblack@google.com
6412853Sgabeblack@google.com    void
6512853Sgabeblack@google.com    updateVaddr(Addr new_vaddr)
6612853Sgabeblack@google.com    {
6712853Sgabeblack@google.com        panic("unimplemented");
6812853Sgabeblack@google.com    }
6912853Sgabeblack@google.com
7012853Sgabeblack@google.com    Addr pageStart()
7112853Sgabeblack@google.com    {
7212853Sgabeblack@google.com        return _pageStart;
7312853Sgabeblack@google.com    }
7412853Sgabeblack@google.com
7512853Sgabeblack@google.com    void serialize(std::ostream &os)
7612853Sgabeblack@google.com    {
7712853Sgabeblack@google.com        SERIALIZE_SCALAR(_pageStart);
7812853Sgabeblack@google.com    }
7912853Sgabeblack@google.com
8012853Sgabeblack@google.com    void unserialize(Checkpoint *cp, const std::string &section)
8112853Sgabeblack@google.com    {
8212853Sgabeblack@google.com        UNSERIALIZE_SCALAR(_pageStart);
8312853Sgabeblack@google.com    }
8412853Sgabeblack@google.com
8512853Sgabeblack@google.com};
8612853Sgabeblack@google.com
8712853Sgabeblack@google.comclass TLB : public BaseTLB
8812853Sgabeblack@google.com{
8912853Sgabeblack@google.com  protected:
9012853Sgabeblack@google.com    typedef std::multimap<Addr, int> PageTable;
9112853Sgabeblack@google.com    PageTable lookupTable;	// Quick lookup into page table
9212853Sgabeblack@google.com
9312853Sgabeblack@google.com    ArmISA::PTE *table;	// the Page Table
9412853Sgabeblack@google.com    int size;			// TLB Size
9512853Sgabeblack@google.com    int nlu;			// not last used entry (for replacement)
9612853Sgabeblack@google.com
9712853Sgabeblack@google.com    void nextnlu() { if (++nlu >= size) nlu = 0; }
9812853Sgabeblack@google.com    ArmISA::PTE *lookup(Addr vpn, uint8_t asn) const;
9912853Sgabeblack@google.com
10012853Sgabeblack@google.com    mutable Stats::Scalar read_hits;
10112853Sgabeblack@google.com    mutable Stats::Scalar read_misses;
10212853Sgabeblack@google.com    mutable Stats::Scalar read_acv;
10312853Sgabeblack@google.com    mutable Stats::Scalar read_accesses;
10412853Sgabeblack@google.com    mutable Stats::Scalar write_hits;
10512853Sgabeblack@google.com    mutable Stats::Scalar write_misses;
10612853Sgabeblack@google.com    mutable Stats::Scalar write_acv;
10712853Sgabeblack@google.com    mutable Stats::Scalar write_accesses;
10812853Sgabeblack@google.com    Stats::Formula hits;
10912853Sgabeblack@google.com    Stats::Formula misses;
11012853Sgabeblack@google.com    Stats::Formula invalids;
11112853Sgabeblack@google.com    Stats::Formula accesses;
11212853Sgabeblack@google.com
11312853Sgabeblack@google.com  public:
11412853Sgabeblack@google.com    typedef ArmTLBParams Params;
11512853Sgabeblack@google.com    TLB(const Params *p);
11612853Sgabeblack@google.com
11712853Sgabeblack@google.com    int probeEntry(Addr vpn,uint8_t) const;
11812853Sgabeblack@google.com    ArmISA::PTE *getEntry(unsigned) const;
11912853Sgabeblack@google.com    virtual ~TLB();
12012853Sgabeblack@google.com    int smallPages;
12112853Sgabeblack@google.com    int getsize() const { return size; }
12212853Sgabeblack@google.com
12312853Sgabeblack@google.com    ArmISA::PTE &index(bool advance = true);
12412853Sgabeblack@google.com    void insert(Addr vaddr, ArmISA::PTE &pte);
12512853Sgabeblack@google.com    void insertAt(ArmISA::PTE &pte, unsigned Index, int _smallPages);
12612853Sgabeblack@google.com    void flushAll();
12712853Sgabeblack@google.com    void demapPage(Addr vaddr, uint64_t asn)
12812853Sgabeblack@google.com    {
12912853Sgabeblack@google.com        panic("demapPage unimplemented.\n");
13012853Sgabeblack@google.com    }
13112853Sgabeblack@google.com
13212853Sgabeblack@google.com    // static helper functions... really
13312853Sgabeblack@google.com    static bool validVirtualAddress(Addr vaddr);
13412853Sgabeblack@google.com
13512853Sgabeblack@google.com    static Fault checkCacheability(RequestPtr &req);
13612853Sgabeblack@google.com
13712853Sgabeblack@google.com    Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode);
13812853Sgabeblack@google.com    void translateTiming(RequestPtr req, ThreadContext *tc,
13912853Sgabeblack@google.com            Translation *translation, Mode mode);
14012853Sgabeblack@google.com
14112853Sgabeblack@google.com    // Checkpointing
14212853Sgabeblack@google.com    void serialize(std::ostream &os);
14312853Sgabeblack@google.com    void unserialize(Checkpoint *cp, const std::string &section);
14412853Sgabeblack@google.com
14512853Sgabeblack@google.com    void regStats();
14612853Sgabeblack@google.com};
14712853Sgabeblack@google.com
14812853Sgabeblack@google.com/* namespace ArmISA */ }
14912853Sgabeblack@google.com
15012853Sgabeblack@google.com#endif // __ARCH_ARM_TLB_HH__
15112853Sgabeblack@google.com