diff options
author | Chih-Min Chao <48193236+chihminchao@users.noreply.github.com> | 2021-01-21 14:30:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 22:30:36 -0800 |
commit | 5b51752cea5c44916c16731c09985f48e89316b9 (patch) | |
tree | 41fadc7c20b546a49a6a2cc49dbe7e7ae59e8518 /riscv/devices.h | |
parent | 9bfb43c668848a4850d5805b9adb8ad18e7f43b6 (diff) | |
download | spike-5b51752cea5c44916c16731c09985f48e89316b9.zip spike-5b51752cea5c44916c16731c09985f48e89316b9.tar.gz spike-5b51752cea5c44916c16731c09985f48e89316b9.tar.bz2 |
add support to page on demand (#634)
This patch splites the target-requested memory regions into pages and only
allocates host memory when it is accessed to reduce larget memory sceniaro
in 64 bit target system
Co-authored-by: Dave.Wen <dave.wen@sifive.com>
Diffstat (limited to 'riscv/devices.h')
-rw-r--r-- | riscv/devices.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/riscv/devices.h b/riscv/devices.h index 3dd6c66..82aab89 100644 --- a/riscv/devices.h +++ b/riscv/devices.h @@ -8,6 +8,7 @@ #include <map> #include <vector> #include <stdexcept> +#include <utility> class processor_t; @@ -45,19 +46,21 @@ class mem_t : public abstract_device_t { mem_t(size_t size) : len(size) { if (!size) throw std::runtime_error("zero bytes of target memory requested"); - data = (char*)calloc(1, size); - if (!data) - throw std::runtime_error("couldn't allocate " + std::to_string(size) + " bytes of target memory"); + data = nullptr; } mem_t(const mem_t& that) = delete; - ~mem_t() { free(data); } + ~mem_t() { + free(data); + } 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() { return data; } + char* contents(); + char* contents(reg_t addr); size_t size() { return len; } private: + std::map<reg_t, std::pair<char*, bool>> acc_tbl; char* data; size_t len; }; |