2 * Copyright (c) 2010 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #ifndef __ARCH_ARM_TABLE_WALKER_HH__
41 #define __ARCH_ARM_TABLE_WALKER_HH__
43 #include "arch/arm/miscregs.hh"
44 #include "arch/arm/tlb.hh"
45 #include "mem/mem_object.hh"
46 #include "mem/request.hh"
47 #include "mem/request.hh"
48 #include "params/ArmTableWalker.hh"
49 #include "sim/faults.hh"
50 #include "sim/eventq.hh"
51 #include "base/fifo_buffer.hh"
60 class TableWalker : public MemObject
64 /** Type of page table entry ARM DDI 0406B: B3-8*/
72 /** The raw bits of the entry */
75 /** This entry has been modified (access flag set) and needs to be
76 * written back to memory */
79 EntryType type() const
81 return (EntryType)(data & 0x3);
84 /** Is the page a Supersection (16MB)?*/
85 bool supersection() const
87 return bits(data, 18);
90 /** Return the physcal address of the entry, bits in position*/
94 panic("Super sections not implemented\n");
95 return mbits(data, 31,20);
98 /** Return the physical frame, bits shifted right */
102 panic("Super sections not implemented\n");
103 return bits(data, 31,20);
106 /** Is the translation global (no asid used)? */
109 return bits(data, 4);
112 /** Is the translation not allow execution? */
115 return bits(data, 17);
118 /** Three bit access protection flags */
121 return (bits(data, 15) << 2) | bits(data,11,10);
124 /** Domain Client/Manager: ARM DDI 0406B: B3-31 */
125 uint8_t domain() const
127 return bits(data,8,5);
130 /** Address of L2 descriptor if it exists */
133 return mbits(data, 31,10);
136 /** Memory region attributes: ARM DDI 0406B: B3-32.
137 * These bits are largly ignored by M5 and only used to
138 * provide the illusion that the memory system cares about
139 * anything but cachable vs. uncachable.
141 uint8_t texcb() const
143 return bits(data, 2) | bits(data,3) << 1 | bits(data, 14, 12) << 2;
146 /** If the section is shareable. See texcb() comment. */
147 bool shareable() const
149 return bits(data, 16);
152 /** Set access flag that this entry has been touched. Mark
153 * the entry as requiring a writeback, in the future.
161 /** This entry needs to be written back to memory */
168 /** Level 2 page table descriptor */
169 struct L2Descriptor {
171 /** The raw bits of the entry. */
174 /** This entry has been modified (access flag set) and needs to be
175 * written back to memory */
178 /** Is the entry invalid */
181 return bits(data, 1,0) == 0;;
184 /** What is the size of the mapping? */
187 return bits(data, 1) == 0;
190 /** Is execution allowed on this mapping? */
193 return large() ? bits(data, 15) : bits(data, 0);
196 /** Is the translation global (no asid used)? */
199 return !bits(data, 11);
202 /** Three bit access protection flags */
205 return bits(data, 5, 4) | (bits(data, 9) << 2);
208 /** Memory region attributes: ARM DDI 0406B: B3-32 */
209 uint8_t texcb() const
212 (bits(data, 2) | (bits(data,3) << 1) | (bits(data, 14, 12) << 2)) :
213 (bits(data, 2) | (bits(data,3) << 1) | (bits(data, 8, 6) << 2));
216 /** Return the physical frame, bits shifted right */
219 return large() ? bits(data, 31, 16) : bits(data, 31, 12);
222 /** If the section is shareable. See texcb() comment. */
223 bool shareable() const
225 return bits(data, 10);
228 /** Set access flag that this entry has been touched. Mark
229 * the entry as requiring a writeback, in the future.
237 /** This entry needs to be written back to memory */
245 struct WalkerState //: public SimObject
247 /** Thread context that we're doing the walk for */
250 /** Request that is currently being serviced */
253 /** Context ID that we're servicing the request under */
256 /** Translation state for delayed requests */
257 TLB::Translation *transState;
259 /** The fault that we are going to return */
262 /** The virtual address that is being translated */
265 /** Cached copy of the sctlr as it existed when translation began */
268 /** Cached copy of the cpsr as it existed when the translation began */
271 /** Width of the base address held in TTRB0 */
274 /** If the access is a write */
277 /** If the access is not from user mode */
280 /** If the access is a fetch (for execution, and no-exec) must be checked?*/
283 /** If the mode is timing or atomic */
286 /** Save mode for use in delayed response */
292 /** Whether L1/L2 descriptor response is delayed in timing mode */
295 TableWalker *tableWalker;
297 void doL1Descriptor();
298 void doL2Descriptor();
300 std::string name() const {return tableWalker->name();}
304 FifoBuffer<WalkerState> stateQueue;
306 /** Port to issue translation requests from */
309 /** TLB that is initiating these table walks */
312 /** Cached copy of the sctlr as it existed when translation began */
315 WalkerState *currState;
318 typedef ArmTableWalkerParams Params;
319 TableWalker(const Params *p);
320 virtual ~TableWalker();
325 return dynamic_cast<const Params *>(_params);
328 virtual unsigned int drain(Event *de) { panic("write me\n"); }
329 virtual Port *getPort(const std::string &if_name, int idx = -1);
331 Fault walk(RequestPtr req, ThreadContext *tc, uint8_t cid, TLB::Mode mode,
332 TLB::Translation *_trans, bool timing);
334 void setTlb(TLB *_tlb) { tlb = _tlb; }
335 void memAttrs(ThreadContext *tc, TlbEntry &te, SCTLR sctlr,
336 uint8_t texcb, bool s);
340 void doL1Descriptor();
341 void doL1DescriptorWrapper();
342 EventWrapper<TableWalker, &TableWalker::doL1DescriptorWrapper> doL1DescEvent;
344 void doL2Descriptor();
345 void doL2DescriptorWrapper();
346 EventWrapper<TableWalker, &TableWalker::doL2DescriptorWrapper> doL2DescEvent;
352 } // namespace ArmISA
354 #endif //__ARCH_ARM_TABLE_WALKER_HH__