diff options
Diffstat (limited to 'spike_main/spike.cc')
-rw-r--r-- | spike_main/spike.cc | 11 |
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; } } |