}
// save/restore of verilator model to/from file.
-void save_model(const char* filenamep, Vmicrowatt* topp)
+void save_model(vluint64_t time, Vmicrowatt* topp)
{
+ char fname[128];
+ sprintf(fname, "verilator.save.%ld", time);
VerilatedSave os;
- os.open(filenamep);
+ os.open(fname);
os << main_time; // user code must save the timestamp, etc
os << *topp;
}
-void restore_model(const char* filenamep, Vmicrowatt* topp)
+void restore_model(vluint64_t time, Vmicrowatt* topp)
{
+ char fname[128];
+ sprintf(fname, "verilator.save.%ld", time);
VerilatedRestore os;
- os.open(filenamep);
+ os.open(fname);
os >> main_time;
os >> *topp;
}
//save bram memory out to a file. use for snapshots
-int memdump(time_t time, unsigned char *mem, size_t sz)
+int memdump(unsigned char *mem, size_t sz)
{
- int fd = open("bram.snapshot.%ld", time, O_RDWR | O_CREAT, (mode_t)0600);
- lseek(fd, sz, SEEK_SET);
- write(fd, "", 1);
- void *map = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
- memcpy(map, mem, sz);
- msync(map, sz, MS_SYNC);
- munmap(map, sz);
- close(fd);
- return 0;
+ char fname[128];
+ sprintf(fname, "bram.snapshot.%ld", main_time);
+ int fd = open(fname, O_RDWR | O_CREAT, (mode_t)0600);
+ lseek(fd, sz, SEEK_SET);
+ write(fd, "", 1);
+ void *map = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ memcpy(map, mem, sz);
+ msync(map, sz, MS_SYNC);
+ munmap(map, sz);
+ close(fd);
+ return 0;
}
+// save-trigger offsets
+vluint64_t save_offset = 1000;
+vluint64_t save_countdown = save_offset;
+
// write (masked by sel) to internal mem offset by bram_addr line
static void mem_write(unsigned char *mem,
unsigned long bram_addr, unsigned long long bram_di,
while(!Verilated::gotFinish()) {
+ // check if a snapshot of the model should be actioned,
+ // otherwise continue counting down
+ if (save_countdown == 0) {
+ fprintf(dump, "snapshot saving at %ld\n", main_time);
+ fflush(dump);
+ save_model(main_time, top);
+ save_countdown = save_offset; // loop for next snapshot
+ } else {
+ --save_countdown;
+ }
+
tick(top, traceme);
// read/write the memory to/from the mmap'd file (if given)