aboutsummaryrefslogtreecommitdiff
path: root/riscv/devices.h
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2021-02-03 17:57:47 -0800
committerAndrew Waterman <andrew@sifive.com>2021-02-04 03:26:19 -0800
commit716245f5147995575b927a094c664a32f9335c4c (patch)
tree3693392d39a2415847a0954844a18c15a30d5997 /riscv/devices.h
parentf8fc5d8c04c1c85e4bf968ed774128bae177d813 (diff)
downloadspike-716245f5147995575b927a094c664a32f9335c4c.zip
spike-716245f5147995575b927a094c664a32f9335c4c.tar.gz
spike-716245f5147995575b927a094c664a32f9335c4c.tar.bz2
Fix --kernel and --initrd options w.r.t. sparse mem_t implementation
For some reason, the old accessors for the non-sparse version were left dangling. These methods are used by the --kernel and --initrd options, and so those options were just broken. This also fixes a memory leak and refactors the implementation a bit.
Diffstat (limited to 'riscv/devices.h')
-rw-r--r--riscv/devices.h25
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 {