gem5  v21.1.0.2
page_table.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Advanced Micro Devices, Inc.
3  * Copyright (c) 2003 The Regents of The University of Michigan
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
35 #ifndef __MEM_PAGE_TABLE_HH__
36 #define __MEM_PAGE_TABLE_HH__
37 
38 #include <string>
39 #include <unordered_map>
40 
41 #include "base/bitfield.hh"
42 #include "base/intmath.hh"
43 #include "base/types.hh"
44 #include "mem/request.hh"
45 #include "sim/serialize.hh"
46 
47 namespace gem5
48 {
49 
50 class ThreadContext;
51 
53 {
54  public:
55  struct Entry
56  {
58  uint64_t flags;
59 
60  Entry(Addr paddr, uint64_t flags) : paddr(paddr), flags(flags) {}
61  Entry() {}
62  };
63 
64  protected:
65  typedef std::unordered_map<Addr, Entry> PTable;
66  typedef PTable::iterator PTableItr;
68 
69  const Addr _pageSize;
71 
72  const uint64_t _pid;
73  const std::string _name;
74 
75  public:
76 
78  const std::string &__name, uint64_t _pid, Addr _pageSize) :
80  _pid(_pid), _name(__name), shared(false)
81  {
82  assert(isPowerOf2(_pageSize));
83  }
84 
85  uint64_t pid() const { return _pid; };
86 
87  virtual ~EmulationPageTable() {};
88 
89  /* generic page table mapping flags
90  * unset | set
91  * bit 0 - no-clobber | clobber
92  * bit 2 - cacheable | uncacheable
93  * bit 3 - read-write | read-only
94  */
95  enum MappingFlags : uint32_t
96  {
97  Clobber = 1,
99  ReadOnly = 8,
100  };
101 
102  // flag which marks the page table as shared among software threads
103  bool shared;
104 
105  virtual void initState() {};
106 
107  // for DPRINTF compatibility
108  const std::string name() const { return _name; }
109 
110  Addr pageAlign(Addr a) { return (a & ~offsetMask); }
111  Addr pageOffset(Addr a) { return (a & offsetMask); }
112  // Page size can technically vary based on the virtual address, but we'll
113  // ignore that for now.
114  Addr pageSize() { return _pageSize; }
115 
124  virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags = 0);
125  virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr);
126  virtual void unmap(Addr vaddr, int64_t size);
127 
134  virtual bool isUnmapped(Addr vaddr, int64_t size);
135 
141  const Entry *lookup(Addr vaddr);
142 
149  bool translate(Addr vaddr, Addr &paddr);
150 
156  bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
157 
163  Fault translate(const RequestPtr &req);
164 
169  const std::string externalize() const;
170 
171  void getMappings(std::vector<std::pair<Addr, Addr>> *addr_mappings);
172 
173  void serialize(CheckpointOut &cp) const override;
174  void unserialize(CheckpointIn &cp) override;
175 };
176 
177 } // namespace gem5
178 
179 #endif // __MEM_PAGE_TABLE_HH__
gem5::EmulationPageTable::EmulationPageTable
EmulationPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize)
Definition: page_table.hh:77
gem5::EmulationPageTable::Entry::flags
uint64_t flags
Definition: page_table.hh:58
gem5::EmulationPageTable::_name
const std::string _name
Definition: page_table.hh:73
gem5::EmulationPageTable::pageSize
Addr pageSize()
Definition: page_table.hh:114
gem5::EmulationPageTable
Definition: page_table.hh:52
gem5::EmulationPageTable::Uncacheable
@ Uncacheable
Definition: page_table.hh:98
serialize.hh
gem5::EmulationPageTable::PTableItr
PTable::iterator PTableItr
Definition: page_table.hh:66
gem5::EmulationPageTable::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: page_table.cc:172
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::EmulationPageTable::unmap
virtual void unmap(Addr vaddr, int64_t size)
Definition: page_table.cc:104
gem5::EmulationPageTable::externalize
const std::string externalize() const
Dump all items in the pTable, to a concatenation of strings of the form Addr:Entry;.
Definition: page_table.cc:210
gem5::EmulationPageTable::initState
virtual void initState()
Definition: page_table.hh:105
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:65
gem5::EmulationPageTable::translate
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:143
std::vector
STL vector class.
Definition: stl.hh:37
gem5::EmulationPageTable::getMappings
void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
Definition: page_table.cc:97
gem5::EmulationPageTable::lookup
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:133
gem5::EmulationPageTable::ReadOnly
@ ReadOnly
Definition: page_table.hh:99
gem5::EmulationPageTable::shared
bool shared
Definition: page_table.hh:103
gem5::isPowerOf2
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
request.hh
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::EmulationPageTable::_pid
const uint64_t _pid
Definition: page_table.hh:72
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::EmulationPageTable::pid
uint64_t pid() const
Definition: page_table.hh:85
bitfield.hh
gem5::Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:255
gem5::EmulationPageTable::translate
bool translate(Addr vaddr)
Simplified translate function (just check for translation)
Definition: page_table.hh:156
gem5::EmulationPageTable::remap
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)
Definition: page_table.cc:75
gem5::RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
gem5::EmulationPageTable::offsetMask
const Addr offsetMask
Definition: page_table.hh:70
gem5::EmulationPageTable::name
const std::string name() const
Definition: page_table.hh:108
gem5::EmulationPageTable::pageAlign
Addr pageAlign(Addr a)
Definition: page_table.hh:110
std::pair< Addr, Addr >
gem5::auxv::Entry
@ Entry
Definition: aux_vector.hh:78
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::EmulationPageTable::pTable
PTable pTable
Definition: page_table.hh:67
gem5::EmulationPageTable::Entry::Entry
Entry(Addr paddr, uint64_t flags)
Definition: page_table.hh:60
gem5::EmulationPageTable::map
virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0)
Maps a virtual memory region to a physical memory region.
Definition: page_table.cc:48
gem5::EmulationPageTable::Entry::paddr
Addr paddr
Definition: page_table.hh:57
types.hh
gem5::floorLog2
static constexpr std::enable_if_t< std::is_integral< T >::value, int > floorLog2(T x)
Definition: intmath.hh:59
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::MipsISA::vaddr
vaddr
Definition: pra_constants.hh:278
intmath.hh
gem5::EmulationPageTable::Entry::Entry
Entry()
Definition: page_table.hh:61
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::EmulationPageTable::pageOffset
Addr pageOffset(Addr a)
Definition: page_table.hh:111
gem5::EmulationPageTable::Entry
Definition: page_table.hh:55
gem5::EmulationPageTable::~EmulationPageTable
virtual ~EmulationPageTable()
Definition: page_table.hh:87
gem5::EmulationPageTable::Clobber
@ Clobber
Definition: page_table.hh:97
gem5::EmulationPageTable::isUnmapped
virtual bool isUnmapped(Addr vaddr, int64_t size)
Check if any pages in a region are already allocated.
Definition: page_table.cc:120
gem5::EmulationPageTable::_pageSize
const Addr _pageSize
Definition: page_table.hh:69
gem5::EmulationPageTable::MappingFlags
MappingFlags
Definition: page_table.hh:95
gem5::EmulationPageTable::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: page_table.cc:189
gem5::EmulationPageTable::PTable
std::unordered_map< Addr, Entry > PTable
Definition: page_table.hh:65

Generated on Tue Sep 21 2021 12:25:34 for gem5 by doxygen 1.8.17