gem5 v24.0.0.0
Loading...
Searching...
No Matches
memory_image.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __BASE_LOADER_MEMORY_IMAGE_HH__
30#define __BASE_LOADER_MEMORY_IMAGE_HH__
31
32#include <algorithm>
33#include <functional>
34#include <initializer_list>
35#include <memory>
36#include <string>
37#include <vector>
38
39#include "base/compiler.hh"
41#include "base/logging.hh"
42#include "base/types.hh"
43
44namespace gem5
45{
46
47class PortProxy;
48
49namespace loader
50{
51
53{
54 public:
55 struct Segment
56 {
57 Segment(const std::string &_name, Addr _base,
58 const uint8_t *_data, size_t _size) :
59 name(_name), base(_base), data(_data), size(_size)
60 {}
61
62 Segment(const std::string &_name, Addr _base, size_t _size) :
63 name(_name), base(_base), size(_size)
64 {}
65
66 Segment(const std::string &_name, Addr _base,
67 const ImageFileDataPtr &_ifd, Addr offset, size_t _size) :
68 ifd(_ifd), name(_name), base(_base), size(_size)
69 {
70 panic_if(offset + size > ifd->len(),
71 "Segment outside the bounds of the image data");
72 data = ifd->data() + offset;
73 }
74
75 Segment(const std::string &_name, const ImageFileDataPtr &_ifd) :
76 Segment(_name, 0, _ifd, 0, _ifd->len())
77 {}
78
80 std::string name;
82 const uint8_t *data = nullptr;
83 size_t size = 0;
84 };
85
87
89 {
91 }
92
93 MemoryImage(std::initializer_list<Segment> segs)
94 {
95 addSegments(segs);
96 }
97
98 private:
100 bool writeSegment(const Segment &seg, const PortProxy &proxy) const;
101
102 public:
104 segments() const
105 {
106 return _segments;
107 }
108
109 void
111 {
112 _segments.emplace_back(seg);
113 }
114
115 void
116 addSegments(std::initializer_list<Segment> segs)
117 {
118 for (auto &seg: segs)
120 }
121
122 bool write(const PortProxy &proxy) const;
123 MemoryImage &move(std::function<Addr(Addr)> mapper);
126 {
127 return move([by](Addr a){ return by + a; });
128 }
131 return move([m](Addr a) { return a & m; });
132 }
133
134 Addr
135 maxAddr() const
136 {
137 Addr max = 0;
138 for (auto &seg: _segments)
139 max = std::max(max, seg.base + seg.size);
140 return max;
141 }
142
143 Addr
144 minAddr() const
145 {
146 Addr min = MaxAddr;
147 for (auto &seg: _segments)
148 min = std::min(min, seg.base);
149 return min;
150 }
151
152 bool
154 {
155 for (auto &seg: _segments) {
156 Addr start = seg.base;
157 Addr end = seg.base + seg.size;
158 if (addr >= start && addr < end)
159 return true;
160 }
161 return false;
162 }
163};
164
165static inline std::ostream &
166operator << (std::ostream &os, const MemoryImage::Segment &seg)
167{
168 ccprintf(os, "%s: %#x %d", seg.name, seg.base, seg.size);
169 return os;
170}
171
172} // namespace loader
173} // namespace gem5
174
175#endif // __BASE_LOADER_MEMORY_IMAGE_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition port_proxy.hh:87
MemoryImage(const Segment &seg)
const std::vector< Segment > & segments() const
void addSegments(std::initializer_list< Segment > segs)
MemoryImage & offset(Addr by)
std::vector< Segment > _segments
void addSegment(const Segment &seg)
bool contains(Addr addr) const
MemoryImage & mask(Addr m)
bool write(const PortProxy &proxy) const
bool writeSegment(const Segment &seg, const PortProxy &proxy) const
MemoryImage(std::initializer_list< Segment > segs)
MemoryImage & move(std::function< Addr(Addr)> mapper)
STL vector class.
Definition stl.hh:37
#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
Bitfield< 18, 16 > len
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 0 > m
Bitfield< 17 > os
Definition misc.hh:838
Bitfield< 3 > addr
Definition types.hh:84
Bitfield< 2, 0 > seg
Definition types.hh:87
static std::ostream & operator<<(std::ostream &os, const MemoryImage::Segment &seg)
std::shared_ptr< ImageFileData > ImageFileDataPtr
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
const Addr MaxAddr
Definition types.hh:171
void ccprintf(cp::Print &print)
Definition cprintf.hh:130
Segment(const std::string &_name, Addr _base, size_t _size)
Segment(const std::string &_name, const ImageFileDataPtr &_ifd)
Segment(const std::string &_name, Addr _base, const ImageFileDataPtr &_ifd, Addr offset, size_t _size)
Segment(const std::string &_name, Addr _base, const uint8_t *_data, size_t _size)

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0