From 42c075ee4b7acdfec1bb9ca38bdc1280d5e73119 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 1 Jan 2022 03:16:07 +0000 Subject: [PATCH] copy mmapd file into large buffer to allow read/write past end --- verilator/microwatt-verilator.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/verilator/microwatt-verilator.cpp b/verilator/microwatt-verilator.cpp index a4a8f25..dbdee92 100644 --- a/verilator/microwatt-verilator.cpp +++ b/verilator/microwatt-verilator.cpp @@ -94,6 +94,7 @@ int main(int argc, char **argv) // contents are not overwritten unsigned char *mem = NULL; if (bram_file != NULL) { + unsigned char *fmem = NULL; int fd = open(bram_file, O_RDONLY); if (fd < 0) { @@ -108,14 +109,20 @@ int main(int argc, char **argv) exit(2); } - mem = (unsigned char*)mmap(NULL, statbuf.st_size, + fmem = (unsigned char*)mmap(NULL, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); - if (mem == MAP_FAILED) { + if (fmem == MAP_FAILED) { printf("Mapping Failed\n"); exit(2); } close(fd); + + // allocate more memory than is in the file, copy it over + size_t sz = 0x2000000; + mem = (unsigned char*)malloc(sz); + memcpy(mem, fmem, statbuf.st_size); + munmap(fmem, statbuf.st_size); } unsigned long long bram_data = 0; unsigned long long bram_data1 = 0; // another clock delay @@ -191,6 +198,10 @@ int main(int argc, char **argv) #endif // BRAM_DEBUG } + if (mem != NULL) { + free(mem); + } + fclose(dump); #if VM_TRACE -- 2.30.2