gem5 v24.0.0.0
Loading...
Searching...
No Matches
translation_gen.hh
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef __MEM_TRANSLATION_GEN_HH__
29#define __MEM_TRANSLATION_GEN_HH__
30
31#include <iterator>
32#include <memory>
33
34#include "base/logging.hh"
35#include "base/types.hh"
36#include "mem/request.hh"
37
38namespace gem5
39{
40
41class TranslationGenConstIterator;
42
62{
63 public:
69 struct Range
70 {
73
75 // PTEs can also set the Secure/non-secure bit, so it is stored here.
78 };
79
80 protected:
97 virtual void translate(Range &range) const = 0;
98
101
102 public:
109 TranslationGen(Addr new_start, Addr new_size) :
110 _start(new_start), _size(new_size)
111 {}
112 virtual ~TranslationGen() {}
113
114 Addr start() const { return _start; }
115 Addr size() const { return _size; }
116
126
127 inline const_iterator begin() const;
128 inline const_iterator end() const;
129};
130
131using TranslationGenPtr = std::unique_ptr<TranslationGen>;
132
144{
145 private:
147 const TranslationGen *gen = nullptr;
148 bool end = true;
149
150 friend class TranslationGen;
151
153 void
155 {
156 current.paddr = 0;
157 // Set the size to however much is left, aka the maximum.
158 current.size = gen->size() - (current.vaddr - gen->start());
159
160 if (current.size == 0) {
161 // Transform into the end iterator.
162 end = true;
163 current.vaddr = 0;
164 gen = nullptr;
165 } else {
167 }
168 }
169
174 current{start}, gen(parent), end(false)
175 {
176 update();
177 }
178
179 public:
181 using reference = const value_type &;
182 using pointer = const value_type *;
183 using iterator_category = std::forward_iterator_tag;
184
188
191 {
192 gen = other.gen;
193 current = other.current;
194 return *this;
195 }
196
199
216 {
217 panic_if(end, "Can't increment end iterator.");
218 assert(gen);
219
220 if (current.fault == NoFault) {
221 // If the last translation was successful, move forward.
223 } else {
224 // If not, clear out the fault and try again, assuming the
225 // caller has fixed whatever the problem was.
227 }
228
229 update();
230
231 return *this;
232 }
233
236 {
237 const auto orig(*this);
238 ++*this;
239 return orig;
240 }
241
242 bool
244 {
245 return other.gen == gen && other.current.vaddr == current.vaddr;
246 }
247
248 bool
250 {
251 return !(*this == other);
252 }
253};
254
255TranslationGenConstIterator
257{
258 return const_iterator(this, start());
259}
260
263{
264 return const_iterator();
265}
266
267} // namespace gem5
268
269#endif // __MEM_TRANSLATION_GEN_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
An iterator for pulling "Range" instances out of a TranslationGen.
TranslationGenConstIterator(const TranslationGen *parent, Addr start)
Construct a valid new iterator and set it's starting conditions.
bool operator!=(const TranslationGenConstIterator &other) const
bool operator==(const TranslationGenConstIterator &other) const
void update()
Use the vaddr of the "current" Range to update its other fields.
TranslationGenConstIterator operator++(int)
std::forward_iterator_tag iterator_category
TranslationGenConstIterator()
Construct a blank iterator, used by end().
TranslationGenConstIterator & operator++()
The increment operator, which is the main work horse of this class.
TranslationGenConstIterator & operator=(const TranslationGenConstIterator &other)
TranslationGenConstIterator(const TranslationGenConstIterator &other)
TranslationGen is a base class for a generator object which returns information about address transla...
friend class TranslationGenConstIterator
A const iterator class is provided so this generator can be used in a range based for loop.
TranslationGen(Addr new_start, Addr new_size)
The starting virtual address and the size of the entire region being translated.
TranslationGenConstIterator const_iterator
const_iterator begin() const
const_iterator end() const
virtual void translate(Range &range) const =0
Subclasses implement this function to complete TranslationGen.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
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
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
constexpr decltype(nullptr) NoFault
Definition types.hh:253
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
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