tlb.hh revision 9738
19242SN/A/*
29242SN/A * Copyright (c) 2007 The Hewlett-Packard Development Company
39242SN/A * All rights reserved.
49242SN/A *
59242SN/A * The license below extends only to copyright in the software and shall
69242SN/A * not be construed as granting a license to any other intellectual
79242SN/A * property including but not limited to intellectual property relating
89242SN/A * to a hardware implementation of the functionality of the software
99242SN/A * licensed hereunder.  You may use the software subject to the license
109242SN/A * terms below provided that you ensure that this notice is replicated
119242SN/A * unmodified and in its entirety in all distributions of the software,
129242SN/A * modified or unmodified, in source code or in binary form.
139242SN/A *
149242SN/A * Redistribution and use in source and binary forms, with or without
159242SN/A * modification, are permitted provided that the following conditions are
169242SN/A * met: redistributions of source code must retain the above copyright
179242SN/A * notice, this list of conditions and the following disclaimer;
189242SN/A * redistributions in binary form must reproduce the above copyright
199242SN/A * notice, this list of conditions and the following disclaimer in the
209242SN/A * documentation and/or other materials provided with the distribution;
219242SN/A * neither the name of the copyright holders nor the names of its
229242SN/A * contributors may be used to endorse or promote products derived from
239242SN/A * this software without specific prior written permission.
249242SN/A *
259242SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
269242SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
279242SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
289242SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
299242SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
309242SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
319242SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
329242SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
339242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
349242SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
359242SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
369242SN/A *
379242SN/A * Authors: Gabe Black
3811458Sandreas.hansson@arm.com */
39
40#ifndef __ARCH_X86_TLB_HH__
41#define __ARCH_X86_TLB_HH__
42
43#include <list>
44#include <string>
45#include <vector>
46
47#include "arch/x86/regs/segment.hh"
48#include "arch/x86/pagetable.hh"
49#include "base/trie.hh"
50#include "mem/mem_object.hh"
51#include "mem/request.hh"
52#include "params/X86TLB.hh"
53#include "sim/fault_fwd.hh"
54#include "sim/sim_object.hh"
55#include "sim/tlb.hh"
56
57class ThreadContext;
58class Packet;
59
60namespace X86ISA
61{
62    class Walker;
63
64    class TLB : public BaseTLB
65    {
66      protected:
67        friend class Walker;
68
69        typedef std::list<TlbEntry *> EntryList;
70
71        uint32_t configAddress;
72
73      public:
74
75        typedef X86TLBParams Params;
76        TLB(const Params *p);
77
78        TlbEntry *lookup(Addr va, bool update_lru = true);
79
80        void setConfigAddress(uint32_t addr);
81
82      protected:
83
84        EntryList::iterator lookupIt(Addr va, bool update_lru = true);
85
86        Walker * walker;
87
88      public:
89        Walker *getWalker();
90
91        void flushAll();
92
93        void flushNonGlobal();
94
95        void demapPage(Addr va, uint64_t asn);
96
97      protected:
98        int size;
99
100        TlbEntry * tlb;
101
102        EntryList freeList;
103        EntryList entryList;
104
105        TlbEntryTrie trie;
106        uint64_t lruSeq;
107
108        Fault translateInt(RequestPtr req, ThreadContext *tc);
109
110        Fault translate(RequestPtr req, ThreadContext *tc,
111                Translation *translation, Mode mode,
112                bool &delayedResponse, bool timing);
113
114      public:
115
116        void evictLRU();
117
118        uint64_t
119        nextSeq()
120        {
121            return ++lruSeq;
122        }
123
124        Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode);
125        void translateTiming(RequestPtr req, ThreadContext *tc,
126                Translation *translation, Mode mode);
127        /** Stub function for compilation support of CheckerCPU. x86 ISA does
128         *  not support Checker model at the moment
129         */
130        Fault translateFunctional(RequestPtr req, ThreadContext *tc, Mode mode);
131
132        /**
133         * Do post-translation physical address finalization.
134         *
135         * Some addresses, for example requests going to the APIC,
136         * need post-translation updates. Such physical addresses are
137         * remapped into a "magic" part of the physical address space
138         * by this method.
139         *
140         * @param req Request to updated in-place.
141         * @param tc Thread context that created the request.
142         * @param mode Request type (read/write/execute).
143         * @return A fault on failure, NoFault otherwise.
144         */
145        Fault finalizePhysical(RequestPtr req, ThreadContext *tc,
146                               Mode mode) const;
147
148        TlbEntry * insert(Addr vpn, TlbEntry &entry);
149
150        // Checkpointing
151        virtual void serialize(std::ostream &os);
152        virtual void unserialize(Checkpoint *cp, const std::string &section);
153
154        /**
155         * Get the table walker master port. This is used for
156         * migrating port connections during a CPU takeOverFrom()
157         * call. For architectures that do not have a table walker,
158         * NULL is returned, hence the use of a pointer rather than a
159         * reference. For X86 this method will always return a valid
160         * port pointer.
161         *
162         * @return A pointer to the walker master port
163         */
164        virtual BaseMasterPort *getMasterPort();
165    };
166}
167
168#endif // __ARCH_X86_TLB_HH__
169