orca-sim
Memory.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 #ifndef ORCASIM_MODELING_INCLUDE_MEMORY_HPP_
27 #define ORCASIM_MODELING_INCLUDE_MEMORY_HPP_
28 
29 // std API
30 #include <iostream>
31 #include <fstream>
32 #include <cstdlib>
33 #include <cstdint>
34 #include <string>
35 
36 // simulation API
37 #include "UntimedModel.hpp"
38 
39 // memory types
40 #include "MemoryType.hpp"
41 
42 // counter-specific definitions
43 #ifdef MEMORY_ENABLE_COUNTERS
44 #include "Signal.hpp"
45 #endif
46 
48 
49 namespace orcasim::modeling {
50 
55 class Memory: public UntimedModel {
56  private:
64 
72 
81 
82  #ifdef MEMORY_ENABLE_COUNTERS
83 
88  Signal<uint32_t>* _counter_nload;
89  #endif
90 
91  #ifdef MEMORY_ENABLE_COUNTERS
92 
97  Signal<uint32_t>* _counter_nstore;
98  #endif
99 
100  public:
113  Memory(std::string name, uint32_t size, uint32_t base = 0,
114  bool wipe = false, std::string binname = "");
115 
119  ~Memory();
120 
129  void Write(uint32_t addr, MemoryType* data, uint32_t length);
130 
138  void Read(uint32_t addr, MemoryType* buffer, uint32_t length);
139 
147  void LoadBin(std::string filename, MemoryAddr base, uint32_t size);
148 
155  void SaveBin(std::string filename, MemoryAddr base, uint32_t size);
156 
160  void Wipe();
161 
169  void Wipe(MemoryAddr base, uint32_t length);
170 
177  void Dump(uint32_t base, uint32_t length);
178 
182  void Dump();
183 
193  return _mem[_base + addr];
194  }
195 
202 
209 
216 
228 
229  #ifdef MEMORY_ENABLE_COUNTERS
230 
235  Signal<uint32_t>* GetSignalCounterLoad();
236  #endif
237 
238  #ifdef MEMORY_ENABLE_COUNTERS
239 
244  Signal<uint32_t>* GetSignalCounterStore();
245  #endif
246 };
247 
248 } // namespace orcasim::modeling
249 #endif // ORCASIM_MODELING_INCLUDE_MEMORY_HPP_
MemoryType * GetMap(MemoryAddr addr)
Gets a pointer of MemoryType type that points to the cell in address <addr>.
Definition: Memory.cpp:144
void Write(uint32_t addr, MemoryType *data, uint32_t length)
Writes data to the memory.
Definition: Memory.cpp:75
MemoryAddr _length
The _length attribute denotes the number of cells of the memory module.
Definition: Memory.hpp:71
MemoryType & operator[](MemoryAddr addr)
Shorthand access for the Read method using operator overloading on &#39;[]&#39; operator. ...
Definition: Memory.hpp:192
MemoryType * _mem
The _mem attribute is an array of MemoryType elements, where MemoryType is the smalled memory unit th...
Definition: Memory.hpp:63
void Wipe()
Write zeroes to the whole addressable memory space.
Definition: Memory.cpp:189
#define MemoryAddr
Definition: MemoryType.hpp:34
void Dump()
Display the contents of the whole memory on the output.
Definition: Memory.cpp:255
Memory(std::string name, uint32_t size, uint32_t base=0, bool wipe=false, std::string binname="")
Construct a new Memory object.
Definition: Memory.cpp:36
void SaveBin(std::string filename, MemoryAddr base, uint32_t size)
Write the contents of memory cells into a binary file.
Definition: Memory.cpp:240
void LoadBin(std::string filename, MemoryAddr base, uint32_t size)
Loads the content of a given file to the memory.
Definition: Memory.cpp:222
MemoryAddr GetLastAddr()
Get the address of the last addressable memory cell.
Definition: Memory.cpp:183
MemoryAddr _base
The _base attribute indicates the first address of the memory module, an offset.
Definition: Memory.hpp:80
MemoryAddr GetBase()
(getter) Gets the base address, which is the first addressable memory cell in the module...
Definition: Memory.cpp:173
void Read(uint32_t addr, MemoryType *buffer, uint32_t length)
Reads data from a given memory location.
Definition: Memory.cpp:111
Untimed models represent hardware models whose clock period is irrelevant for the simulation...
This class models a memory module.
Definition: Memory.hpp:55
~Memory()
Destroy the Memory object.
Definition: Memory.cpp:289
MemoryAddr GetSize()
(getter) Gets the size (alternatively, length) of the memory module, representing the number of addre...
Definition: Memory.cpp:178
#define MemoryType
Definition: MemoryType.hpp:33