orca-sim
|
This class models a memory module. More...
#include <Memory.hpp>
Public Member Functions | |
Memory (std::string name, uint32_t size, uint32_t base=0, bool wipe=false, std::string binname="") | |
Construct a new Memory object. More... | |
~Memory () | |
Destroy the Memory object. More... | |
void | Write (uint32_t addr, MemoryType *data, uint32_t length) |
Writes data to the memory. More... | |
void | Read (uint32_t addr, MemoryType *buffer, uint32_t length) |
Reads data from a given memory location. More... | |
void | LoadBin (std::string filename, MemoryAddr base, uint32_t size) |
Loads the content of a given file to the memory. More... | |
void | SaveBin (std::string filename, MemoryAddr base, uint32_t size) |
Write the contents of memory cells into a binary file. More... | |
void | Wipe () |
Write zeroes to the whole addressable memory space. More... | |
void | Wipe (MemoryAddr base, uint32_t length) |
Write zeroes to a region of the memory. More... | |
void | Dump (uint32_t base, uint32_t length) |
Display the contents of the memory on the output. More... | |
void | Dump () |
Display the contents of the whole memory on the output. More... | |
MemoryType & | operator[] (MemoryAddr addr) |
Shorthand access for the Read method using operator overloading on '[]' operator. More... | |
MemoryAddr | GetBase () |
(getter) Gets the base address, which is the first addressable memory cell in the module. More... | |
MemoryAddr | GetSize () |
(getter) Gets the size (alternatively, length) of the memory module, representing the number of addressable cells. More... | |
MemoryAddr | GetLastAddr () |
Get the address of the last addressable memory cell. More... | |
MemoryType * | GetMap (MemoryAddr addr) |
Gets a pointer of MemoryType type that points to the cell in address <addr>. More... | |
a name that identifies the model, advisably not empty. | |
Default ctor. | |
std::string | GetName () |
Getter method for the <_name> field. More... | |
void | SetName (std::string s) |
Setter method for the <_name> field. More... | |
Private Attributes | |
MemoryType * | _mem |
The _mem attribute is an array of MemoryType elements, where MemoryType is the smalled memory unit that can be read or writen to the memory. More... | |
MemoryAddr | _length |
The _length attribute denotes the number of cells of the memory module. More... | |
MemoryAddr | _base |
The _base attribute indicates the first address of the memory module, an offset. More... | |
This class models a memory module.
The module has no clock as it is an UntimedModel *
Definition at line 55 of file Memory.hpp.
Memory::Memory | ( | std::string | name, |
uint32_t | size, | ||
uint32_t | base = 0 , |
||
bool | wipe = false , |
||
std::string | binname = "" |
||
) |
Construct a new Memory object.
name | A string name to identify the object. There is no restriction on object names. |
size | The number of cells to be emulated. The size of cell is defined by the MemoryType type. |
base | (optional) The base address for the emulated memory space. Default value is zero. |
wipe | (optional) If set to true, erase memory cells after class instantiation, writing zero to each cell. Default behavior |
binname | (optional) |
Definition at line 36 of file Memory.cpp.
Memory::~Memory | ( | ) |
Destroy the Memory object.
Definition at line 289 of file Memory.cpp.
void Memory::Dump | ( | uint32_t | base, |
uint32_t | length | ||
) |
Display the contents of the memory on the output.
Data will be displayed as hexadecimal values.
base | The first address to display |
length | The number of cells to display |
Definition at line 259 of file Memory.cpp.
void Memory::Dump | ( | ) |
Display the contents of the whole memory on the output.
Definition at line 255 of file Memory.cpp.
MemoryAddr Memory::GetBase | ( | ) |
(getter) Gets the base address, which is the first addressable memory cell in the module.
Definition at line 173 of file Memory.cpp.
MemoryAddr Memory::GetLastAddr | ( | ) |
Get the address of the last addressable memory cell.
The address is given by (base + length - 1).
Definition at line 183 of file Memory.cpp.
MemoryType * Memory::GetMap | ( | MemoryAddr | addr | ) |
Gets a pointer of MemoryType type that points to the cell in address <addr>.
Although the pointer points to a single cell, neighbor cells can be accessed by incrementing on the pointer. Please note that this method bypassed the encapsuling methods Write and Read, and its use should be avoided for data manipulation purpose.
addr | The addres to which the pointer must point to. |
Definition at line 144 of file Memory.cpp.
|
inherited |
uint32_t Memory::GetSize | ( | ) |
(getter) Gets the size (alternatively, length) of the memory module, representing the number of addressable cells.
Definition at line 178 of file Memory.cpp.
void Memory::LoadBin | ( | std::string | filename, |
MemoryAddr | base, | ||
uint32_t | size | ||
) |
Loads the content of a given file to the memory.
File contents are treated as binaray data.
filename | Name of the file to be read. |
location | Location of the memory area in which the contents of the loaded file will be put. |
Definition at line 222 of file Memory.cpp.
|
inline |
Shorthand access for the Read method using operator overloading on '[]' operator.
On contrary of Read method, this operator is capable of returning only a single memory cell value. Please note that its counter for writing is not implemented.
addr | The address of the cell to read from |
Definition at line 192 of file Memory.hpp.
void Memory::Read | ( | uint32_t | addr, |
MemoryType * | buffer, | ||
uint32_t | length | ||
) |
Reads data from a given memory location.
addr | Location to read from. |
buffer | Buffer to where the read data will be copied. |
length | Length of the data that will be copyied from memory to the buffer. |
Definition at line 111 of file Memory.cpp.
void Memory::SaveBin | ( | std::string | filename, |
MemoryAddr | base, | ||
uint32_t | size | ||
) |
Write the contents of memory cells into a binary file.
filename | file name, overwrites file is it exists already |
size | number of memory cells to save |
addr | address of the first cell to save |
Definition at line 240 of file Memory.cpp.
|
inherited |
void Memory::Wipe | ( | ) |
Write zeroes to the whole addressable memory space.
Definition at line 189 of file Memory.cpp.
void Memory::Wipe | ( | MemoryAddr | base, |
uint32_t | length | ||
) |
Write zeroes to a region of the memory.
base | The starting address, will be the first address to be writen |
length | Number of cells to write zeroes to. Cells will follow the position of the base cell. |
Definition at line 193 of file Memory.cpp.
void Memory::Write | ( | uint32_t | addr, |
MemoryType * | data, | ||
uint32_t | length | ||
) |
Writes data to the memory.
addr | Address of the first cell to receive the data. If data is largen than a single cell, neighbor cells will be writen. |
data | A pointers of MemoryType that indicates the beggining of data to be copied. |
length | Number of cells to write |
Definition at line 75 of file Memory.cpp.
|
private |
The _base attribute indicates the first address of the memory module, an offset.
Since this model can only address contiguous cells, one may use multiple memory models to emulate a non-contiguous space.
Definition at line 80 of file Memory.hpp.
|
private |
The _length attribute denotes the number of cells of the memory module.
The total number of memory space is given by sizeof(MemoryType) * _length (in bytes).
Definition at line 71 of file Memory.hpp.
|
private |
The _mem attribute is an array of MemoryType elements, where MemoryType is the smalled memory unit that can be read or writen to the memory.
Definition at line 63 of file Memory.hpp.