gem5  v22.1.0.0
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__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
PageTableTranslationGen(EmulationPageTable *_pt, Addr vaddr, Addr size)
Definition: page_table.hh:172
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition: page_table.cc:172
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
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:133
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)
Definition: page_table.cc:75
bool translate(Addr vaddr)
Simplified translate function (just check for translation)
Definition: page_table.hh:158
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: page_table.cc:186
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:143
uint64_t pid() const
Definition: page_table.hh:86
const uint64_t _pid
Definition: page_table.hh:73
PTable::iterator PTableItr
Definition: page_table.hh:67
virtual void unmap(Addr vaddr, int64_t size)
Definition: page_table.cc:104
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
virtual ~EmulationPageTable()
Definition: page_table.hh:88
virtual bool isUnmapped(Addr vaddr, int64_t size)
Check if any pages in a region are already allocated.
Definition: page_table.cc:120
const std::string name() const
Definition: page_table.hh:109
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: page_table.cc:203
EmulationPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize)
Definition: page_table.hh:78
virtual void initState()
Definition: page_table.hh:106
const std::string _name
Definition: page_table.hh:74
void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
Definition: page_table.cc:97
std::unordered_map< Addr, Entry > PTable
Definition: page_table.hh:66
TranslationGenPtr translateRange(Addr vaddr, Addr size)
Definition: page_table.hh:178
Basic support for object serialization.
Definition: serialize.hh:170
TranslationGen is a base class for a generator object which returns information about address transla...
STL vector class.
Definition: stl.hh:37
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
uint8_t flags
Definition: helpers.cc:66
Bitfield< 8 > a
Definition: misc_types.hh:66
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
std::unique_ptr< TranslationGen > TranslationGenPtr
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Entry(Addr paddr, uint64_t flags)
Definition: page_table.hh:61
This structure represents a single, contiguous translation, or carries information about whatever fau...

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1