gem5  v20.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/intmath.hh"
42 #include "base/types.hh"
43 #include "mem/request.hh"
44 #include "sim/serialize.hh"
45 
46 class ThreadContext;
47 
49 {
50  public:
51  struct Entry
52  {
54  uint64_t flags;
55 
56  Entry(Addr paddr, uint64_t flags) : paddr(paddr), flags(flags) {}
57  Entry() {}
58  };
59 
60  protected:
61  typedef std::unordered_map<Addr, Entry> PTable;
62  typedef PTable::iterator PTableItr;
64 
65  const Addr pageSize;
67 
68  const uint64_t _pid;
69  const std::string _name;
70 
71  public:
72 
74  const std::string &__name, uint64_t _pid, Addr _pageSize) :
75  pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))),
76  _pid(_pid), _name(__name), shared(false)
77  {
78  assert(isPowerOf2(pageSize));
79  }
80 
81  uint64_t pid() const { return _pid; };
82 
83  virtual ~EmulationPageTable() {};
84 
85  /* generic page table mapping flags
86  * unset | set
87  * bit 0 - no-clobber | clobber
88  * bit 2 - cacheable | uncacheable
89  * bit 3 - read-write | read-only
90  */
91  enum MappingFlags : uint32_t {
92  Clobber = 1,
94  ReadOnly = 8,
95  };
96 
97  // flag which marks the page table as shared among software threads
98  bool shared;
99 
100  virtual void initState() {};
101 
102  // for DPRINTF compatibility
103  const std::string name() const { return _name; }
104 
105  Addr pageAlign(Addr a) { return (a & ~offsetMask); }
106  Addr pageOffset(Addr a) { return (a & offsetMask); }
107 
116  virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags = 0);
117  virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr);
118  virtual void unmap(Addr vaddr, int64_t size);
119 
126  virtual bool isUnmapped(Addr vaddr, int64_t size);
127 
133  const Entry *lookup(Addr vaddr);
134 
141  bool translate(Addr vaddr, Addr &paddr);
142 
148  bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
149 
155  Fault translate(const RequestPtr &req);
156 
157  void getMappings(std::vector<std::pair<Addr, Addr>> *addr_mappings);
158 
159  void serialize(CheckpointOut &cp) const override;
160  void unserialize(CheckpointIn &cp) override;
161 };
162 
163 #endif // __MEM_PAGE_TABLE_HH__
EmulationPageTable::Entry
Definition: page_table.hh:51
serialize.hh
EmulationPageTable::Uncacheable
@ Uncacheable
Definition: page_table.hh:93
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
EmulationPageTable::initState
virtual void initState()
Definition: page_table.hh:100
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
EmulationPageTable::_name
const std::string _name
Definition: page_table.hh:69
std::vector
STL vector class.
Definition: stl.hh:37
EmulationPageTable::unmap
virtual void unmap(Addr vaddr, int64_t size)
Definition: page_table.cc:101
floorLog2
std::enable_if< std::is_integral< T >::value, int >::type floorLog2(T x)
Definition: intmath.hh:63
EmulationPageTable::Entry::flags
uint64_t flags
Definition: page_table.hh:54
EmulationPageTable::isUnmapped
virtual bool isUnmapped(Addr vaddr, int64_t size)
Check if any pages in a region are already allocated.
Definition: page_table.cc:117
EmulationPageTable::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: page_table.cc:186
EmulationPageTable::_pid
const uint64_t _pid
Definition: page_table.hh:68
request.hh
EmulationPageTable::lookup
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:130
EmulationPageTable::Entry::Entry
Entry()
Definition: page_table.hh:57
EmulationPageTable::getMappings
void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
Definition: page_table.cc:94
EmulationPageTable::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: page_table.cc:169
cp
Definition: cprintf.cc:40
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
EmulationPageTable::pageSize
const Addr pageSize
Definition: page_table.hh:65
EmulationPageTable
Definition: page_table.hh:48
EmulationPageTable::remap
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)
Definition: page_table.cc:72
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
EmulationPageTable::Entry::Entry
Entry(Addr paddr, uint64_t flags)
Definition: page_table.hh:56
EmulationPageTable::Clobber
@ Clobber
Definition: page_table.hh:92
std::pair< Addr, Addr >
EmulationPageTable::name
const std::string name() const
Definition: page_table.hh:103
EmulationPageTable::pageOffset
Addr pageOffset(Addr a)
Definition: page_table.hh:106
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
EmulationPageTable::shared
bool shared
Definition: page_table.hh:98
EmulationPageTable::MappingFlags
MappingFlags
Definition: page_table.hh:91
EmulationPageTable::pTable
PTable pTable
Definition: page_table.hh:63
EmulationPageTable::translate
bool translate(Addr vaddr)
Simplified translate function (just check for translation)
Definition: page_table.hh:148
EmulationPageTable::ReadOnly
@ ReadOnly
Definition: page_table.hh:94
EmulationPageTable::pid
uint64_t pid() const
Definition: page_table.hh:81
types.hh
EmulationPageTable::Entry::paddr
Addr paddr
Definition: page_table.hh:53
EmulationPageTable::offsetMask
const Addr offsetMask
Definition: page_table.hh:66
EmulationPageTable::PTable
std::unordered_map< Addr, Entry > PTable
Definition: page_table.hh:61
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
EmulationPageTable::pageAlign
Addr pageAlign(Addr a)
Definition: page_table.hh:105
intmath.hh
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:45
CheckpointIn
Definition: serialize.hh:67
EmulationPageTable::PTableItr
PTable::iterator PTableItr
Definition: page_table.hh:62
EmulationPageTable::translate
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:140
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102
EmulationPageTable::~EmulationPageTable
virtual ~EmulationPageTable()
Definition: page_table.hh:83
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
EmulationPageTable::EmulationPageTable
EmulationPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize)
Definition: page_table.hh:73

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