diff options
author | Jerry Zhao <jerryz123@berkeley.edu> | 2023-07-20 10:38:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-20 10:38:56 -0700 |
commit | 1b41ed3c48b5425b6d35a54043ae422789fca473 (patch) | |
tree | fedfed3cd7fb31e1e1b24f292c31b2ffa1d0842d /riscv | |
parent | 432c9ee97613ec73bbb10591f0cef9c1c93b4284 (diff) | |
parent | cb013516665addb45dadd197028762fd3757bdb0 (diff) | |
download | riscv-isa-sim-1b41ed3c48b5425b6d35a54043ae422789fca473.zip riscv-isa-sim-1b41ed3c48b5425b6d35a54043ae422789fca473.tar.gz riscv-isa-sim-1b41ed3c48b5425b6d35a54043ae422789fca473.tar.bz2 |
Merge pull request #1415 from michalt/memt-virtual
Make methods of `mem_t` virtual to allow overriding
Diffstat (limited to 'riscv')
-rw-r--r-- | riscv/devices.h | 19 | ||||
-rw-r--r-- | riscv/dts.cc | 2 | ||||
-rw-r--r-- | riscv/dts.h | 2 | ||||
-rw-r--r-- | riscv/sim.cc | 4 | ||||
-rw-r--r-- | riscv/sim.h | 4 |
5 files changed, 20 insertions, 11 deletions
diff --git a/riscv/devices.h b/riscv/devices.h index b752a21..6ef32e9 100644 --- a/riscv/devices.h +++ b/riscv/devices.h @@ -36,17 +36,26 @@ class rom_device_t : public abstract_device_t { std::vector<char> data; }; -class mem_t : public abstract_device_t { +class abstract_mem_t : public abstract_device_t { + public: + virtual ~abstract_mem_t() = default; + + virtual char* contents(reg_t addr) = 0; + virtual reg_t size() = 0; + virtual void dump(std::ostream& o) = 0; +}; + +class mem_t : public abstract_mem_t { public: mem_t(reg_t size); mem_t(const mem_t& that) = delete; - ~mem_t(); + ~mem_t() override; bool load(reg_t addr, size_t len, uint8_t* bytes) override { return load_store(addr, len, bytes, false); } bool store(reg_t addr, size_t len, const uint8_t* bytes) override { return load_store(addr, len, const_cast<uint8_t*>(bytes), true); } - char* contents(reg_t addr); - reg_t size() { return sz; } - void dump(std::ostream& o); + char* contents(reg_t addr) override; + reg_t size() override { return sz; } + void dump(std::ostream& o) override; private: bool load_store(reg_t addr, size_t len, uint8_t* bytes, bool store); diff --git a/riscv/dts.cc b/riscv/dts.cc index cc65e3c..9f73bac 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -17,7 +17,7 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, const char* bootargs, size_t pmpregions, std::vector<processor_t*> procs, - std::vector<std::pair<reg_t, mem_t*>> mems, + std::vector<std::pair<reg_t, abstract_mem_t*>> mems, std::string device_nodes) { std::stringstream s; diff --git a/riscv/dts.h b/riscv/dts.h index 7ec1ceb..9240124 100644 --- a/riscv/dts.h +++ b/riscv/dts.h @@ -11,7 +11,7 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, const char* bootargs, size_t pmpregions, std::vector<processor_t*> procs, - std::vector<std::pair<reg_t, mem_t*>> mems, + std::vector<std::pair<reg_t, abstract_mem_t*>> mems, std::string device_nodes); std::string dts_compile(const std::string& dts); diff --git a/riscv/sim.cc b/riscv/sim.cc index c60d30b..fc75a37 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -37,7 +37,7 @@ extern device_factory_t* plic_factory; extern device_factory_t* ns16550_factory; sim_t::sim_t(const cfg_t *cfg, bool halted, - std::vector<std::pair<reg_t, mem_t*>> mems, + std::vector<std::pair<reg_t, abstract_mem_t*>> mems, std::vector<const device_factory_t*> plugin_device_factories, const std::vector<std::string>& args, const debug_module_config_t &dm_config, @@ -380,7 +380,7 @@ char* sim_t::addr_to_mem(reg_t paddr) { if (!paddr_ok(paddr)) return NULL; auto desc = bus.find_device(paddr); - if (auto mem = dynamic_cast<mem_t*>(desc.second)) + if (auto mem = dynamic_cast<abstract_mem_t*>(desc.second)) if (paddr - desc.first < mem->size()) return mem->contents(paddr - desc.first); return NULL; diff --git a/riscv/sim.h b/riscv/sim.h index 2b58975..2455263 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -26,7 +26,7 @@ class sim_t : public htif_t, public simif_t { public: sim_t(const cfg_t *cfg, bool halted, - std::vector<std::pair<reg_t, mem_t*>> mems, + std::vector<std::pair<reg_t, abstract_mem_t*>> mems, std::vector<const device_factory_t*> plugin_device_factories, const std::vector<std::string>& args, const debug_module_config_t &dm_config, const char *log_path, @@ -68,7 +68,7 @@ public: private: isa_parser_t isa; const cfg_t * const cfg; - std::vector<std::pair<reg_t, mem_t*>> mems; + std::vector<std::pair<reg_t, abstract_mem_t*>> mems; std::vector<processor_t*> procs; std::map<size_t, processor_t*> harts; std::pair<reg_t, reg_t> initrd_range; |