gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 "arch/isa_traits.hh"
44 #include "arch/tlb.hh"
45 #include "base/intmath.hh"
46 #include "base/types.hh"
47 #include "config/the_isa.hh"
48 #include "mem/request.hh"
49 #include "sim/serialize.hh"
50 
51 class ThreadContext;
52 class System;
53 
58 {
59  protected:
60  struct cacheElement {
61  bool valid;
64  };
65 
67 
68  const Addr pageSize;
70 
71  const uint64_t pid;
72  const std::string _name;
73 
74  public:
75 
76  PageTableBase(const std::string &__name, uint64_t _pid,
77  Addr _pageSize = TheISA::PageBytes)
78  : pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))),
79  pid(_pid), _name(__name)
80  {
81  assert(isPowerOf2(pageSize));
82  pTableCache[0].valid = false;
83  pTableCache[1].valid = false;
84  pTableCache[2].valid = false;
85  }
86 
87  virtual ~PageTableBase() {};
88 
89  /* generic page table mapping flags
90  * unset | set
91  * bit 0 - no-clobber | clobber
92  * bit 1 - present | not-present
93  * bit 2 - cacheable | uncacheable
94  * bit 3 - read-write | read-only
95  */
96  enum MappingFlags : uint32_t {
97  Zero = 0,
98  Clobber = 1,
101  ReadOnly = 8,
102  };
103 
104  virtual void initState(ThreadContext* tc) = 0;
105 
106  // for DPRINTF compatibility
107  const std::string name() const { return _name; }
108 
109  Addr pageAlign(Addr a) { return (a & ~offsetMask); }
110  Addr pageOffset(Addr a) { return (a & offsetMask); }
111 
120  virtual void map(Addr vaddr, Addr paddr, int64_t size,
121  uint64_t flags = 0) = 0;
122  virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr) = 0;
123  virtual void unmap(Addr vaddr, int64_t size) = 0;
124 
131  virtual bool isUnmapped(Addr vaddr, int64_t size) = 0;
132 
138  virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry) = 0;
139 
146  bool translate(Addr vaddr, Addr &paddr);
147 
153  bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); }
154 
161 
168  {
172 
176 
177  pTableCache[0].entry = entry;
178  pTableCache[0].vaddr = vaddr;
179  pTableCache[0].valid = true;
180  }
181 
187  {
188  // Invalidate cached entries if necessary
189  if (pTableCache[0].valid && pTableCache[0].vaddr == vaddr) {
190  pTableCache[0].valid = false;
191  } else if (pTableCache[1].valid && pTableCache[1].vaddr == vaddr) {
192  pTableCache[1].valid = false;
193  } else if (pTableCache[2].valid && pTableCache[2].vaddr == vaddr) {
194  pTableCache[2].valid = false;
195  }
196  }
197 
199  *addr_mappings) {};
200 };
201 
206 {
207  private:
208  typedef std::unordered_map<Addr, TheISA::TlbEntry> PTable;
209  typedef PTable::iterator PTableItr;
211 
212  public:
213 
214  FuncPageTable(const std::string &__name, uint64_t _pid,
215  Addr _pageSize = TheISA::PageBytes);
216 
217  ~FuncPageTable();
218 
219  void initState(ThreadContext* tc) override
220  {
221  }
222 
223  void map(Addr vaddr, Addr paddr, int64_t size,
224  uint64_t flags = 0) override;
225  void remap(Addr vaddr, int64_t size, Addr new_vaddr) override;
226  void unmap(Addr vaddr, int64_t size) override;
227 
234  bool isUnmapped(Addr vaddr, int64_t size) override;
235 
241  bool lookup(Addr vaddr, TheISA::TlbEntry &entry) override;
242 
243  void serialize(CheckpointOut &cp) const override;
244  void unserialize(CheckpointIn &cp) override;
245 
246  void getMappings(std::vector<std::pair<Addr, Addr>> *addr_maps) override;
247 };
248 
255 {
256  public:
257  NoArchPageTable(const std::string &__name, uint64_t _pid, System *_sys,
258  Addr _pageSize = TheISA::PageBytes) : FuncPageTable(__name, _pid)
259  {
260  fatal("No architectural page table defined for this ISA.\n");
261  }
262 };
263 
264 #endif // __MEM_PAGE_TABLE_HH__
Declaration of functional page table.
Definition: page_table.hh:205
virtual void unmap(Addr vaddr, int64_t size)=0
virtual void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
Definition: page_table.hh:198
void updateCache(Addr vaddr, TheISA::TlbEntry entry)
Update the page table cache.
Definition: page_table.hh:167
virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0)=0
Maps a virtual memory region to a physical memory region.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Bitfield< 8 > a
Definition: miscregs.hh:1377
bool isUnmapped(Addr vaddr, int64_t size) override
Check if any pages in a region are already allocated.
Definition: page_table.cc:129
Addr pageAlign(Addr a)
Definition: page_table.hh:109
TheISA::TlbEntry entry
Definition: page_table.hh:63
virtual ~PageTableBase()
Definition: page_table.hh:87
FuncPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize=TheISA::PageBytes)
Definition: page_table.cc:51
Definition: system.hh:83
Addr pageOffset(Addr a)
Definition: page_table.hh:110
ThreadContext is the external interface to all thread state for anything outside of the CPU...
const Addr pageSize
Definition: page_table.hh:68
STL vector class.
Definition: stl.hh:40
void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0) override
Maps a virtual memory region to a physical memory region.
Definition: page_table.cc:62
std::unordered_map< Addr, TheISA::TlbEntry > PTable
Definition: page_table.hh:208
PTable::iterator PTableItr
Definition: page_table.hh:209
void remap(Addr vaddr, int64_t size, Addr new_vaddr) override
Definition: page_table.cc:85
bool translate(Addr vaddr)
Simplified translate function (just check for translation)
Definition: page_table.hh:153
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)=0
bool translate(Addr vaddr, Addr &paddr)
Translate function.
Definition: page_table.cc:173
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: page_table.cc:203
Faux page table class indended to stop the usage of an architectural page table, when there is none d...
Definition: page_table.hh:254
#define fatal(...)
Definition: misc.hh:163
TlbEntry(Addr asn, Addr _vaddr, Addr _paddr, bool uncacheable, bool read_only)
bool isPowerOf2(const T &n)
Definition: intmath.hh:73
const Addr offsetMask
Definition: page_table.hh:69
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
const std::string name() const
Definition: page_table.hh:107
Basic support for object serialization.
Definition: serialize.hh:220
virtual void initState(ThreadContext *tc)=0
const Addr PageBytes
Definition: isa_traits.hh:52
Declaration of base class for page table.
Definition: page_table.hh:57
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: page_table.cc:218
int floorLog2(unsigned x)
Definition: intmath.hh:100
int size()
Definition: pagetable.hh:146
void unmap(Addr vaddr, int64_t size) override
Definition: page_table.cc:114
void getMappings(std::vector< std::pair< Addr, Addr >> *addr_maps) override
Definition: page_table.cc:107
NoArchPageTable(const std::string &__name, uint64_t _pid, System *_sys, Addr _pageSize=TheISA::PageBytes)
Definition: page_table.hh:257
std::ostream CheckpointOut
Definition: serialize.hh:67
bool lookup(Addr vaddr, TheISA::TlbEntry &entry) override
Lookup function.
Definition: page_table.cc:144
virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry)=0
Lookup function.
void eraseCacheEntry(Addr vaddr)
Erase an entry from the page table cache.
Definition: page_table.hh:186
const std::string _name
Definition: page_table.hh:72
struct cacheElement pTableCache[3]
Definition: page_table.hh:66
Bitfield< 3, 0 > mask
Definition: types.hh:64
void initState(ThreadContext *tc) override
Definition: page_table.hh:219
virtual bool isUnmapped(Addr vaddr, int64_t size)=0
Check if any pages in a region are already allocated.
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
const uint64_t pid
Definition: page_table.hh:71
PageTableBase(const std::string &__name, uint64_t _pid, Addr _pageSize=TheISA::PageBytes)
Definition: page_table.hh:76

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6