46 if (wipe) this->
Wipe();
52 #ifdef MEMORY_ENABLE_COUNTERS 59 _counter_nstore->
Write(0);
60 _counter_nload->
Write(0);
64 #ifdef MEMORY_ENABLE_COUNTERS 67 return _counter_nstore;
71 return _counter_nload;
76 #ifdef MEMORY_WRITE_ADDRESS_CHECKING 79 if (addr < _sram_base) {
81 s << this->
GetName() <<
": unable to write to addr (0x" << std::hex
82 << addr <<
") lower than sram base.";
84 throw std::runtime_error(s.str());
91 s << this->
GetName() <<
": unable to write to addr (0x" << std::hex
92 << addr <<
") higher than last mapped address of (0x" << std::hex
94 throw std::runtime_error(s.str());
98 #ifdef MEMORY_ENABLE_COUNTERS 100 _counter_nstore->Inc(1);
105 for (uint32_t i = 0; i < length; i++) {
112 #ifdef MEMORY_READ_ADDRESS_CHECKING 115 if (addr < _sram_base) {
117 s << this->
GetName() <<
": unable to read from addr (0x" << std::hex
118 << addr <<
") lower than sram base.";
119 throw std::runtime_error(s.str());
126 s << this->
GetName() <<
": unable to read from addr (0x" << std::hex
127 << addr <<
") higher than last mapped address of (0x" << std::hex
129 throw std::runtime_error(s.str());
135 for (uint32_t i = 0; i < length; i++)
138 #ifdef MEMORY_ENABLE_COUNTERS 140 _counter_nload->Inc(1);
145 #ifdef MEMORY_MAP_ADDRESS_CHECKING 149 if (addr < _sram_base) {
151 s << this->
GetName() <<
": unable to map from to addr (0x" << std::hex
152 << addr <<
") lower than sram base.";
153 throw std::runtime_error(s.str());
161 s << this->
GetName() <<
": unable to map from to addr (0x" << std::hex
162 << addr <<
") higher than last mapped address of (0x" << std::hex
164 throw std::runtime_error(s.str());
194 #ifdef MEMORY_WRITE_ADDRESS_CHECKING 197 throw std::runtime_error(this->
GetName() +
198 ": unable to wipe from base (" + std::to_string(base) +
199 ") lower than sram base .");
203 throw std::runtime_error(this->
GetName() +
204 ": unable to wipe from base (" + std::to_string(base) +
205 ") higher than sram base .");
209 throw std::runtime_error(this->
GetName() +
210 ": unable to wipe that much length (" + std::to_string(size) +
211 ") higher than sram base + length.");
218 for (uint32_t i = 0; i < size; i++)
224 std::ifstream f(filename, std::ios::binary | std::ios::in | std::ios::out);
228 f.read(reinterpret_cast<char*>(&
_mem[base -
_base]),
229 sizeof(
_mem[0]) * size);
234 std::string err_msg = this->
GetName() +
": unable to load '" 236 throw std::runtime_error(err_msg);
241 std::ofstream f(filename, std::ifstream::binary);
244 f.write(reinterpret_cast<char*>(&
_mem[base -
_base]),
245 sizeof(
_mem[0]) * size);
248 std::string err_msg = this->
GetName() +
249 ": unable to save'" + filename +
"'.";
250 throw std::runtime_error(err_msg);
264 uint32_t mask = 0x000000FF;
268 for (k = 0; k < length; k += 16) {
270 printf(
"\n%08x ", base + k);
271 for (l = 0; l < 16; l++) {
272 printf(
"%02x ",
_mem[k + l + (base -
_base)] & mask);
273 if (l == 7) putchar(
' ');
278 for (l = 0; l < 16; l++) {
280 if ((ch >= 32) && (ch <= 126))
293 #ifdef MEMORY_ENABLE_COUNTERS 295 delete(_counter_nstore);
296 delete(_counter_nload);
MemoryType * GetMap(MemoryAddr addr)
Gets a pointer of MemoryType type that points to the cell in address <addr>.
void Write(uint32_t addr, MemoryType *data, uint32_t length)
Writes data to the memory.
MemoryAddr _length
The _length attribute denotes the number of cells of the memory module.
MemoryType * _mem
The _mem attribute is an array of MemoryType elements, where MemoryType is the smalled memory unit th...
void Wipe()
Write zeroes to the whole addressable memory space.
void Dump()
Display the contents of the whole memory on the output.
void SaveBin(std::string filename, MemoryAddr base, uint32_t size)
Write the contents of memory cells into a binary file.
void LoadBin(std::string filename, MemoryAddr base, uint32_t size)
Loads the content of a given file to the memory.
void Write(T val)
Writes some value to the bus.
MemoryAddr GetLastAddr()
Get the address of the last addressable memory cell.
MemoryAddr _base
The _base attribute indicates the first address of the memory module, an offset.
std::string GetName()
Getter method for the <_name> field.
MemoryAddr GetBase()
(getter) Gets the base address, which is the first addressable memory cell in the module...
void Read(uint32_t addr, MemoryType *buffer, uint32_t length)
Reads data from a given memory location.
Untimed models represent hardware models whose clock period is irrelevant for the simulation...
This class models a memory module.
~Memory()
Destroy the Memory object.
MemoryAddr GetSize()
(getter) Gets the size (alternatively, length) of the memory module, representing the number of addre...