aboutsummaryrefslogtreecommitdiff
path: root/spike_main/spike.cc
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2020-04-13 19:00:56 -0700
committerAndrew Waterman <andrew@sifive.com>2020-04-13 19:00:56 -0700
commitecb15182b55c03bbe7b20a8f7fdc59b6878586e7 (patch)
tree61d874a0d9a5ab34330ddff98a75908bcc8aa5a6 /spike_main/spike.cc
parent220ae7ec6b9bf4a5d81190ffa1028438c3cf402b (diff)
downloadspike-ecb15182b55c03bbe7b20a8f7fdc59b6878586e7.zip
spike-ecb15182b55c03bbe7b20a8f7fdc59b6878586e7.tar.gz
spike-ecb15182b55c03bbe7b20a8f7fdc59b6878586e7.tar.bz2
Handle misaligned memories by aligning them, rather than erroring
Resolves #442
Diffstat (limited to 'spike_main/spike.cc')
-rw-r--r--spike_main/spike.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc
index 31c0cd7..9056f31 100644
--- a/spike_main/spike.cc
+++ b/spike_main/spike.cc
@@ -112,8 +112,23 @@ static std::vector<std::pair<reg_t, mem_t*>> make_mems(const char* arg)
if (!*p || *p != ':')
help();
auto size = strtoull(p + 1, &p, 0);
- if ((size | base) % PGSIZE != 0)
+
+ // page-align base and size
+ auto base0 = base, size0 = size;
+ size += base0 % PGSIZE;
+ base -= base0 % PGSIZE;
+ if (size % PGSIZE != 0)
+ size += PGSIZE - size % PGSIZE;
+
+ if (base + size < base)
help();
+
+ if (size != size0) {
+ 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, PGSIZE / 1024, base, base + size - 1);
+ }
+
res.push_back(std::make_pair(reg_t(base), new mem_t(size)));
if (!*p)
break;