// 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) {
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
#endif // BRAM_DEBUG
}
+ if (mem != NULL) {
+ free(mem);
+ }
+
fclose(dump);
#if VM_TRACE