aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;