aboutsummaryrefslogtreecommitdiff
path: root/spike_main
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2022-11-16 11:19:50 -0800
committerGitHub <noreply@github.com>2022-11-16 11:19:50 -0800
commit0b14bb363ce7e4ca2be12e4965167ac3e7dca3fe (patch)
treebf6db77d557c02604b2169efc42f4b6ca6a5da25 /spike_main
parentab3225a3ff687fda8b4180f9e4e0949a400d1247 (diff)
parente2ccdf6b694d0b7cd10e016214497edaf61e1136 (diff)
downloadriscv-isa-sim-0b14bb363ce7e4ca2be12e4965167ac3e7dca3fe.zip
riscv-isa-sim-0b14bb363ce7e4ca2be12e4965167ac3e7dca3fe.tar.gz
riscv-isa-sim-0b14bb363ce7e4ca2be12e4965167ac3e7dca3fe.tar.bz2
Merge pull request #1119 from aap-sc/aap-sc/max_pa_restriction
Do not allow memory regions larger than (1ull << MAX_PADDR_BITS)
Diffstat (limited to 'spike_main')
-rw-r--r--spike_main/spike.cc29
1 files changed, 24 insertions, 5 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc
index 3d9da02..cd8a6d8 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)
@@ -177,20 +180,36 @@ static std::vector<mem_cfg_t> parse_mem_layout(const char* arg)
size += PGSIZE - size % PGSIZE;
if (size != size0) {
- fprintf(stderr, "Warning: the memory at [0x%llX, 0x%llX] has been realigned\n"
+ fprintf(stderr, "Warning: the memory at [0x%llX, 0x%llX] has been realigned\n"
"to the %ld KiB page size: [0x%llX, 0x%llX]\n",
base0, base0 + size0 - 1, long(PGSIZE / 1024), base, base + size - 1);
}
if (!mem_cfg_t::check_if_supported(base, size)) {
- fprintf(stderr, "unsupported memory region "
+ fprintf(stderr, "Unsupported memory region "
"{base = 0x%llX, size = 0x%llX} specified\n",
- (unsigned long long)base,
- (unsigned long long)size);
+ base, size);
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 != ',')