diff options
author | Andrew Waterman <andrew@sifive.com> | 2019-10-16 16:24:11 -0700 |
---|---|---|
committer | Chih-Min Chao <chihmin.chao@sifive.com> | 2019-10-22 20:08:13 -0700 |
commit | d00c27ddd52cc6bb8f4539e616430a83f1917ace (patch) | |
tree | 807871cdea1b62eb3d7a26c3c8fa8bc46a43013d /riscv/sim.cc | |
parent | 3742f48eb3186c5a36d4e29bef57ab73e9d5edb7 (diff) | |
download | spike-d00c27ddd52cc6bb8f4539e616430a83f1917ace.zip spike-d00c27ddd52cc6bb8f4539e616430a83f1917ace.tar.gz spike-d00c27ddd52cc6bb8f4539e616430a83f1917ace.tar.bz2 |
Enforce 2^56-bit physical address limit
It's very difficult to encounter this (need to manually place a device or
memory at very high addresses), but it is technically a Spike bug.
Diffstat (limited to 'riscv/sim.cc')
-rw-r--r-- | riscv/sim.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/riscv/sim.cc b/riscv/sim.cc index 64332c3..be53a9c 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -163,16 +163,21 @@ void sim_t::set_procs_debug(bool value) procs[i]->set_debug(value); } +static bool paddr_ok(reg_t addr) +{ + return (addr >> MAX_PADDR_BITS) == 0; +} + bool sim_t::mmio_load(reg_t addr, size_t len, uint8_t* bytes) { - if (addr + len < addr) + if (addr + len < addr || !paddr_ok(addr + len - 1)) return false; return bus.load(addr, len, bytes); } bool sim_t::mmio_store(reg_t addr, size_t len, const uint8_t* bytes) { - if (addr + len < addr) + if (addr + len < addr || !paddr_ok(addr + len - 1)) return false; return bus.store(addr, len, bytes); } @@ -210,6 +215,8 @@ void sim_t::make_dtb() } char* sim_t::addr_to_mem(reg_t addr) { + if (!paddr_ok(addr)) + return NULL; auto desc = bus.find_device(addr); if (auto mem = dynamic_cast<mem_t*>(desc.second)) if (addr - desc.first < mem->size()) |