gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pagetable.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2012-2013 ARM Limited
3  * All rights reserved
4  *
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.
13  *
14  * Copyright (c) 2002-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __ARCH_ARM_PAGETABLE_H__
42 #define __ARCH_ARM_PAGETABLE_H__
43 
44 #include <cstdint>
45 
46 #include "arch/arm/isa_traits.hh"
47 #include "arch/arm/utility.hh"
48 #include "sim/serialize.hh"
49 
50 namespace ArmISA {
51 
52 struct VAddr
53 {
54  VAddr(Addr a) { panic("not implemented yet."); }
55 };
56 
57 
58 // ITB/DTB page table entry
59 struct PTE
60 {
61  void serialize(CheckpointOut &cp) const
62  {
63  panic("Need to implement PTE serialization\n");
64  }
65 
67  {
68  panic("Need to implement PTE serialization\n");
69  }
70 
71 };
72 
73 // Lookup level
75  L0 = 0, // AArch64 only
76  L1,
77  L2,
78  L3,
80 };
81 
82 // ITB/DTB table entry
83 struct TlbEntry : public Serializable
84 {
85  public:
86  enum class MemoryType : std::uint8_t {
87  StronglyOrdered,
88  Device,
89  Normal
90  };
91 
92  enum class DomainType : std::uint8_t {
93  NoAccess = 0,
94  Client,
95  Reserved,
96  Manager
97  };
98 
99  // Matching variables
101  Addr size; // Size of this entry, == Type of TLB Rec
102  Addr vpn; // Virtual Page Number
103  uint64_t attributes; // Memory attributes formatted for PAR
104 
105  LookupLevel lookupLevel; // Lookup level where the descriptor was fetched
106  // from. Used to set the FSR for faults
107  // occurring while the long desc. format is in
108  // use (AArch32 w/ LPAE and AArch64)
109 
110  uint16_t asid; // Address Space Identifier
111  uint8_t vmid; // Virtual machine Identifier
112  uint8_t N; // Number of bits in pagesize
113  uint8_t innerAttrs;
114  uint8_t outerAttrs;
115  uint8_t ap; // Access permissions bits
116  uint8_t hap; // Hyp access permissions bits
117  DomainType domain; // Access Domain
118 
120 
121  // True if the long descriptor format is used for this entry (LPAE only)
122  bool longDescFormat; // @todo use this in the update attribute bethod
123 
124  bool isHyp;
125  bool global;
126  bool valid;
127 
128  // True if the entry targets the non-secure physical address space
129  bool ns;
130  // True if the entry was brought in from a non-secure page table
131  bool nstid;
132  // Exception level on insert, AARCH64 EL0&1, AARCH32 -> el=1
134 
135  // Type of memory
136  bool nonCacheable; // Can we wrap this in mtype?
137 
138  // Memory Attributes
139  bool shareable;
141 
142  // Access permissions
143  bool xn; // Execute Never
144  bool pxn; // Privileged Execute Never (LPAE only)
145 
146  //Construct an entry that maps to physical address addr for SE mode
147  TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr,
148  bool uncacheable, bool read_only) :
149  pfn(_paddr >> PageShift), size(PageBytes - 1), vpn(_vaddr >> PageShift),
150  attributes(0), lookupLevel(L1), asid(_asn), vmid(0), N(0),
151  innerAttrs(0), outerAttrs(0), ap(read_only ? 0x3 : 0), hap(0x3),
152  domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
153  longDescFormat(false), isHyp(false), global(false), valid(true),
154  ns(true), nstid(true), el(EL0), nonCacheable(uncacheable),
155  shareable(false), outerShareable(false), xn(0), pxn(0)
156  {
157  // no restrictions by default, hap = 0x3
158 
159  // @todo Check the memory type
160  if (read_only)
161  warn("ARM TlbEntry does not support read-only mappings\n");
162  }
163 
165  pfn(0), size(0), vpn(0), attributes(0), lookupLevel(L1), asid(0),
166  vmid(0), N(0), innerAttrs(0), outerAttrs(0), ap(0), hap(0x3),
167  domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
168  longDescFormat(false), isHyp(false), global(false), valid(false),
169  ns(true), nstid(true), el(EL0), nonCacheable(false),
170  shareable(false), outerShareable(false), xn(0), pxn(0)
171  {
172  // no restrictions by default, hap = 0x3
173 
174  // @todo Check the memory type
175  }
176 
177  void
178  updateVaddr(Addr new_vaddr)
179  {
180  vpn = new_vaddr >> PageShift;
181  }
182 
183  Addr
184  pageStart() const
185  {
186  return pfn << PageShift;
187  }
188 
189  bool
190  match(Addr va, uint8_t _vmid, bool hypLookUp, bool secure_lookup,
191  ExceptionLevel target_el) const
192  {
193  return match(va, 0, _vmid, hypLookUp, secure_lookup, true, target_el);
194  }
195 
196  bool
197  match(Addr va, uint16_t asn, uint8_t _vmid, bool hypLookUp,
198  bool secure_lookup, bool ignore_asn, ExceptionLevel target_el) const
199  {
200  bool match = false;
201  Addr v = vpn << N;
202 
203  if (valid && va >= v && va <= v + size && (secure_lookup == !nstid) &&
204  (hypLookUp == isHyp))
205  {
206  match = checkELMatch(target_el);
207 
208  if (match && !ignore_asn) {
209  match = global || (asn == asid);
210  }
211  if (match && nstid) {
212  match = isHyp || (_vmid == vmid);
213  }
214  }
215  return match;
216  }
217 
218  bool
219  checkELMatch(ExceptionLevel target_el) const
220  {
221  if (target_el == EL2 || target_el == EL3) {
222  return (el == target_el);
223  } else {
224  return (el == EL0) || (el == EL1);
225  }
226  }
227 
228  Addr
229  pAddr(Addr va) const
230  {
231  return (pfn << N) | (va & size);
232  }
233 
234  void
236  {
237  uint64_t mask;
238  uint64_t newBits;
239 
240  // chec bit 11 to determine if its currently LPAE or VMSA format.
241  if ( attributes & (1 << 11) ) {
242  newBits = ((outerShareable ? 0x2 :
243  shareable ? 0x3 : 0) << 7);
244  mask = 0x180;
245  } else {
261  newBits = ((outerShareable ? 0:1) << 10) |
262  ((shareable ? 1:0) << 7) |
263  (innerAttrs << 4) |
264  (outerAttrs << 2);
265  // TODO: Supersection bit
266  mask = 0x4FC;
267  }
268  // common bits
269  newBits |= ns << 9; // NS bit
270  mask |= 1 << 9;
271  // add in the new bits
272  attributes &= ~mask;
273  attributes |= newBits;
274  }
275 
276  void
278  {
279  attributes = lpae ? (1 << 11) : 0;
280  updateAttributes();
281  }
282 
283  std::string
284  print() const
285  {
286  return csprintf("%#x, asn %d vmn %d hyp %d ppn %#x size: %#x ap:%d "
287  "ns:%d nstid:%d g:%d el:%d", vpn << N, asid, vmid,
288  isHyp, pfn << N, size, ap, ns, nstid, global, el);
289  }
290 
291  void
292  serialize(CheckpointOut &cp) const override
293  {
294  SERIALIZE_SCALAR(longDescFormat);
295  SERIALIZE_SCALAR(pfn);
296  SERIALIZE_SCALAR(size);
297  SERIALIZE_SCALAR(vpn);
298  SERIALIZE_SCALAR(asid);
299  SERIALIZE_SCALAR(vmid);
300  SERIALIZE_SCALAR(isHyp);
301  SERIALIZE_SCALAR(N);
302  SERIALIZE_SCALAR(global);
303  SERIALIZE_SCALAR(valid);
304  SERIALIZE_SCALAR(ns);
305  SERIALIZE_SCALAR(nstid);
306  SERIALIZE_SCALAR(nonCacheable);
307  SERIALIZE_ENUM(lookupLevel);
308  SERIALIZE_ENUM(mtype);
309  SERIALIZE_SCALAR(innerAttrs);
310  SERIALIZE_SCALAR(outerAttrs);
311  SERIALIZE_SCALAR(shareable);
312  SERIALIZE_SCALAR(outerShareable);
313  SERIALIZE_SCALAR(attributes);
314  SERIALIZE_SCALAR(xn);
315  SERIALIZE_SCALAR(pxn);
316  SERIALIZE_SCALAR(ap);
317  SERIALIZE_SCALAR(hap);
318  uint8_t domain_ = static_cast<uint8_t>(domain);
319  paramOut(cp, "domain", domain_);
320  }
321  void
323  {
324  UNSERIALIZE_SCALAR(longDescFormat);
325  UNSERIALIZE_SCALAR(pfn);
326  UNSERIALIZE_SCALAR(size);
327  UNSERIALIZE_SCALAR(vpn);
328  UNSERIALIZE_SCALAR(asid);
329  UNSERIALIZE_SCALAR(vmid);
330  UNSERIALIZE_SCALAR(isHyp);
332  UNSERIALIZE_SCALAR(global);
333  UNSERIALIZE_SCALAR(valid);
334  UNSERIALIZE_SCALAR(ns);
335  UNSERIALIZE_SCALAR(nstid);
336  UNSERIALIZE_SCALAR(nonCacheable);
337  UNSERIALIZE_ENUM(lookupLevel);
338  UNSERIALIZE_ENUM(mtype);
339  UNSERIALIZE_SCALAR(innerAttrs);
340  UNSERIALIZE_SCALAR(outerAttrs);
341  UNSERIALIZE_SCALAR(shareable);
342  UNSERIALIZE_SCALAR(outerShareable);
343  UNSERIALIZE_SCALAR(attributes);
344  UNSERIALIZE_SCALAR(xn);
345  UNSERIALIZE_SCALAR(pxn);
346  UNSERIALIZE_SCALAR(ap);
347  UNSERIALIZE_SCALAR(hap);
348  uint8_t domain_;
349  paramIn(cp, "domain", domain_);
350  domain = static_cast<DomainType>(domain_);
351  }
352 
353 };
354 
355 
356 
357 }
358 #endif // __ARCH_ARM_PAGETABLE_H__
359 
uint8_t innerAttrs
Definition: pagetable.hh:113
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
Bitfield< 28 > v
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pagetable.hh:292
const Addr PageShift
Definition: isa_traits.hh:55
VAddr(Addr a)
Definition: pagetable.hh:54
void serialize(CheckpointOut &cp) const
Definition: pagetable.hh:61
Bitfield< 8 > a
Addr pageStart() const
Definition: pagetable.hh:184
Definition: ccregs.hh:41
std::string print() const
Definition: pagetable.hh:284
MemoryType mtype
Definition: pagetable.hh:119
Definition: cprintf.cc:40
Bitfield< 9 > lpae
ExceptionLevel
Definition: types.hh:583
TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr, bool uncacheable, bool read_only)
Definition: pagetable.hh:147
ExceptionLevel el
Definition: pagetable.hh:133
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:770
void unserialize(CheckpointIn &cp)
Definition: pagetable.hh:66
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
#define SERIALIZE_ENUM(scalar)
Definition: serialize.hh:786
void updateVaddr(Addr new_vaddr)
Definition: pagetable.hh:178
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition: types.cc:38
bool checkELMatch(ExceptionLevel target_el) const
Definition: pagetable.hh:219
uint64_t attributes
Definition: pagetable.hh:103
Addr pAddr(Addr va) const
Definition: pagetable.hh:229
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
uint8_t outerAttrs
Definition: pagetable.hh:114
bool match(Addr va, uint8_t _vmid, bool hypLookUp, bool secure_lookup, ExceptionLevel target_el) const
Definition: pagetable.hh:190
Bitfield< 8 > va
Basic support for object serialization.
Definition: serialize.hh:166
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:763
Bitfield< 7, 4 > domain
std::ostream CheckpointOut
Definition: serialize.hh:63
#define UNSERIALIZE_ENUM(scalar)
Definition: serialize.hh:793
DomainType domain
Definition: pagetable.hh:117
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition: types.cc:69
void updateAttributes()
Definition: pagetable.hh:235
const Addr PageBytes
Definition: isa_traits.hh:56
Bitfield< 3, 0 > mask
Definition: types.hh:62
#define warn(...)
Definition: logging.hh:208
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pagetable.hh:322
bool match(Addr va, uint16_t asn, uint8_t _vmid, bool hypLookUp, bool secure_lookup, bool ignore_asn, ExceptionLevel target_el) const
Definition: pagetable.hh:197
LookupLevel lookupLevel
Definition: pagetable.hh:105
LookupLevel
Definition: pagetable.hh:74
void setAttributes(bool lpae)
Definition: pagetable.hh:277

Generated on Thu May 28 2020 16:11:02 for gem5 by doxygen 1.8.13