gem5  v21.2.1.1
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 "mem/translation_gen.hh"
46 #include "sim/serialize.hh"
47 
48 namespace gem5
49 {
50 
51 class ThreadContext;
52 
54 {
55  public:
56  struct Entry
57  {
59  uint64_t flags;
60 
61  Entry(Addr paddr, uint64_t flags) : paddr(paddr), flags(flags) {}
62  Entry() {}
63  };
64 
65  protected:
66  typedef std::unordered_map<Addr, Entry> PTable;
67  typedef PTable::iterator PTableItr;
69 
70  const Addr _pageSize;
72 
73  const uint64_t _pid;
74  const std::string _name;
75 
76  public:
77 
79  const std::string &__name, uint64_t _pid, Addr _pageSize) :
81  _pid(_pid), _name(__name), shared(false)
82  {
83  assert(isPowerOf2(_pageSize));
84  }
85 
86  uint64_t pid() const { return _pid; };
87 
88  virtual ~EmulationPageTable() {};
89 
90  /* generic page table mapping flags
91  * unset | set
92  * bit 0 - no-clobber | clobber
93  * bit 2 - cacheable | uncacheable
94  * bit 3 - read-write | read-only
95  */
96  enum MappingFlags : uint32_t
97  {
98  Clobber = 1,
100  ReadOnly = 8,
101  };
102 
103  // flag which marks the page table as shared among software threads
104  bool shared;
105 
106  virtual void initState() {};
107 
108  // for DPRINTF compatibility
109  const std::string name() const { return _name; }
110 
111  Addr pageAlign(Addr a) { return (a & ~offsetMask); }
112  Addr pageOffset(Addr a) { return (a & offsetMask); }
113  // Page size can technically vary based on the virtual address, but we'll
114  // ignore that for now.
115  Addr pageSize() { return _pageSize; }
116 
125  virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags = 0);
126  virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr);
127  virtual void unmap(Addr vaddr, int64_t size);
128 
135  virtual bool isUnmapped(Addr vaddr, int64_t size);
136 
142  const Entry *lookup(Addr vaddr);
143 
150  bool translate(Addr vaddr, Addr &paddr);
151 
157  bool
159  {
160  Addr dummy;
161  return translate(vaddr, dummy);
162  }
163 
165  {
166  private:
168 
169  void translate(Range &range) const override;
170 
171  public:
173  Addr size) : TranslationGen(vaddr, size), pt(_pt)
174  {}
175  };
176 
179  {
180  return TranslationGenPtr(
181  new PageTableTranslationGen(this, vaddr, size));
182  }
183 
189  Fault translate(const RequestPtr &req);
190 
195  const std::string externalize() const;
196 
197  void getMappings(std::vector<std::pair<Addr, Addr>> *addr_mappings);
198 
199  void serialize(CheckpointOut &cp) const override;
200  void unserialize(CheckpointIn &cp) override;
201 };
202 
203 } // namespace gem5
204 
205 #endif // __MEM_PAGE_TABLE_HH__
gem5::EmulationPageTable::EmulationPageTable
EmulationPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize)
Definition: page_table.hh:78
gem5::EmulationPageTable::Entry::flags
uint64_t flags
Definition: page_table.hh:59
gem5::TranslationGen::size
Addr size() const
Definition: translation_gen.hh:112
gem5::EmulationPageTable::_name
const std::string _name
Definition: page_table.hh:74
gem5::EmulationPageTable::pageSize
Addr pageSize()
Definition: page_table.hh:115
gem5::EmulationPageTable
Definition: page_table.hh:53
gem5::EmulationPageTable::Uncacheable
@ Uncacheable
Definition: page_table.hh:99
serialize.hh
gem5::EmulationPageTable::PTableItr
PTable::iterator PTableItr
Definition: page_table.hh:67
gem5::EmulationPageTable::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: page_table.cc:186
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:224
gem5::EmulationPageTable::initState
virtual void initState()
Definition: page_table.hh:106
gem5::floorLog2
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
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:100
gem5::EmulationPageTable::shared
bool shared
Definition: page_table.hh:104
gem5::isPowerOf2
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
request.hh
gem5::TranslationGen::Range
This structure represents a single, contiguous translation, or carries information about whatever fau...
Definition: translation_gen.hh:68
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:73
gem5::EmulationPageTable::PageTableTranslationGen
Definition: page_table.hh:164
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::EmulationPageTable::pid
uint64_t pid() const
Definition: page_table.hh:86
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:158
gem5::EmulationPageTable::remap
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)
Definition: page_table.cc:75
gem5::EmulationPageTable::PageTableTranslationGen::PageTableTranslationGen
PageTableTranslationGen(EmulationPageTable *_pt, Addr vaddr, Addr size)
Definition: page_table.hh:172
translation_gen.hh
gem5::RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
gem5::EmulationPageTable::translateRange
TranslationGenPtr translateRange(Addr vaddr, Addr size)
Definition: page_table.hh:178
gem5::EmulationPageTable::offsetMask
const Addr offsetMask
Definition: page_table.hh:71
gem5::EmulationPageTable::name
const std::string name() const
Definition: page_table.hh:109
gem5::EmulationPageTable::pageAlign
Addr pageAlign(Addr a)
Definition: page_table.hh:111
std::pair< Addr, Addr >
gem5::auxv::Entry
@ Entry
Definition: aux_vector.hh:76
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::TranslationGen
TranslationGen is a base class for a generator object which returns information about address transla...
Definition: translation_gen.hh:60
gem5::EmulationPageTable::pTable
PTable pTable
Definition: page_table.hh:68
gem5::EmulationPageTable::Entry::Entry
Entry(Addr paddr, uint64_t flags)
Definition: page_table.hh:61
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:58
types.hh
gem5::EmulationPageTable::PageTableTranslationGen::pt
EmulationPageTable * pt
Definition: page_table.hh:167
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:62
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::EmulationPageTable::pageOffset
Addr pageOffset(Addr a)
Definition: page_table.hh:112
gem5::EmulationPageTable::Entry
Definition: page_table.hh:56
gem5::EmulationPageTable::~EmulationPageTable
virtual ~EmulationPageTable()
Definition: page_table.hh:88
gem5::EmulationPageTable::Clobber
@ Clobber
Definition: page_table.hh:98
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:70
gem5::TranslationGenPtr
std::unique_ptr< TranslationGen > TranslationGenPtr
Definition: translation_gen.hh:128
gem5::EmulationPageTable::MappingFlags
MappingFlags
Definition: page_table.hh:96
gem5::EmulationPageTable::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: page_table.cc:203
gem5::EmulationPageTable::PTable
std::unordered_map< Addr, Entry > PTable
Definition: page_table.hh:66
gem5::EmulationPageTable::PageTableTranslationGen::translate
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition: page_table.cc:172

Generated on Wed May 4 2022 12:14:00 for gem5 by doxygen 1.8.17