gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
44 namespace gem5
45 {
46 
47 class PortProxy;
48 
49 namespace 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;
81  Addr base = 0;
82  const uint8_t *data = nullptr;
83  size_t size = 0;
84  };
85 
87 
89  {
90  addSegment(seg);
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:
103  const std::vector<Segment> &
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)
119  addSegment(seg);
120  }
121 
122  bool write(const PortProxy &proxy) const;
123  MemoryImage &move(std::function<Addr(Addr)> mapper);
124  MemoryImage &
126  {
127  return move([by](Addr a){ return by + a; });
128  }
129  MemoryImage &
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 
165 static inline std::ostream &
166 operator << (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__
gem5::loader::MemoryImage::MemoryImage
MemoryImage()
Definition: memory_image.hh:86
gem5::loader::MemoryImage::maxAddr
Addr maxAddr() const
Definition: memory_image.hh:135
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, const ImageFileDataPtr &_ifd)
Definition: memory_image.hh:75
gem5::loader::MemoryImage::MemoryImage
MemoryImage(std::initializer_list< Segment > segs)
Definition: memory_image.hh:93
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::loader::operator<<
static std::ostream & operator<<(std::ostream &os, const MemoryImage::Segment &seg)
Definition: memory_image.hh:166
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, Addr _base, const uint8_t *_data, size_t _size)
Definition: memory_image.hh:57
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
std::vector
STL vector class.
Definition: stl.hh:37
gem5::loader::MemoryImage::Segment::ifd
ImageFileDataPtr ifd
Definition: memory_image.hh:79
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, Addr _base, size_t _size)
Definition: memory_image.hh:62
image_file_data.hh
gem5::ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
gem5::loader::MemoryImage::Segment::base
Addr base
Definition: memory_image.hh:81
gem5::loader::MemoryImage::_segments
std::vector< Segment > _segments
Definition: memory_image.hh:99
gem5::loader::MemoryImage::Segment
Definition: memory_image.hh:55
gem5::loader::MemoryImage::offset
MemoryImage & offset(Addr by)
Definition: memory_image.hh:125
gem5::MaxAddr
const Addr MaxAddr
Definition: types.hh:171
gem5::loader::MemoryImage::addSegment
void addSegment(const Segment &seg)
Definition: memory_image.hh:110
gem5::loader::MemoryImage::move
MemoryImage & move(std::function< Addr(Addr)> mapper)
Definition: memory_image.cc:62
gem5::loader::MemoryImage::Segment::size
size_t size
Definition: memory_image.hh:83
gem5::loader::MemoryImage
Definition: memory_image.hh:52
len
uint16_t len
Definition: helpers.cc:62
gem5::PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:86
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, Addr _base, const ImageFileDataPtr &_ifd, Addr offset, size_t _size)
Definition: memory_image.hh:66
gem5::loader::MemoryImage::contains
bool contains(Addr addr) const
Definition: memory_image.hh:153
compiler.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::loader::MemoryImage::Segment::data
const uint8_t * data
Definition: memory_image.hh:82
panic_if
#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
gem5::loader::MemoryImage::addSegments
void addSegments(std::initializer_list< Segment > segs)
Definition: memory_image.hh:116
gem5::loader::MemoryImage::minAddr
Addr minAddr() const
Definition: memory_image.hh:144
types.hh
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:810
gem5::loader::MemoryImage::segments
const std::vector< Segment > & segments() const
Definition: memory_image.hh:104
gem5::loader::ImageFileDataPtr
std::shared_ptr< ImageFileData > ImageFileDataPtr
Definition: image_file_data.hh:60
gem5::X86ISA::seg
Bitfield< 2, 0 > seg
Definition: types.hh:87
logging.hh
gem5::loader::MemoryImage::MemoryImage
MemoryImage(const Segment &seg)
Definition: memory_image.hh:88
gem5::loader::MemoryImage::write
bool write(const PortProxy &proxy) const
Definition: memory_image.cc:53
gem5::loader::MemoryImage::mask
MemoryImage & mask(Addr m)
Definition: memory_image.hh:130
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::loader::MemoryImage::writeSegment
bool writeSegment(const Segment &seg, const PortProxy &proxy) const
Definition: memory_image.cc:39
gem5::loader::MemoryImage::Segment::name
std::string name
Definition: memory_image.hh:80
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17