gem5  v20.1.0.0
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 
53 // Max. physical address range in bits supported by the architecture
54 const unsigned MaxPhysAddrRange = 48;
55 
56 // ITB/DTB page table entry
57 struct PTE
58 {
59  void serialize(CheckpointOut &cp) const
60  {
61  panic("Need to implement PTE serialization\n");
62  }
63 
65  {
66  panic("Need to implement PTE serialization\n");
67  }
68 
69 };
70 
71 // Lookup level
73  L0 = 0, // AArch64 only
74  L1,
75  L2,
76  L3,
78 };
79 
80 // ITB/DTB table entry
81 struct TlbEntry : public Serializable
82 {
83  public:
84  enum class MemoryType : std::uint8_t {
86  Device,
87  Normal
88  };
89 
90  enum class DomainType : std::uint8_t {
91  NoAccess = 0,
92  Client,
93  Reserved,
94  Manager
95  };
96 
97  // Matching variables
99  Addr size; // Size of this entry, == Type of TLB Rec
100  Addr vpn; // Virtual Page Number
101  uint64_t attributes; // Memory attributes formatted for PAR
102 
103  LookupLevel lookupLevel; // Lookup level where the descriptor was fetched
104  // from. Used to set the FSR for faults
105  // occurring while the long desc. format is in
106  // use (AArch32 w/ LPAE and AArch64)
107 
108  uint16_t asid; // Address Space Identifier
109  uint8_t vmid; // Virtual machine Identifier
110  uint8_t N; // Number of bits in pagesize
111  uint8_t innerAttrs;
112  uint8_t outerAttrs;
113  uint8_t ap; // Access permissions bits
114  uint8_t hap; // Hyp access permissions bits
115  DomainType domain; // Access Domain
116 
118 
119  // True if the long descriptor format is used for this entry (LPAE only)
120  bool longDescFormat; // @todo use this in the update attribute bethod
121 
122  bool isHyp;
123  bool global;
124  bool valid;
125 
126  // True if the entry targets the non-secure physical address space
127  bool ns;
128  // True if the entry was brought in from a non-secure page table
129  bool nstid;
130  // Exception level on insert, AARCH64 EL0&1, AARCH32 -> el=1
132 
133  // Type of memory
134  bool nonCacheable; // Can we wrap this in mtype?
135 
136  // Memory Attributes
137  bool shareable;
139 
140  // Access permissions
141  bool xn; // Execute Never
142  bool pxn; // Privileged Execute Never (LPAE only)
143 
144  //Construct an entry that maps to physical address addr for SE mode
145  TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr,
146  bool uncacheable, bool read_only) :
147  pfn(_paddr >> PageShift), size(PageBytes - 1), vpn(_vaddr >> PageShift),
148  attributes(0), lookupLevel(L1), asid(_asn), vmid(0), N(0),
149  innerAttrs(0), outerAttrs(0), ap(read_only ? 0x3 : 0), hap(0x3),
150  domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
151  longDescFormat(false), isHyp(false), global(false), valid(true),
152  ns(true), nstid(true), el(EL0), nonCacheable(uncacheable),
153  shareable(false), outerShareable(false), xn(0), pxn(0)
154  {
155  // no restrictions by default, hap = 0x3
156 
157  // @todo Check the memory type
158  if (read_only)
159  warn("ARM TlbEntry does not support read-only mappings\n");
160  }
161 
163  pfn(0), size(0), vpn(0), attributes(0), lookupLevel(L1), asid(0),
164  vmid(0), N(0), innerAttrs(0), outerAttrs(0), ap(0), hap(0x3),
165  domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
166  longDescFormat(false), isHyp(false), global(false), valid(false),
167  ns(true), nstid(true), el(EL0), nonCacheable(false),
168  shareable(false), outerShareable(false), xn(0), pxn(0)
169  {
170  // no restrictions by default, hap = 0x3
171 
172  // @todo Check the memory type
173  }
174 
175  void
176  updateVaddr(Addr new_vaddr)
177  {
178  vpn = new_vaddr >> PageShift;
179  }
180 
181  Addr
182  pageStart() const
183  {
184  return pfn << PageShift;
185  }
186 
187  bool
188  match(Addr va, uint8_t _vmid, bool hypLookUp, bool secure_lookup,
189  ExceptionLevel target_el, bool in_host) const
190  {
191  return match(va, 0, _vmid, hypLookUp, secure_lookup, true,
192  target_el, in_host);
193  }
194 
195  bool
196  match(Addr va, uint16_t asn, uint8_t _vmid, bool hypLookUp,
197  bool secure_lookup, bool ignore_asn, ExceptionLevel target_el,
198  bool in_host) const
199  {
200  bool match = false;
201  Addr v = vpn << N;
202  if (valid && va >= v && va <= v + size && (secure_lookup == !nstid) &&
203  (hypLookUp == isHyp))
204  {
205  match = checkELMatch(target_el, in_host);
206 
207  if (match && !ignore_asn) {
208  match = global || (asn == asid);
209  }
210  if (match && nstid) {
211  match = isHyp || (_vmid == vmid);
212  }
213  }
214  return match;
215  }
216 
217  bool
218  checkELMatch(ExceptionLevel target_el, bool in_host) const
219  {
220  switch (target_el) {
221  case EL3:
222  return el == EL3;
223  case EL2:
224  {
225  return el == EL2 || (el == EL0 && in_host);
226  }
227  case EL1:
228  case EL0:
229  return (el == EL0) || (el == EL1);
230  default:
231  return false;
232  }
233  }
234 
235  Addr
236  pAddr(Addr va) const
237  {
238  return (pfn << N) | (va & size);
239  }
240 
241  void
243  {
244  uint64_t mask;
245  uint64_t newBits;
246 
247  // chec bit 11 to determine if its currently LPAE or VMSA format.
248  if ( attributes & (1 << 11) ) {
249  newBits = ((outerShareable ? 0x2 :
250  shareable ? 0x3 : 0) << 7);
251  mask = 0x180;
252  } else {
268  newBits = ((outerShareable ? 0:1) << 10) |
269  ((shareable ? 1:0) << 7) |
270  (innerAttrs << 4) |
271  (outerAttrs << 2);
272  // TODO: Supersection bit
273  mask = 0x4FC;
274  }
275  // common bits
276  newBits |= ns << 9; // NS bit
277  mask |= 1 << 9;
278  // add in the new bits
279  attributes &= ~mask;
280  attributes |= newBits;
281  }
282 
283  void
285  {
286  attributes = lpae ? (1 << 11) : 0;
288  }
289 
290  std::string
291  print() const
292  {
293  return csprintf("%#x, asn %d vmn %d hyp %d ppn %#x size: %#x ap:%d "
294  "ns:%d nstid:%d g:%d el:%d", vpn << N, asid, vmid,
295  isHyp, pfn << N, size, ap, ns, nstid, global, el);
296  }
297 
298  void
299  serialize(CheckpointOut &cp) const override
300  {
325  uint8_t domain_ = static_cast<uint8_t>(domain);
326  paramOut(cp, "domain", domain_);
327  }
328  void
330  {
355  uint8_t domain_;
356  paramIn(cp, "domain", domain_);
357  domain = static_cast<DomainType>(domain_);
358  }
359 
360 };
361 
362 
363 
364 }
365 #endif // __ARCH_ARM_PAGETABLE_H__
366 
ArmISA::LookupLevel
LookupLevel
Definition: pagetable.hh:72
warn
#define warn(...)
Definition: logging.hh:239
ArmISA::EL2
@ EL2
Definition: types.hh:624
ArmISA::TlbEntry::global
bool global
Definition: pagetable.hh:123
ArmISA::TlbEntry::hap
uint8_t hap
Definition: pagetable.hh:114
ArmISA::TlbEntry::ap
uint8_t ap
Definition: pagetable.hh:113
serialize.hh
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
ArmISA::TlbEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pagetable.hh:299
ArmISA::EL0
@ EL0
Definition: types.hh:622
ArmISA::TlbEntry::N
uint8_t N
Definition: pagetable.hh:110
ArmISA::TlbEntry::el
ExceptionLevel el
Definition: pagetable.hh:131
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
ArmISA::TlbEntry::updateVaddr
void updateVaddr(Addr new_vaddr)
Definition: pagetable.hh:176
ArmISA::TlbEntry::ns
bool ns
Definition: pagetable.hh:127
ArmISA::EL3
@ EL3
Definition: types.hh:625
ArmISA::TlbEntry::match
bool match(Addr va, uint8_t _vmid, bool hypLookUp, bool secure_lookup, ExceptionLevel target_el, bool in_host) const
Definition: pagetable.hh:188
ArmISA::TlbEntry::MemoryType::Device
@ Device
ArmISA::TlbEntry::longDescFormat
bool longDescFormat
Definition: pagetable.hh:120
ArmISA
Definition: ccregs.hh:41
paramOut
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition: types.cc:38
ArmISA::TlbEntry::DomainType::Client
@ Client
ArmISA::L0
@ L0
Definition: pagetable.hh:73
ArmISA::TlbEntry::TlbEntry
TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr, bool uncacheable, bool read_only)
Definition: pagetable.hh:145
SERIALIZE_ENUM
#define SERIALIZE_ENUM(scalar)
Definition: serialize.hh:813
ArmISA::TlbEntry::innerAttrs
uint8_t innerAttrs
Definition: pagetable.hh:111
cp
Definition: cprintf.cc:40
ArmISA::TlbEntry::attributes
uint64_t attributes
Definition: pagetable.hh:101
ArmISA::PTE::serialize
void serialize(CheckpointOut &cp) const
Definition: pagetable.hh:59
ArmISA::TlbEntry::pageStart
Addr pageStart() const
Definition: pagetable.hh:182
ArmISA::TlbEntry::print
std::string print() const
Definition: pagetable.hh:291
ArmISA::TlbEntry::mtype
MemoryType mtype
Definition: pagetable.hh:117
ArmISA::PTE
Definition: pagetable.hh:57
ArmISA::L1
@ L1
Definition: pagetable.hh:74
ArmISA::TlbEntry::MemoryType::StronglyOrdered
@ StronglyOrdered
ArmISA::ExceptionLevel
ExceptionLevel
Definition: types.hh:621
ArmISA::PageShift
const Addr PageShift
Definition: isa_traits.hh:51
ArmISA::MaxPhysAddrRange
const unsigned MaxPhysAddrRange
Definition: pagetable.hh:54
ArmISA::TlbEntry::pxn
bool pxn
Definition: pagetable.hh:142
ArmISA::TlbEntry::pfn
Addr pfn
Definition: pagetable.hh:98
ArmISA::TlbEntry::shareable
bool shareable
Definition: pagetable.hh:137
ArmISA::TlbEntry::pAddr
Addr pAddr(Addr va) const
Definition: pagetable.hh:236
ArmISA::TlbEntry::setAttributes
void setAttributes(bool lpae)
Definition: pagetable.hh:284
ArmISA::TlbEntry::vmid
uint8_t vmid
Definition: pagetable.hh:109
ArmISA::TlbEntry::MemoryType
MemoryType
Definition: pagetable.hh:84
ArmISA::L2
@ L2
Definition: pagetable.hh:75
ArmISA::TlbEntry::outerAttrs
uint8_t outerAttrs
Definition: pagetable.hh:112
ArmISA::EL1
@ EL1
Definition: types.hh:623
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
utility.hh
ArmISA::TlbEntry::DomainType
DomainType
Definition: pagetable.hh:90
ArmISA::TlbEntry
Definition: pagetable.hh:81
ArmISA::PageBytes
const Addr PageBytes
Definition: isa_traits.hh:52
ArmISA::TlbEntry::nstid
bool nstid
Definition: pagetable.hh:129
ArmISA::TlbEntry::xn
bool xn
Definition: pagetable.hh:141
ArmISA::TlbEntry::checkELMatch
bool checkELMatch(ExceptionLevel target_el, bool in_host) const
Definition: pagetable.hh:218
ArmISA::TlbEntry::domain
DomainType domain
Definition: pagetable.hh:115
ArmISA::TlbEntry::DomainType::Reserved
@ Reserved
ArmISA::TlbEntry::match
bool match(Addr va, uint16_t asn, uint8_t _vmid, bool hypLookUp, bool secure_lookup, bool ignore_asn, ExceptionLevel target_el, bool in_host) const
Definition: pagetable.hh:196
ArmISA::TlbEntry::outerShareable
bool outerShareable
Definition: pagetable.hh:138
ArmISA::TlbEntry::size
Addr size
Definition: pagetable.hh:99
paramIn
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition: types.cc:69
ArmISA::MAX_LOOKUP_LEVELS
@ MAX_LOOKUP_LEVELS
Definition: pagetable.hh:77
ArmISA::TlbEntry::vpn
Addr vpn
Definition: pagetable.hh:100
isa_traits.hh
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
ArmISA::TlbEntry::updateAttributes
void updateAttributes()
Definition: pagetable.hh:242
UNSERIALIZE_ENUM
#define UNSERIALIZE_ENUM(scalar)
Definition: serialize.hh:820
ArmISA::TlbEntry::asid
uint16_t asid
Definition: pagetable.hh:108
ArmISA::TlbEntry::MemoryType::Normal
@ Normal
ArmISA::TlbEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pagetable.hh:329
CheckpointIn
Definition: serialize.hh:67
ArmISA::TlbEntry::nonCacheable
bool nonCacheable
Definition: pagetable.hh:134
ArmISA::PTE::unserialize
void unserialize(CheckpointIn &cp)
Definition: pagetable.hh:64
ArmISA::TlbEntry::lookupLevel
LookupLevel lookupLevel
Definition: pagetable.hh:103
ArmISA::TlbEntry::valid
bool valid
Definition: pagetable.hh:124
ArmISA::TlbEntry::isHyp
bool isHyp
Definition: pagetable.hh:122
ArmISA::TlbEntry::TlbEntry
TlbEntry()
Definition: pagetable.hh:162
ArmISA::lpae
Bitfield< 9 > lpae
Definition: miscregs_types.hh:419
ArmISA::TlbEntry::DomainType::NoAccess
@ NoAccess
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
ArmISA::v
Bitfield< 28 > v
Definition: miscregs_types.hh:51
ArmISA::TlbEntry::DomainType::Manager
@ Manager
ArmISA::va
Bitfield< 8 > va
Definition: miscregs_types.hh:272
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::L3
@ L3
Definition: pagetable.hh:76
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Wed Sep 30 2020 14:02:01 for gem5 by doxygen 1.8.17