14#include "sparta/memory/TranslationIF.hpp"
15#include "sparta/memory/AddressTypes.hpp"
16#include "sparta/utils/StringManager.hpp"
17#include "sparta/utils/Utils.hpp"
100 const std::string& _name=
"default") :
105 <<
name <<
"\" where start address (0x"
106 << std::hex <<
start <<
") >= end address (0x" <<
end <<
")";
183 <<
block_size_ <<
") specified is not a power of 2 for DebugMemoryIF: "
195 throw SpartaException(
"0 access windows specified for DebugMemoryIF: ")
206 if(win.start % block_size != 0){
207 throw SpartaException(
"Memory AccessWindow start address was not block-size (")
208 << block_size <<
") aligned. Was " << std::hex << win.start;
210 if(win.end % block_size != 0){
211 throw SpartaException(
"Memory AccessWindow end address was not block-size (")
212 << block_size <<
") aligned. Was " << std::hex << win.end;
328 if(win.containsAddr(addr)){
348 MemoryAccessError ex(addr, size,
"any",
"The access at does not fit within access windows: ");
434 uint8_t *buf)
const {
441 const addr_t end = addr + size;
444 if(block_end >= end){
445 return tryPeek_(a, end - a, out);
448 addr_t size_in_block = block_end - a;
449 if(!tryPeek_(a, size_in_block, out)){
452 out += size_in_block;
463 uint8_t *buf)
const {
504 const uint8_t *buf) {
509 const uint8_t* in = buf;
511 const addr_t end = addr + size;
514 if(block_end >= end){
515 return tryPoke_(a, end - a, in);
518 addr_t size_in_block = block_end - a;
519 if(!tryPoke_(a, size_in_block, in)){
533 const uint8_t *buf) {
614 virtual bool tryPeek_(
addr_t addr,
616 uint8_t *buf)
const = 0;
631 virtual bool tryPoke_(
addr_t addr,
633 const uint8_t *buf) = 0;
File that contains some exception types related to memory interfaces.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
static StringManager & getStringManager()
Returns the StringManager singleton.
Memory interface which represents a simple, immediately accessible (blocking) address-space with supp...
virtual ~DebugMemoryIF()
Virutal destructor.
addr_t high_end_
Highest accessible address + 1.
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...
DebugMemoryIF(const std::string &desc, addr_t block_size, const AccessWindow &window, TranslationIF *transif=nullptr)
Construct a DebugMemoryInterface.
const std::string & getDescription()
Returns the description specified at construction.
virtual const TranslationIF * getTranslationIF()
Gets the translation interface associated with this Debug memory interface (if any).
bool doesAccessSpan(addr_t addr, addr_t size) const noexcept
Determines if the given address spans block boundaries defined for this interface....
bool isInAccessWindows(addr_t addr, addr_t size) const
Determines if the range [addr, addr+size) is within the access windows for this interface.
addr_t getAccessibleSize() const
Gets the total accessible size of this interface's valid addresses within the total size (getRange) e...
addr_t accessible_size_
Number of bytes accessible through this interface.
addr_t getHighEnd() const
Gets the highest address accessible + 1.
addr_t total_range_
Range of addresses from highest accessible to lowest.
const addr_t block_size_
Size of a block accessed through this interface.
addr_t block_mask_
Mask applied to an address to get only bits representing the block ID.
addr_t getLowEnd() const
Gets the lowest address accessible.
addr_t getRange() const
Gets the total span of this interface's valid address range.
TranslationIF * trans_
Translation interface created for this interface. Externally owned.
bool isAddressInWindows(addr_t addr) const noexcept
Determines if the given address is in an access window defined for this interface.
void poke(addr_t addr, addr_t size, const uint8_t *buf)
Wrapper on tryPoke which throws a MemoryAccessError if the poke is not legal.
addr_t block_idx_lsb_
rshift applied to an address to get the block ID
void verifyNoBlockSpan(addr_t addr, addr_t size) const
Verifies that the given address does not span block boundaries defined for this interface.
const std::string *const desc_ptr_
Description pointer.
const std::vector< AccessWindow > & getWindows() const
Gets the vector of windows representing 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.
DebugMemoryIF()=delete
Default constuctor.
addr_t low_end_
Lowest accessible address.
const std::vector< AccessWindow > acc_windows_
Vector of access windows representing this memory.
void peek(addr_t addr, addr_t size, uint8_t *buf) const
Wrapper on tryPeek which throws a MemoryAccessError if the peek is not legal.
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...
Indicates that there was an issue accessing a SPARTA memory object or interface.
Error while attempting to peek some memory object or interface.
Error while attempting to poke some memory object or interface.
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.
bool isPowerOf2(uint64_t x)
Determines if input is 0 or a power of 2.
Defines an access window within this interface. Accesses through a memory interface are constrained t...
AccessWindow(const AccessWindow &)=default
Default copy constructor.
bool containsAddr(addr_t addr) const noexcept
Does this window interval contain the specified post-translated address addr.
const addr_t start
inclusive start address (block-aligned)
const addr_t end
exclusive end address (block-aligned)
const std::string name
What is this window called (for printouts)
AccessWindow(addr_t _start, addr_t _end, const std::string &_name="default")
Construct address window with range.