tlb.hh revision 7399
19665Sandreas.hansson@arm.com/*
29665Sandreas.hansson@arm.com * Copyright (c) 2010 ARM Limited
39665Sandreas.hansson@arm.com * All rights reserved
49665Sandreas.hansson@arm.com *
59665Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
69665Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
79665Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
89665Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
99665Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
109665Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
119665Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
129665Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
135353Svilas.sridharan@gmail.com *
143395Shsul@eecs.umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
153395Shsul@eecs.umich.edu * All rights reserved.
163395Shsul@eecs.umich.edu *
173395Shsul@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
183395Shsul@eecs.umich.edu * modification, are permitted provided that the following conditions are
193395Shsul@eecs.umich.edu * met: redistributions of source code must retain the above copyright
203395Shsul@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
213395Shsul@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
223395Shsul@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
233395Shsul@eecs.umich.edu * documentation and/or other materials provided with the distribution;
243395Shsul@eecs.umich.edu * neither the name of the copyright holders nor the names of its
253395Shsul@eecs.umich.edu * contributors may be used to endorse or promote products derived from
263395Shsul@eecs.umich.edu * this software without specific prior written permission.
273395Shsul@eecs.umich.edu *
283395Shsul@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
293395Shsul@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
303395Shsul@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
313395Shsul@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
323395Shsul@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
333395Shsul@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
343395Shsul@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
353395Shsul@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
363395Shsul@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
373395Shsul@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
383395Shsul@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
393395Shsul@eecs.umich.edu *
403395Shsul@eecs.umich.edu * Authors: Ali Saidi
4113774Sandreas.sandberg@arm.com */
4213774Sandreas.sandberg@arm.com
4313774Sandreas.sandberg@arm.com#ifndef __ARCH_ARM_TLB_HH__
448920Snilay@cs.wisc.edu#define __ARCH_ARM_TLB_HH__
458920Snilay@cs.wisc.edu
468920Snilay@cs.wisc.edu#include <map>
477025SBrad.Beckmann@amd.com
4813774Sandreas.sandberg@arm.com#include "arch/arm/isa_traits.hh"
4913774Sandreas.sandberg@arm.com#include "arch/arm/utility.hh"
5013774Sandreas.sandberg@arm.com#include "arch/arm/vtophys.hh"
5113876Sjavier.bueno@metempsy.com#include "arch/arm/pagetable.hh"
5213774Sandreas.sandberg@arm.com#include "base/statistics.hh"
5313774Sandreas.sandberg@arm.com#include "mem/request.hh"
5410747SChris.Emmons@arm.com#include "params/ArmTLB.hh"
559520SAndreas.Sandberg@ARM.com#include "sim/faults.hh"
569520SAndreas.Sandberg@ARM.com#include "sim/tlb.hh"
579520SAndreas.Sandberg@ARM.com
589520SAndreas.Sandberg@ARM.comclass ThreadContext;
5913432Spau.cabre@metempsy.com
6013432Spau.cabre@metempsy.comnamespace ArmISA {
6113432Spau.cabre@metempsy.com
6213432Spau.cabre@metempsy.comclass TLB : public BaseTLB
6313876Sjavier.bueno@metempsy.com{
6413876Sjavier.bueno@metempsy.com  public:
6513876Sjavier.bueno@metempsy.com    enum ArmFlags {
6613876Sjavier.bueno@metempsy.com        AlignmentMask = 0x7,
679665Sandreas.hansson@arm.com
689665Sandreas.hansson@arm.com        AlignByte = 0x0,
699665Sandreas.hansson@arm.com        AlignHalfWord = 0x1,
709665Sandreas.hansson@arm.com        AlignWord = 0x3,
7111238Sandreas.sandberg@arm.com        AlignDoubleWord = 0x7,
7211238Sandreas.sandberg@arm.com
7311238Sandreas.sandberg@arm.com        AllowUnaligned = 0x8,
7411238Sandreas.sandberg@arm.com        // Because zero otherwise looks like a valid setting and may be used
7511688Sandreas.hansson@arm.com        // accidentally, this bit must be non-zero to show it was used on
7611688Sandreas.hansson@arm.com        // purpose.
7711688Sandreas.hansson@arm.com        MustBeOne = 0x10
7811688Sandreas.hansson@arm.com    };
798920Snilay@cs.wisc.edu  protected:
809827Sakash.bagdia@arm.com    typedef std::multimap<Addr, int> PageTable;
819827Sakash.bagdia@arm.com    PageTable lookupTable;	// Quick lookup into page table
829827Sakash.bagdia@arm.com
839827Sakash.bagdia@arm.com    ArmISA::PTE *table;	// the Page Table
849790Sakash.bagdia@arm.com    int size;			// TLB Size
859790Sakash.bagdia@arm.com    int nlu;			// not last used entry (for replacement)
869790Sakash.bagdia@arm.com
879790Sakash.bagdia@arm.com    void nextnlu() { if (++nlu >= size) nlu = 0; }
8811688Sandreas.hansson@arm.com    ArmISA::PTE *lookup(Addr vpn, uint8_t asn) const;
8911688Sandreas.hansson@arm.com
9011688Sandreas.hansson@arm.com    // Access Stats
9111688Sandreas.hansson@arm.com    mutable Stats::Scalar read_hits;
9211688Sandreas.hansson@arm.com    mutable Stats::Scalar read_misses;
9311837Swendy.elsasser@arm.com    mutable Stats::Scalar read_acv;
9411688Sandreas.hansson@arm.com    mutable Stats::Scalar read_accesses;
9511688Sandreas.hansson@arm.com    mutable Stats::Scalar write_hits;
9611688Sandreas.hansson@arm.com    mutable Stats::Scalar write_misses;
9711688Sandreas.hansson@arm.com    mutable Stats::Scalar write_acv;
9811688Sandreas.hansson@arm.com    mutable Stats::Scalar write_accesses;
9911688Sandreas.hansson@arm.com    Stats::Formula hits;
10011688Sandreas.hansson@arm.com    Stats::Formula misses;
10111688Sandreas.hansson@arm.com    Stats::Formula invalids;
10211688Sandreas.hansson@arm.com    Stats::Formula accesses;
10311688Sandreas.hansson@arm.com
10411688Sandreas.hansson@arm.com  public:
10511688Sandreas.hansson@arm.com    typedef ArmTLBParams Params;
10611688Sandreas.hansson@arm.com    TLB(const Params *p);
10711688Sandreas.hansson@arm.com
10811688Sandreas.hansson@arm.com    virtual ~TLB();
10911688Sandreas.hansson@arm.com    int getsize() const { return size; }
11011688Sandreas.hansson@arm.com
11111688Sandreas.hansson@arm.com    void insert(Addr vaddr, ArmISA::PTE &pte);
11211688Sandreas.hansson@arm.com    void flushAll();
11311688Sandreas.hansson@arm.com    void demapPage(Addr vaddr, uint64_t asn)
11411688Sandreas.hansson@arm.com    {
11511688Sandreas.hansson@arm.com        panic("demapPage unimplemented.\n");
11611688Sandreas.hansson@arm.com    }
11711688Sandreas.hansson@arm.com
11811688Sandreas.hansson@arm.com    static bool validVirtualAddress(Addr vaddr);
11911688Sandreas.hansson@arm.com
12011688Sandreas.hansson@arm.com    Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode);
12111688Sandreas.hansson@arm.com    void translateTiming(RequestPtr req, ThreadContext *tc,
12211688Sandreas.hansson@arm.com            Translation *translation, Mode mode);
12311688Sandreas.hansson@arm.com
12411688Sandreas.hansson@arm.com    // Checkpointing
12511688Sandreas.hansson@arm.com    void serialize(std::ostream &os);
12611688Sandreas.hansson@arm.com    void unserialize(Checkpoint *cp, const std::string &section);
12711688Sandreas.hansson@arm.com
12811688Sandreas.hansson@arm.com    void regStats();
12911688Sandreas.hansson@arm.com};
13011688Sandreas.hansson@arm.com
13111688Sandreas.hansson@arm.com/* namespace ArmISA */ }
13211688Sandreas.hansson@arm.com
13311688Sandreas.hansson@arm.com#endif // __ARCH_ARM_TLB_HH__
13411688Sandreas.hansson@arm.com