tlb.hh revision 5891:73084c6bb183
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 2007 The Hewlett-Packard Development Company
312855Sgabeblack@google.com * All rights reserved.
412855Sgabeblack@google.com *
512855Sgabeblack@google.com * Redistribution and use of this software in source and binary forms,
612855Sgabeblack@google.com * with or without modification, are permitted provided that the
712855Sgabeblack@google.com * following conditions are met:
812855Sgabeblack@google.com *
912855Sgabeblack@google.com * The software must be used only for Non-Commercial Use which means any
1012855Sgabeblack@google.com * use which is NOT directed to receiving any direct monetary
1112855Sgabeblack@google.com * compensation for, or commercial advantage from such use.  Illustrative
1212855Sgabeblack@google.com * examples of non-commercial use are academic research, personal study,
1312855Sgabeblack@google.com * teaching, education and corporate research & development.
1412855Sgabeblack@google.com * Illustrative examples of commercial use are distributing products for
1512855Sgabeblack@google.com * commercial advantage and providing services using the software for
1612855Sgabeblack@google.com * commercial advantage.
1712855Sgabeblack@google.com *
1812855Sgabeblack@google.com * If you wish to use this software or functionality therein that may be
1912855Sgabeblack@google.com * covered by patents for commercial use, please contact:
2012855Sgabeblack@google.com *     Director of Intellectual Property Licensing
2112855Sgabeblack@google.com *     Office of Strategy and Technology
2212855Sgabeblack@google.com *     Hewlett-Packard Company
2312855Sgabeblack@google.com *     1501 Page Mill Road
2412855Sgabeblack@google.com *     Palo Alto, California  94304
2512855Sgabeblack@google.com *
2612855Sgabeblack@google.com * Redistributions of source code must retain the above copyright notice,
2712855Sgabeblack@google.com * this list of conditions and the following disclaimer.  Redistributions
2812855Sgabeblack@google.com * in binary form must reproduce the above copyright notice, this list of
2912855Sgabeblack@google.com * conditions and the following disclaimer in the documentation and/or
3012855Sgabeblack@google.com * other materials provided with the distribution.  Neither the name of
3112855Sgabeblack@google.com * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
3212855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
3312855Sgabeblack@google.com * this software without specific prior written permission.  No right of
3412855Sgabeblack@google.com * sublicense is granted herewith.  Derivatives of the software and
3512855Sgabeblack@google.com * output created using the software may be prepared, but only for
3612855Sgabeblack@google.com * Non-Commercial Uses.  Derivatives of the software may be shared with
3712855Sgabeblack@google.com * others provided: (i) the others agree to abide by the list of
3812855Sgabeblack@google.com * conditions herein which includes the Non-Commercial Use restrictions;
3912855Sgabeblack@google.com * and (ii) such Derivatives of the software include the above copyright
4012855Sgabeblack@google.com * notice to acknowledge the contribution from this software where
4112855Sgabeblack@google.com * applicable, this list of conditions and the disclaimer below.
4212855Sgabeblack@google.com *
4312855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4412855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4512855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4612855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4712855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4812855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4912855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5012855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5112855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5212855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5312855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5412855Sgabeblack@google.com *
5512855Sgabeblack@google.com * Authors: Gabe Black
5612855Sgabeblack@google.com */
5712855Sgabeblack@google.com
5812855Sgabeblack@google.com#ifndef __ARCH_X86_TLB_HH__
5912855Sgabeblack@google.com#define __ARCH_X86_TLB_HH__
6012855Sgabeblack@google.com
6112855Sgabeblack@google.com#include <list>
6212855Sgabeblack@google.com#include <vector>
6312855Sgabeblack@google.com#include <string>
6412855Sgabeblack@google.com
6512855Sgabeblack@google.com#include "arch/x86/pagetable.hh"
6612855Sgabeblack@google.com#include "arch/x86/segmentregs.hh"
6712855Sgabeblack@google.com#include "config/full_system.hh"
6812855Sgabeblack@google.com#include "mem/mem_object.hh"
6912855Sgabeblack@google.com#include "mem/request.hh"
7012855Sgabeblack@google.com#include "params/X86DTB.hh"
7112855Sgabeblack@google.com#include "params/X86ITB.hh"
7212855Sgabeblack@google.com#include "sim/faults.hh"
7312855Sgabeblack@google.com#include "sim/tlb.hh"
7412855Sgabeblack@google.com#include "sim/sim_object.hh"
7512855Sgabeblack@google.com
7612855Sgabeblack@google.comclass ThreadContext;
7712855Sgabeblack@google.comclass Packet;
7812855Sgabeblack@google.com
7912855Sgabeblack@google.comnamespace X86ISA
8012855Sgabeblack@google.com{
8112855Sgabeblack@google.com    class Walker;
8212855Sgabeblack@google.com
8312855Sgabeblack@google.com    static const unsigned StoreCheck = 1 << NUM_SEGMENTREGS;
8412855Sgabeblack@google.com
8512855Sgabeblack@google.com    class TLB;
8612855Sgabeblack@google.com
8712855Sgabeblack@google.com    class TLB : public BaseTLB
8812855Sgabeblack@google.com    {
8912855Sgabeblack@google.com      protected:
9012855Sgabeblack@google.com        friend class FakeITLBFault;
9112855Sgabeblack@google.com        friend class FakeDTLBFault;
9212855Sgabeblack@google.com
9312855Sgabeblack@google.com        typedef std::list<TlbEntry *> EntryList;
9412855Sgabeblack@google.com
9512855Sgabeblack@google.com        bool _allowNX;
9612855Sgabeblack@google.com        uint32_t configAddress;
9712855Sgabeblack@google.com
9812855Sgabeblack@google.com      public:
9912855Sgabeblack@google.com        bool allowNX() const
10012855Sgabeblack@google.com        {
10112855Sgabeblack@google.com            return _allowNX;
10212855Sgabeblack@google.com        }
10312855Sgabeblack@google.com
10412855Sgabeblack@google.com        typedef X86TLBParams Params;
10512855Sgabeblack@google.com        TLB(const Params *p);
10612855Sgabeblack@google.com
10712855Sgabeblack@google.com        void dumpAll();
10812855Sgabeblack@google.com
10912855Sgabeblack@google.com        TlbEntry *lookup(Addr va, bool update_lru = true);
11012855Sgabeblack@google.com
11112855Sgabeblack@google.com        void setConfigAddress(uint32_t addr);
11212855Sgabeblack@google.com
11312855Sgabeblack@google.com      protected:
11412855Sgabeblack@google.com
11512855Sgabeblack@google.com        EntryList::iterator lookupIt(Addr va, bool update_lru = true);
11612855Sgabeblack@google.com
11712855Sgabeblack@google.com#if FULL_SYSTEM
11812855Sgabeblack@google.com      protected:
11912855Sgabeblack@google.com
12012855Sgabeblack@google.com        Walker * walker;
12112855Sgabeblack@google.com
12212855Sgabeblack@google.com        void walk(ThreadContext * _tc, Addr vaddr, bool write, bool execute);
12312855Sgabeblack@google.com#endif
12412855Sgabeblack@google.com
12512855Sgabeblack@google.com      public:
12612855Sgabeblack@google.com        void invalidateAll();
12712855Sgabeblack@google.com
12812855Sgabeblack@google.com        void invalidateNonGlobal();
12912855Sgabeblack@google.com
13012855Sgabeblack@google.com        void demapPage(Addr va, uint64_t asn);
13112855Sgabeblack@google.com
13212855Sgabeblack@google.com      protected:
13312855Sgabeblack@google.com        int size;
13412855Sgabeblack@google.com
13512855Sgabeblack@google.com        TlbEntry * tlb;
13612855Sgabeblack@google.com
13712855Sgabeblack@google.com        EntryList freeList;
13812855Sgabeblack@google.com        EntryList entryList;
13912855Sgabeblack@google.com
14012855Sgabeblack@google.com        template<class TlbFault>
14112855Sgabeblack@google.com        Fault translateAtomic(RequestPtr &req, ThreadContext *tc,
14212855Sgabeblack@google.com                bool write, bool execute);
143
144      public:
145
146        void insert(Addr vpn, TlbEntry &entry);
147
148        // Checkpointing
149        virtual void serialize(std::ostream &os);
150        virtual void unserialize(Checkpoint *cp, const std::string &section);
151    };
152
153    class ITB : public TLB
154    {
155      public:
156        typedef X86ITBParams Params;
157        ITB(const Params *p) : TLB(p)
158        {
159            _allowNX = false;
160        }
161
162        Fault translateAtomic(RequestPtr &req, ThreadContext *tc);
163
164        friend class DTB;
165    };
166
167    class DTB : public TLB
168    {
169      public:
170        typedef X86DTBParams Params;
171        DTB(const Params *p) : TLB(p)
172        {
173            _allowNX = true;
174        }
175        Fault translateAtomic(RequestPtr &req, ThreadContext *tc, bool write);
176#if FULL_SYSTEM
177        Tick doMmuRegRead(ThreadContext *tc, Packet *pkt);
178        Tick doMmuRegWrite(ThreadContext *tc, Packet *pkt);
179#endif
180
181        // Checkpointing
182        virtual void serialize(std::ostream &os);
183        virtual void unserialize(Checkpoint *cp, const std::string &section);
184    };
185}
186
187#endif // __ARCH_X86_TLB_HH__
188