Browse Source

Handle misaligned memories by aligning them, rather than erroring

Resolves #442
pull/452/head
Andrew Waterman 6 years ago
parent
commit
ecb15182b5
  1. 17
      spike_main/spike.cc

17
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;

Loading…
Cancel
Save