gem5 v24.0.0.0
Loading...
Searching...
No Matches
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"
46#include "sim/serialize.hh"
47
48namespace gem5
49{
50
51class ThreadContext;
52
54{
55 public:
56 struct Entry
57 {
59 uint64_t flags;
60
62 Entry() {}
63 };
64
65 protected:
66 typedef std::unordered_map<Addr, Entry> PTable;
67 typedef PTable::iterator PTableItr;
69
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 {
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:
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)
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
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.
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)
void serialize(CheckpointOut &cp) const override
Serialize an object.
bool translate(Addr vaddr, Addr &paddr)
Translate function.
uint64_t pid() const
Definition page_table.hh:86
PTable::iterator PTableItr
Definition page_table.hh:67
virtual void unmap(Addr vaddr, int64_t size)
const std::string externalize() const
Dump all items in the pTable, to a concatenation of strings of the form Addr:Entry;.
virtual bool isUnmapped(Addr vaddr, int64_t size)
Check if any pages in a region are already allocated.
const std::string name() const
void unserialize(CheckpointIn &cp) override
Unserialize an object.
EmulationPageTable(const std::string &__name, uint64_t _pid, Addr _pageSize)
Definition page_table.hh:78
virtual void initState()
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)
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 pair class.
Definition stl.hh:58
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
uint8_t flags
Definition helpers.cc:87
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 8 > a
Definition misc_types.hh:66
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
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 Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0