gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Steve Reinhardt
30  */
31 
37 #ifndef __MEM_PAGE_TABLE_HH__
38 #define __MEM_PAGE_TABLE_HH__
39 
40 #include <string>
41 #include <unordered_map>
42 
43 #include "base/intmath.hh"
44 #include "base/types.hh"
45 #include "mem/request.hh"
46 #include "sim/serialize.hh"
47 
48 class ThreadContext;
49 
51 {
52  public:
53  struct Entry
54  {
56  uint64_t flags;
57 
58  Entry(Addr paddr, uint64_t flags) : paddr(paddr), flags(flags) {}
59  Entry() {}
60  };
61 
62  protected:
63  typedef std::unordered_map<Addr, Entry> PTable;
64  typedef PTable::iterator PTableItr;
65  PTable pTable;
66 
67  const Addr pageSize;
69 
70  const uint64_t _pid;
71  const std::string _name;
72 
73  public:
74 
76  const std::string &__name, uint64_t _pid, Addr _pageSize) :
77  pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))),
78  _pid(_pid), _name(__name), shared(false)
79  {
80  assert(isPowerOf2(pageSize));
81  }
82 
83  uint64_t pid() const { return _pid; };
84 
85  virtual ~EmulationPageTable() {};
86 
87  /* generic page table mapping flags
88  * unset | set
89  * bit 0 - no-clobber | clobber
90  * bit 2 - cacheable | uncacheable
91  * bit 3 - read-write | read-only
92  */
93  enum MappingFlags : uint32_t {
94  Clobber = 1,
96  ReadOnly = 8,
97  };
98 
99  // flag which marks the page table as shared among software threads
100  bool shared;
101 
102  virtual void initState() {};
103 
104  // for DPRINTF compatibility
105  const std::string name() const { return _name; }
106 
107  Addr pageAlign(Addr a) { return (a & ~offsetMask); }
108  Addr pageOffset(Addr a) { return (a & offsetMask); }
109 
118  virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags = 0);
119  virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr);
120  virtual void unmap(Addr vaddr, int64_t size);
121 
128  virtual bool isUnmapped(Addr vaddr, int64_t size);
129 
135  const Entry *lookup(Addr vaddr);
136 
143  bool translate(Addr vaddr, Addr &paddr);
144 
150  bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
151 
157  Fault translate(const RequestPtr &req);
158 
159  void getMappings(std::vector<std::pair<Addr, Addr>> *addr_mappings);
160 
161  void serialize(CheckpointOut &cp) const override;
162  void unserialize(CheckpointIn &cp) override;
163 };
164 
165 #endif // __MEM_PAGE_TABLE_HH__
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)
Definition: page_table.cc:76
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:49
const std::string name() const
Definition: page_table.hh:105
const std::string _name
Definition: page_table.hh:71
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: page_table.cc:189
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
Bitfield< 8 > a
std::unordered_map< Addr, Entry > PTable
Definition: page_table.hh:63
bool translate(Addr vaddr)
Simplified translate function (just check for translation)
Definition: page_table.hh:150
Definition: cprintf.cc:42
const Addr pageSize
Definition: page_table.hh:67
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Entry(Addr paddr, uint64_t flags)
Definition: page_table.hh:58
STL vector class.
Definition: stl.hh:40
Addr pageOffset(Addr a)
Definition: page_table.hh:108
Addr pageAlign(Addr a)
Definition: page_table.hh:107
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:144
virtual ~EmulationPageTable()
Definition: page_table.hh:85
EmulationPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize)
Definition: page_table.hh:75
bool isPowerOf2(const T &n)
Definition: intmath.hh:146
virtual void initState()
Definition: page_table.hh:102
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Basic support for object serialization.
Definition: serialize.hh:153
int floorLog2(unsigned x)
Definition: intmath.hh:61
virtual bool isUnmapped(Addr vaddr, int64_t size)
Check if any pages in a region are already allocated.
Definition: page_table.cc:121
std::ostream CheckpointOut
Definition: serialize.hh:68
PTable::iterator PTableItr
Definition: page_table.hh:64
const Entry * lookup(Addr vaddr)
Lookup function.
Definition: page_table.cc:134
virtual void unmap(Addr vaddr, int64_t size)
Definition: page_table.cc:105
const uint64_t _pid
Definition: page_table.hh:70
void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
Definition: page_table.cc:98
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: page_table.cc:173
Bitfield< 3, 0 > mask
Definition: types.hh:64
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
const Addr offsetMask
Definition: page_table.hh:68
uint64_t pid() const
Definition: page_table.hh:83

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13