The Sparta Modeling Framework
Loading...
Searching...
No Matches
SimpleMemoryMapNode.hpp
Go to the documentation of this file.
1
7#pragma once
8
11
12namespace sparta
13{
14 namespace memory
15 {
31 {
32 public:
33
35
39
40 SimpleMemoryMapNode() = delete;
41
59 const std::string& name,
60 const std::string& group,
61 group_idx_type group_idx,
62 const std::string& desc,
63 addr_t block_size,
64 addr_t total_size,
65 TranslationIF* transif=nullptr) :
66 BlockingMemoryIFNode(parent, name, group, group_idx, desc,
67 block_size,
68 DebugMemoryIF::AccessWindow(0, total_size),
69 transif),
70 SimpleMemoryMap(block_size)
71 { }
72
80 const std::string& name,
81 const std::string& desc,
82 addr_t block_size,
83 addr_t total_size,
84 TranslationIF* transif=nullptr) :
86 name,
89 desc,
90 block_size,
91 total_size,
92 transif)
93 { }
94
95 virtual ~SimpleMemoryMapNode() {}
96
99
103
118 void read(addr_t addr,
119 addr_t size,
120 uint8_t *buf,
121 const void *in_supplement=nullptr,
122 void *out_supplement=nullptr) {
123 if(!tryRead(addr, size, buf, in_supplement, out_supplement)){
124 verifyHasMapping(addr, size);
125 verifyNoBlockSpan(addr, size);
126 verifyInAccessWindows(addr, size);
127 throw MemoryReadError(addr, size, "Unknown reason");
128 }
129 }
130
146 void write(addr_t addr,
147 addr_t size,
148 const uint8_t *buf,
149 const void *in_supplement=nullptr,
150 void *out_supplement=nullptr) {
151 if(!tryWrite(addr, size, buf, in_supplement, out_supplement)){
152 verifyHasMapping(addr, size);
153 verifyNoBlockSpan(addr, size);
154 verifyInAccessWindows(addr, size);
155 throw MemoryReadError(addr, size, "Unkonwn reason");
156 }
157 }
158
161
165
180 DMIBlockingMemoryIF *getDMI(addr_t addr, addr_t size) override {
181 const Mapping * m = findMapping(addr);
182 if(!m) {
183 return nullptr;
184 }
185 return m->memif->getDMI(m->mapAddress(addr), size);
186 }
187
190
191 protected:
192
196
204 virtual bool tryRead_(addr_t addr,
205 addr_t size,
206 uint8_t *buf,
207 const void *in_supplement=nullptr,
208 void *out_supplement=nullptr) override {
209 const Mapping* m = findMapping(addr);
210 if(!m){
211 return false;
212 //throw MemoryReadError(addr, size, "Could not find mapping at this address");
213 }
214 return m->memif->tryRead(m->mapAddress(addr), size, buf, in_supplement, out_supplement);
215 }
216
224 virtual bool tryWrite_(addr_t addr,
225 addr_t size,
226 const uint8_t *buf,
227 const void *in_supplement=nullptr,
228 void *out_supplement=nullptr) override {
229 Mapping* m = findMapping(addr);
230 if(!m){
231 return false;
232 //throw MemoryWriteError(addr, size, "Could not find mapping at this address");
233 }
234 return m->memif->tryWrite(m->mapAddress(addr), size, buf, in_supplement, out_supplement);
235 }
236
242 virtual bool tryPeek_(addr_t addr,
243 addr_t size,
244 uint8_t *buf) const override {
245 // Note that input peeks are already split into blocks, so each
246 // may be translated once. Easy. Recall that peek has no
247 // performance requirement either.
248
249 const Mapping* m = findMapping(addr);
250 if(!m){
251 return false;
252 }
253 return m->memif->tryPeek(m->mapAddress(addr), size, buf);
254 }
255
261 virtual bool tryPoke_(addr_t addr,
262 addr_t size,
263 const uint8_t *buf) override {
264 // Note that input peeks are already split into blocks, so each
265 // may be translated once. Easy. Recall that peek has no
266 // performance requirement either.
267
268 Mapping* m = findMapping(addr);
269 if(!m){
270 return false;
271 }
272 return m->memif->tryPoke(m->mapAddress(addr), size, buf);
273 }
274
277
278 }; // class SimpleMemoryMapNode
279 } // namespace memory
280} // namespace sparta
File that contains BlockingMemoryIFNode.
File that contains SimpleMemoryMap.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
Definition TreeNode.hpp:303
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
Definition TreeNode.hpp:314
uint32_t group_idx_type
Index within a group.
Definition TreeNode.hpp:261
Pure-virtual memory interface that builds on the BlockingMemoryIF, acting as a TreeNode in the SPARTA...
virtual bool tryRead(addr_t addr, addr_t size, uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr) override
Attempt to read memory of size size at address addr.
virtual bool tryWrite(addr_t addr, addr_t size, const uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr) override
Attempt to write memory of size size at address addr.
virtual bool tryRead(addr_t addr, addr_t size, uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
Attempt to read memory of size size at address addr.
virtual DMIBlockingMemoryIF * getDMI(addr_t addr, addr_t size)
Get a DMI blocking interface to access the given address/size.
virtual bool tryWrite(addr_t addr, addr_t size, const uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
Attempt to write memory of size size at address addr.
Class that provides a BlockingMemoryIF over a raw pointer.
Memory interface which represents a simple, immediately accessible (blocking) address-space with supp...
bool tryPeek(addr_t addr, addr_t size, uint8_t *buf) const
Attempts to 'peek' memory without having any side effects, size-limitations, alignment constraints ex...
void verifyNoBlockSpan(addr_t addr, addr_t size) const
Verifies that the given address does not span block boundaries defined for this interface.
void verifyInAccessWindows(addr_t addr, addr_t size) const
Verifies that the range [addr, addr+size) is within the access windows for this interface.
bool tryPoke(addr_t addr, addr_t size, const uint8_t *buf)
Attempts to 'poke' memory without having any side effects other than changing the bytes within the ra...
addr_t getBlockSize() const
Returns the block size of memory represented by this interface. Read and write accesses must not span...
Error while attempting to read some memory object or interface.
Memory mapping object which implements BlockingMemoryIFNode. Supports a simple mapping of incoming ad...
virtual bool tryWrite_(addr_t addr, addr_t size, const uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr) override
Implements tryWrite_.
SimpleMemoryMapNode(sparta::TreeNode *parent, const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, addr_t block_size, addr_t total_size, TranslationIF *transif=nullptr)
Construct a SimpleMemoryMap that is also a BlockingMemoryIFNode subclass.
DMIBlockingMemoryIF * getDMI(addr_t addr, addr_t size) override
Get a DMI blocking interface at the given address and size.
virtual bool tryPoke_(addr_t addr, addr_t size, const uint8_t *buf) override
Implements tryPoke_.
void write(addr_t addr, addr_t size, const uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
Write a block of memory.
virtual bool tryPeek_(addr_t addr, addr_t size, uint8_t *buf) const override
Implements tryPeek_.
virtual bool tryRead_(addr_t addr, addr_t size, uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr) override
Implements tryRead_.
SimpleMemoryMapNode(sparta::TreeNode *parent, const std::string &name, const std::string &desc, addr_t block_size, addr_t total_size, TranslationIF *transif=nullptr)
Constructor for SimpleMemoryMapNode without TreeNode group information.
void read(addr_t addr, addr_t size, uint8_t *buf, const void *in_supplement=nullptr, void *out_supplement=nullptr)
Read a block of memory.
Memory mapping object which maps addresses onto block-aligned destinations, each of which is a Blocki...
void verifyHasMapping(addr_t addr, addr_t size) const
Determines if a mapping is valid or not.
Mapping * findMapping(addr_t addr)
Finds the Mapping object associated with an address.
Blocking translation interface with 1:1 translation unless subclassed.
uint64_t addr_t
Type for generic address representation in generic interfaces, errors and printouts within SPARTA.
Macros for handling exponential backoff.
Defines an access window within this interface. Accesses through a memory interface are constrained t...
Represents a mapping between an input address and output address for use in a destination BlockingMem...
addr_t mapAddress(addr_t input) const noexcept
Maps an input address to the address-space for the destination memory interface.
BlockingMemoryIF *const memif
Memory interface mapped to (after add/sub are applied to address)