Skip to content

Commit 58384aa

Browse files
committed
adds a memory for each space to memory_with_htif
1 parent 6b75a4d commit 58384aa

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/iss/mem/memory_with_htif.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
#define _MEMORY_WITH_HTIF_
3737

3838
#include "iss/arch/riscv_hart_common.h"
39+
#include "iss/arch/traits.h"
3940
#include "iss/vm_types.h"
4041
#include "memory_if.h"
42+
#include <array>
4143
#include <cstdlib>
4244
#include <util/logging.h>
4345
#include <util/sparse_array.h>
@@ -67,6 +69,7 @@ template <typename PLAT> struct memory_with_htif : public memory_elem {
6769
// for(auto offs = 0U; offs < length; ++offs) {
6870
// *(data + offs) = mem[(addr + offs) % mem.size()];
6971
// }
72+
mem_type mem = memories[space];
7073
if(mem.is_allocated(addr)) {
7174
const auto& p = mem(addr / mem.page_size);
7275
auto offs = addr & mem.page_addr_mask;
@@ -87,6 +90,7 @@ template <typename PLAT> struct memory_with_htif : public memory_elem {
8790
}
8891

8992
iss::status write_mem(iss::access_type access, uint32_t space, uint64_t addr, unsigned length, uint8_t const* data) {
93+
mem_type mem = memories[space];
9094
auto& p = mem(addr / mem.page_size);
9195
auto offs = addr & mem.page_addr_mask;
9296
if((offs + length) > mem.page_size) {
@@ -106,8 +110,11 @@ template <typename PLAT> struct memory_with_htif : public memory_elem {
106110
}
107111

108112
protected:
109-
using mem_type = util::sparse_array<uint8_t, 1ULL << 32>;
110-
mem_type mem;
113+
// Currently no type erasure for the sparse_array is available, so all memories
114+
// have the largest possible size. Memory footprint should still be small as it
115+
// a sparse array
116+
using mem_type = util::sparse_array<uint8_t, arch::traits<PLAT>::max_mem_size>;
117+
std::array<mem_type, arch::traits<PLAT>::mem_sizes.size()> memories;
111118
arch::priv_if<reg_t> hart_if;
112119
};
113120
} // namespace mem

0 commit comments

Comments
 (0)