aboutsummaryrefslogtreecommitdiff
path: root/spike_main
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2021-02-03 17:57:47 -0800
committerAndrew Waterman <andrew@sifive.com>2021-02-04 03:26:19 -0800
commit716245f5147995575b927a094c664a32f9335c4c (patch)
tree3693392d39a2415847a0954844a18c15a30d5997 /spike_main
parentf8fc5d8c04c1c85e4bf968ed774128bae177d813 (diff)
downloadspike-716245f5147995575b927a094c664a32f9335c4c.zip
spike-716245f5147995575b927a094c664a32f9335c4c.tar.gz
spike-716245f5147995575b927a094c664a32f9335c4c.tar.bz2
Fix --kernel and --initrd options w.r.t. sparse mem_t implementation
For some reason, the old accessors for the non-sparse version were left dangling. These methods are used by the --kernel and --initrd options, and so those options were just broken. This also fixes a memory leak and refactors the implementation a bit.
Diffstat (limited to 'spike_main')
-rw-r--r--spike_main/spike.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc
index b86f829..94b35c5 100644
--- a/spike_main/spike.cc
+++ b/spike_main/spike.cc
@@ -89,11 +89,14 @@ static std::ifstream::pos_type get_file_size(const char *filename)
}
static void read_file_bytes(const char *filename,size_t fileoff,
- char *read_buf, size_t read_sz)
+ mem_t* mem, size_t memoff, size_t read_sz)
{
std::ifstream in(filename, std::ios::in | std::ios::binary);
in.seekg(fileoff, std::ios::beg);
- in.read(read_buf, read_sz);
+
+ std::vector<char> read_buf(read_sz, 0);
+ in.read(&read_buf[0], read_sz);
+ mem->store(memoff, read_sz, (uint8_t*)&read_buf[0]);
}
bool sort_mem_region(const std::pair<reg_t, mem_t*> &a,
@@ -374,7 +377,7 @@ int main(int argc, char** argv)
kernel_offset = 0x400000;
for (auto& m : mems) {
if (kernel_size && (kernel_offset + kernel_size) < m.second->size()) {
- read_file_bytes(kernel, 0, m.second->contents() + kernel_offset, kernel_size);
+ read_file_bytes(kernel, 0, m.second, kernel_offset, kernel_size);
break;
}
}
@@ -386,7 +389,7 @@ int main(int argc, char** argv)
if (initrd_size && (initrd_size + 0x1000) < m.second->size()) {
initrd_end = m.first + m.second->size() - 0x1000;
initrd_start = initrd_end - initrd_size;
- read_file_bytes(initrd, 0, m.second->contents() + (initrd_start - m.first), initrd_size);
+ read_file_bytes(initrd, 0, m.second, initrd_start - m.first, initrd_size);
break;
}
}