gem5 v23.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
37namespace gem5
38{
39
40class TranslationGenConstIterator;
41
61{
62 public:
68 struct Range
69 {
72
75 };
76
77 protected:
94 virtual void translate(Range &range) const = 0;
95
98
99 public:
106 TranslationGen(Addr new_start, Addr new_size) :
107 _start(new_start), _size(new_size)
108 {}
109 virtual ~TranslationGen() {}
110
111 Addr start() const { return _start; }
112 Addr size() const { return _size; }
113
123
124 inline const_iterator begin() const;
125 inline const_iterator end() const;
126};
127
128using TranslationGenPtr = std::unique_ptr<TranslationGen>;
129
141{
142 private:
144 const TranslationGen *gen = nullptr;
145 bool end = true;
146
147 friend class TranslationGen;
148
150 void
152 {
153 current.paddr = 0;
154 // Set the size to however much is left, aka the maximum.
155 current.size = gen->size() - (current.vaddr - gen->start());
156
157 if (current.size == 0) {
158 // Transform into the end iterator.
159 end = true;
160 current.vaddr = 0;
161 gen = nullptr;
162 } else {
164 }
165 }
166
171 current{start}, gen(parent), end(false)
172 {
173 update();
174 }
175
176 public:
178 using reference = const value_type &;
179 using pointer = const value_type *;
180 using iterator_category = std::forward_iterator_tag;
181
183 current(other.current), gen(other.gen)
184 {}
185
188 {
189 gen = other.gen;
190 current = other.current;
191 return *this;
192 }
193
196
213 {
214 panic_if(end, "Can't increment end iterator.");
215 assert(gen);
216
217 if (current.fault == NoFault) {
218 // If the last translation was successful, move forward.
220 } else {
221 // If not, clear out the fault and try again, assuming the
222 // caller has fixed whatever the problem was.
224 }
225
226 update();
227
228 return *this;
229 }
230
233 {
234 const auto orig(*this);
235 ++*this;
236 return orig;
237 }
238
239 bool
241 {
242 return other.gen == gen && other.current.vaddr == current.vaddr;
243 }
244
245 bool
247 {
248 return !(*this == other);
249 }
250};
251
252TranslationGenConstIterator
254{
255 return const_iterator(this, start());
256}
257
260{
261 return const_iterator();
262}
263
264} // namespace gem5
265
266#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
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
This structure represents a single, contiguous translation, or carries information about whatever fau...

Generated on Mon Jul 10 2023 14:24:33 for gem5 by doxygen 1.9.7