diff options
author | Parshintsev Anatoly <anatoly.parshintsev@syntacore.com> | 2022-11-14 16:58:36 +0300 |
---|---|---|
committer | Parshintsev Anatoly <anatoly.parshintsev@syntacore.com> | 2022-11-16 18:42:16 +0300 |
commit | e2ccdf6b694d0b7cd10e016214497edaf61e1136 (patch) | |
tree | 2febf071337fab5305c1620e42de8b96a9928abf /spike_main | |
parent | 4470418b809ab4a439c468b0714bd15cde3cde46 (diff) | |
download | spike-e2ccdf6b694d0b7cd10e016214497edaf61e1136.zip spike-e2ccdf6b694d0b7cd10e016214497edaf61e1136.tar.gz spike-e2ccdf6b694d0b7cd10e016214497edaf61e1136.tar.bz2 |
Only allow memory regions that are less than (1ull << MAX_PADDR_BITS)
Other regions are inaccessible to the hardware being modeled
Diffstat (limited to 'spike_main')
-rw-r--r-- | spike_main/spike.cc | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 2df3223..96c7eb1 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -3,6 +3,7 @@ #include "cfg.h" #include "sim.h" #include "mmu.h" +#include "arith.h" #include "remote_bitbang.h" #include "cachesim.h" #include "extension.h" @@ -14,6 +15,8 @@ #include <string> #include <memory> #include <fstream> +#include <limits> +#include <cinttypes> #include "../VERSION" static void help(int exit_code = 1) @@ -188,7 +191,24 @@ static std::vector<mem_cfg_t> parse_mem_layout(const char* arg) exit(EXIT_FAILURE); } - res.push_back(mem_cfg_t(reg_t(base), reg_t(size))); + const unsigned long long max_allowed_pa = (1ull << MAX_PADDR_BITS) - 1ull; + assert(max_allowed_pa <= std::numeric_limits<reg_t>::max()); + mem_cfg_t mem_region(base, size); + auto last_pa_region = mem_region.base + mem_region.size - 1; + if (last_pa_region > max_allowed_pa) { + int bits_required = 64 - clz(last_pa_region); + fprintf(stderr, "Unsupported memory region " + "{base = 0x%" PRIX64 ", size = 0x%" PRIX64 "} specified," + " which requires %d bits of physical address\n" + " The largest accessible physical address " + "is 0x%llX (defined by MAX_PADDR_BITS constant, which is %d)\n", + mem_region.base, mem_region.size, bits_required, + max_allowed_pa, MAX_PADDR_BITS); + exit(EXIT_FAILURE); + } + + res.push_back(mem_region); + if (!*p) break; if (*p != ',') |