diff options
author | Andrew Waterman <andrew@sifive.com> | 2020-04-13 19:00:56 -0700 |
---|---|---|
committer | Chih-Min Chao <chihmin.chao@sifive.com> | 2020-04-14 19:20:11 -0700 |
commit | 6a571f710ee7f8a6a107176ac5b7dd8a9f14cf0b (patch) | |
tree | d612e3a3353b725ba72e0df552299ce89fe40d13 /spike_main | |
parent | 80b2e9002ae81001e34b2fb76a1e7e3bbf839e9d (diff) | |
download | spike-6a571f710ee7f8a6a107176ac5b7dd8a9f14cf0b.zip spike-6a571f710ee7f8a6a107176ac5b7dd8a9f14cf0b.tar.gz spike-6a571f710ee7f8a6a107176ac5b7dd8a9f14cf0b.tar.bz2 |
Handle misaligned memories by aligning them, rather than erroring
Resolves #442
Diffstat (limited to 'spike_main')
-rw-r--r-- | spike_main/spike.cc | 17 |
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; |