summaryrefslogtreecommitdiff
path: root/tb/mem.hpp
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-10-16 16:01:47 -0600
committerAlejandro Soto <alejandro@34project.org>2022-10-16 16:01:47 -0600
commit3aca2967a35d05dac3d9121a882d608b10a588bb (patch)
tree25a8d37d6213f518b9ff95ef8b4de30a337a1b2d /tb/mem.hpp
parent2e6ce7931b690ccec1e41fa6847dfc1351c59d75 (diff)
Implement simulation testbenches
Diffstat (limited to '')
-rw-r--r--tb/mem.hpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/tb/mem.hpp b/tb/mem.hpp
index 78c4818..016fdc0 100644
--- a/tb/mem.hpp
+++ b/tb/mem.hpp
@@ -24,13 +24,35 @@ namespace taller::avalon
}
virtual bool read(std::uint32_t addr, std::uint32_t &data) final override;
- virtual bool write(std::uint32_t addr, std::uint32_t data, unsigned byte_enable = 0b1111) final override;
+ virtual bool write
+ (
+ std::uint32_t addr, std::uint32_t data, unsigned byte_enable = 0b1111
+ ) final override;
+
+ template<typename F>
+ void load(F loader, std::size_t addr = 0);
private:
std::unique_ptr<std::uint32_t[]> block;
std::uint32_t base;
std::uint32_t mask;
};
+
+ template<typename F>
+ void mem::load(F loader, std::size_t addr)
+ {
+ std::size_t size = mask + 1;
+ while(addr < size)
+ {
+ std::size_t read = loader(&block[base + addr], size - addr);
+ if(read == 0)
+ {
+ break;
+ }
+
+ addr += read;
+ }
+ }
}
#endif