2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
3 * Copyright (c) 2007 The Hewlett-Packard Development Company
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are
17 * met: redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer;
19 * redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution;
22 * neither the name of the copyright holders nor the names of its
23 * contributors may be used to endorse or promote products derived from
24 * this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #ifndef __ARCH_X86_PAGETABLE_HH__
42 #define __ARCH_X86_PAGETABLE_HH__
48 #include "base/bitunion.hh"
49 #include "base/types.hh"
50 #include "base/trie.hh"
51 #include "arch/x86/system.hh"
52 #include "debug/MMU.hh"
62 typedef Trie<Addr, X86ISA::TlbEntry> TlbEntryTrie;
66 struct TlbEntry : public Serializable
68 // The base of the physical page.
71 // The beginning of the virtual page this entry maps.
73 // The size of the page this represents, in address bits.
76 // Read permission is always available, assuming it isn't blocked by
79 // Whether this page is accesible without being in supervisor mode.
81 // Whether to use write through or write back. M5 ignores this and
82 // lets the caches handle the writeback policy.
84 // Whether the page is cacheable or not.
86 // Whether or not to kick this page out on a write to CR3.
88 // A bit used to form an index into the PAT table.
90 // Whether or not memory on this page can be executed.
92 // A sequence number to keep track of LRU.
95 TlbEntryTrie::Handle trieHandle;
97 TlbEntry(Addr asn, Addr _vaddr, Addr _paddr,
98 bool uncacheable, bool read_only);
102 updateVaddr(Addr new_vaddr)
112 // Return the page size in bytes
115 return (1 << logBytes);
118 void serialize(CheckpointOut &cp) const override;
119 void unserialize(CheckpointIn &cp) override;
124 Bitfield<20, 12> longl1;
125 Bitfield<29, 21> longl2;
126 Bitfield<38, 30> longl3;
127 Bitfield<47, 39> longl4;
129 Bitfield<20, 12> pael1;
130 Bitfield<29, 21> pael2;
131 Bitfield<31, 30> pael3;
133 Bitfield<21, 12> norml1;
134 Bitfield<31, 22> norml2;
137 // Unfortunately, the placement of the base field in a page table entry is
138 // very erratic and would make a mess here. It might be moved here at some
139 // point in the future.
140 BitUnion64(PageTableEntry)
142 Bitfield<51, 12> base;
153 EndBitUnion(PageTableEntry)
155 template <int first, int last>
159 Addr paddr() { return pte.base << PageShift; }
160 void paddr(Addr addr) { pte.base = addr >> PageShift; }
162 bool present() { return pte.p; }
163 void present(bool p) { pte.p = p ? 1 : 0; }
165 bool uncacheable() { return pte.pcd; }
166 void uncacheable(bool u) { pte.pcd = u ? 1 : 0; }
168 bool readonly() { return !pte.w; }
169 void readonly(bool r) { pte.w = r ? 0 : 1; }
172 read(PortProxy &p, Addr table, Addr vaddr)
175 entryAddr += bits(vaddr, first, last) * sizeof(PageTableEntry);
176 pte = p.read<PageTableEntry>(entryAddr);
180 reset(Addr _paddr, bool _present=true,
181 bool _uncacheable=false, bool _readonly=false)
187 uncacheable(_uncacheable);
191 void write(PortProxy &p) { p.write(entryAddr, pte); }
196 return 1 << ((first - last) + 4 - PageShift);