diff options
Diffstat (limited to 'riscv/devices.h')
-rw-r--r-- | riscv/devices.h | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/riscv/devices.h b/riscv/devices.h index 82aab89..2003d17 100644 --- a/riscv/devices.h +++ b/riscv/devices.h @@ -7,7 +7,6 @@ #include <string> #include <map> #include <vector> -#include <stdexcept> #include <utility> class processor_t; @@ -43,26 +42,20 @@ class rom_device_t : public abstract_device_t { class mem_t : public abstract_device_t { public: - mem_t(size_t size) : len(size) { - if (!size) - throw std::runtime_error("zero bytes of target memory requested"); - data = nullptr; - } + mem_t(reg_t size); mem_t(const mem_t& that) = delete; - ~mem_t() { - free(data); - } + ~mem_t(); - bool load(reg_t addr, size_t len, uint8_t* bytes) { return false; } - bool store(reg_t addr, size_t len, const uint8_t* bytes) { return false; } - char* contents(); + bool load(reg_t addr, size_t len, uint8_t* bytes) { return load_store(addr, len, bytes, false); } + bool store(reg_t addr, size_t len, const uint8_t* bytes) { return load_store(addr, len, const_cast<uint8_t*>(bytes), true); } char* contents(reg_t addr); - size_t size() { return len; } + reg_t size() { return sz; } private: - std::map<reg_t, std::pair<char*, bool>> acc_tbl; - char* data; - size_t len; + bool load_store(reg_t addr, size_t len, uint8_t* bytes, bool store); + + std::map<reg_t, char*> sparse_memory_map; + reg_t sz; }; class clint_t : public abstract_device_t { |