gem5  v21.1.0.2
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 GEM5_DEPRECATED_NAMESPACE(Loader, loader);
50 namespace loader
51 {
52 
54 {
55  public:
56  struct Segment
57  {
58  Segment(const std::string &_name, Addr _base,
59  const uint8_t *_data, size_t _size) :
60  name(_name), base(_base), data(_data), size(_size)
61  {}
62 
63  Segment(const std::string &_name, Addr _base, size_t _size) :
64  name(_name), base(_base), size(_size)
65  {}
66 
67  Segment(const std::string &_name, Addr _base,
68  const ImageFileDataPtr &_ifd, Addr offset, size_t _size) :
69  ifd(_ifd), name(_name), base(_base), size(_size)
70  {
71  panic_if(offset + size > ifd->len(),
72  "Segment outside the bounds of the image data");
73  data = ifd->data() + offset;
74  }
75 
76  Segment(const std::string &_name, const ImageFileDataPtr &_ifd) :
77  Segment(_name, 0, _ifd, 0, _ifd->len())
78  {}
79 
81  std::string name;
82  Addr base = 0;
83  const uint8_t *data = nullptr;
84  size_t size = 0;
85  };
86 
88 
90  {
91  addSegment(seg);
92  }
93 
94  MemoryImage(std::initializer_list<Segment> segs)
95  {
96  addSegments(segs);
97  }
98 
99  private:
101  bool writeSegment(const Segment &seg, const PortProxy &proxy) const;
102 
103  public:
104  const std::vector<Segment> &
105  segments() const
106  {
107  return _segments;
108  }
109 
110  void
112  {
113  _segments.emplace_back(seg);
114  }
115 
116  void
117  addSegments(std::initializer_list<Segment> segs)
118  {
119  for (auto &seg: segs)
120  addSegment(seg);
121  }
122 
123  bool write(const PortProxy &proxy) const;
124  MemoryImage &move(std::function<Addr(Addr)> mapper);
125  MemoryImage &
127  {
128  return move([by](Addr a){ return by + a; });
129  }
130  MemoryImage &
132  return move([m](Addr a) { return a & m; });
133  }
134 
135  Addr
136  maxAddr() const
137  {
138  Addr max = 0;
139  for (auto &seg: _segments)
140  max = std::max(max, seg.base + seg.size);
141  return max;
142  }
143 
144  Addr
145  minAddr() const
146  {
147  Addr min = MaxAddr;
148  for (auto &seg: _segments)
149  min = std::min(min, seg.base);
150  return min;
151  }
152 
153  bool
155  {
156  for (auto &seg: _segments) {
157  Addr start = seg.base;
158  Addr end = seg.base + seg.size;
159  if (addr >= start && addr < end)
160  return true;
161  }
162  return false;
163  }
164 };
165 
166 static inline std::ostream &
167 operator << (std::ostream &os, const MemoryImage::Segment &seg)
168 {
169  ccprintf(os, "%s: %#x %d", seg.name, seg.base, seg.size);
170  return os;
171 }
172 
173 } // namespace loader
174 } // namespace gem5
175 
176 #endif // __BASE_LOADER_MEMORY_IMAGE_HH__
gem5::loader::MemoryImage::MemoryImage
MemoryImage()
Definition: memory_image.hh:87
gem5::loader::MemoryImage::maxAddr
Addr maxAddr() const
Definition: memory_image.hh:136
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, const ImageFileDataPtr &_ifd)
Definition: memory_image.hh:76
gem5::loader::MemoryImage::MemoryImage
MemoryImage(std::initializer_list< Segment > segs)
Definition: memory_image.hh:94
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
gem5::loader::operator<<
static std::ostream & operator<<(std::ostream &os, const MemoryImage::Segment &seg)
Definition: memory_image.hh:167
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, Addr _base, const uint8_t *_data, size_t _size)
Definition: memory_image.hh:58
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:65
std::vector
STL vector class.
Definition: stl.hh:37
gem5::loader::MemoryImage::Segment::ifd
ImageFileDataPtr ifd
Definition: memory_image.hh:80
gem5::loader::MemoryImage::Segment::Segment
Segment(const std::string &_name, Addr _base, size_t _size)
Definition: memory_image.hh:63
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:82
gem5::loader::MemoryImage::_segments
std::vector< Segment > _segments
Definition: memory_image.hh:100
gem5::loader::MemoryImage::Segment
Definition: memory_image.hh:56
gem5::loader::MemoryImage::offset
MemoryImage & offset(Addr by)
Definition: memory_image.hh:126
gem5::MaxAddr
const Addr MaxAddr
Definition: types.hh:171
gem5::loader::MemoryImage::addSegment
void addSegment(const Segment &seg)
Definition: memory_image.hh:111
gem5::loader::MemoryImage::move
MemoryImage & move(std::function< Addr(Addr)> mapper)
Definition: memory_image.cc:63
gem5::loader::MemoryImage::Segment::size
size_t size
Definition: memory_image.hh:84
gem5::loader::MemoryImage
Definition: memory_image.hh:53
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:67
gem5::loader::MemoryImage::contains
bool contains(Addr addr) const
Definition: memory_image.hh:154
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::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::loader::MemoryImage::Segment::data
const uint8_t * data
Definition: memory_image.hh:83
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:203
gem5::ArmISA::m
Bitfield< 0 > m
Definition: misc_types.hh:394
gem5::loader::MemoryImage::addSegments
void addSegments(std::initializer_list< Segment > segs)
Definition: memory_image.hh:117
gem5::loader::MemoryImage::minAddr
Addr minAddr() const
Definition: memory_image.hh:145
types.hh
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
gem5::loader::MemoryImage::segments
const std::vector< Segment > & segments() const
Definition: memory_image.hh:105
gem5::loader::ImageFileDataPtr
std::shared_ptr< ImageFileData > ImageFileDataPtr
Definition: image_file_data.hh:61
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:89
gem5::loader::MemoryImage::write
bool write(const PortProxy &proxy) const
Definition: memory_image.cc:54
gem5::loader::MemoryImage::mask
MemoryImage & mask(Addr m)
Definition: memory_image.hh:131
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::loader::MemoryImage::writeSegment
bool writeSegment(const Segment &seg, const PortProxy &proxy) const
Definition: memory_image.cc:40
gem5::loader::MemoryImage::Segment::name
std::string name
Definition: memory_image.hh:81
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17