The Sparta Modeling Framework
|
Memory mapping object which maps addresses onto block-aligned destinations, each of which is a BlockingMemoryIF object. This method does not actually support memory accesses, only mapping and querying. More...
#include <SimpleMemoryMap.hpp>
Classes | |
struct | Mapping |
Represents a mapping between an input address and output address for use in a destination BlockingMemoryIF. More... | |
Public Member Functions | |
std::string | stringize (bool pretty=false) const |
Render description of this SimpleMemoryMap as a string. | |
Construction | |
SimpleMemoryMap (addr_t block_size) | |
Construct a SimpleMemoryMap. | |
virtual | ~SimpleMemoryMap () |
Destructor. | |
Mapping Interface | |
void | addMapping (addr_t start, addr_t end, BlockingMemoryIF *memif, addr_t dest_start) |
Create a mapping from addresses entering this object to a destination memory interface. | |
void | dumpTree (std::ostream &o) const |
Dumps the tree to an ostream like a directory listing. | |
void | dumpMappings (std::ostream &o) const |
Dumps a list of mappings to an ostream with a newline after each mapping entry. | |
BlockingMemoryIF * | findInterface (addr_t addr) |
Returns the destination memory interface associated with a mapping containing an address. | |
Mapping * | findMapping (addr_t addr) |
Finds the Mapping object associated with an address. | |
const Mapping * | findMapping (addr_t addr) const |
void | verifyHasMapping (addr_t addr, addr_t size) const |
Determines if a mapping is valid or not. | |
std::pair< const BlockingMemoryIF *, addr_t > | mapAddress (addr_t addr) const noexcept |
Maps an input address to a destination interface and address within that destination interface. | |
uint32_t | getNumMappings () const |
Returns the number of mappings successfully added to this map. | |
const std::vector< const Mapping * > & | getMappings () const |
Returns the vector of current mappings in the order added. | |
Attributes | |
addr_t | getBlockSize () const |
Returns the block size of memory represented by this interface. Read and write accesses must not span block boundaries (where addr % block_size == 0). | |
Memory mapping object which maps addresses onto block-aligned destinations, each of which is a BlockingMemoryIF object. This method does not actually support memory accesses, only mapping and querying.
Mapping is performed within this map and is invisible to clients of this class. Internal mapping is not considered a translation and there is no TranslationIF associated with the internals mapping of this class.
Mapped ranges can be added only (not removed), cannot overlap, can, however, map to overlapping ranges on the same destination memory.
All mappings are Affine and contiguous. For mapping multiple regions to the same object or mapping one range to discontinuous or overlapping ranges in a destination memory object, use separate mappings.
Implemented as a red-black tree to balance the tree and make lookups more consistently log(n).
Example
Definition at line 53 of file SimpleMemoryMap.hpp.
|
inline |
Construct a SimpleMemoryMap.
block_size | Size of blocks in mapping. Must match or be smaller than all BlockingMemoryIF instances to which this object will maps. Must be a power of 2 and greater than 0 |
Definition at line 149 of file SimpleMemoryMap.hpp.
|
inlinevirtual |
Destructor.
Definition at line 162 of file SimpleMemoryMap.hpp.
|
inline |
Create a mapping from addresses entering this object to a destination memory interface.
start | Start address of mapping region. Must be block-aligned |
end | End address (exclusive) of mapping region. Must be block-aligned. Must be > start (mapping must be 1 or more bytes). The range defined by [start,end) cannot overlap any other mapping range already added to this object. Edges may be shared though (e.g. range 1 end can equal range 2 start). |
memif | Memory interface to which accesses in the range defined by [start,end) will be forwarded with the new address of: address - start + dest_start. The block size (BlockingMemoryIF::getBlockSize) of this interface must be exactly the size of this SimpleMemoryMap block size. Requiring the block size to be equal means that no legal accesses can be made through this interface which span blocks in destination memory interfaces. This allows this class to avoid testing for mapping-spanning accesses because the destination interfaces are expected to reject them. If a destination BlockingMemoryIF were to violate this assumption, an access could be made through this map which spanned blocks and thus spanned mapping ranges - this would be undesirable behavior. |
dest_start | Added address offset at destination. Must be a multiple of block_size - effectively limits granulariry of any mapping to whole-block-to-whole-block. If dest_start were 0, accesses with an address equal to start to be forwarded to memif with an address of 0. Accesses with address = start+4 would be forwarded with an address of 4. dest_start allows this to be adjusted by adding an offset to the destination address. |
Definition at line 222 of file SimpleMemoryMap.hpp.
|
inline |
Dumps a list of mappings to an ostream with a newline after each mapping entry.
o | ostream to which mappings will be printed |
Definition at line 443 of file SimpleMemoryMap.hpp.
|
inline |
Dumps the tree to an ostream like a directory listing.
o | ostream to which tree will be printed |
Definition at line 432 of file SimpleMemoryMap.hpp.
|
inline |
Returns the destination memory interface associated with a mapping containing an address.
Definition at line 479 of file SimpleMemoryMap.hpp.
Finds the Mapping object associated with an address.
Definition at line 492 of file SimpleMemoryMap.hpp.
const-qualified version of findMapping
Definition at line 524 of file SimpleMemoryMap.hpp.
|
inline |
Returns the block size of memory represented by this interface. Read and write accesses must not span block boundaries (where addr % block_size == 0).
Definition at line 644 of file SimpleMemoryMap.hpp.
|
inline |
Returns the vector of current mappings in the order added.
Definition at line 628 of file SimpleMemoryMap.hpp.
|
inline |
Returns the number of mappings successfully added to this map.
Definition at line 621 of file SimpleMemoryMap.hpp.
|
inlinenoexcept |
Maps an input address to a destination interface and address within that destination interface.
add | Input address to map |
Example:
Definition at line 609 of file SimpleMemoryMap.hpp.
|
inline |
Render description of this SimpleMemoryMap as a string.
Definition at line 652 of file SimpleMemoryMap.hpp.
Determines if a mapping is valid or not.
MemoryAccessError | if mapping is not valid |
Note that normal read/write paths may not perform a check this careful for performance reasons
Definition at line 559 of file SimpleMemoryMap.hpp.