diff --git a/src/test/csrc/common/ram.cpp b/src/test/csrc/common/ram.cpp index 289764cbf..3923541dd 100644 --- a/src/test/csrc/common/ram.cpp +++ b/src/test/csrc/common/ram.cpp @@ -432,6 +432,13 @@ void LinearizedFootprintsMemory::save_linear_memory(const char *filename) { out_file.close(); } +void overwrite_ram(const char *gcpt_restore, uint64_t overwrite_nbytes) { + InputReader *reader = new FileReader(gcpt_restore); + int overwrite_size = reader->read_all(simMemory->as_ptr(), overwrite_nbytes); + Info("Overwrite %d bytes from file %s.\n", overwrite_size, gcpt_restore); + delete reader; +} + #ifdef WITH_DRAMSIM3 void dramsim3_init() { #if !defined(DRAMSIM3_CONFIG) || !defined(DRAMSIM3_OUTDIR) diff --git a/src/test/csrc/common/ram.h b/src/test/csrc/common/ram.h index 1a5972d96..8e549c747 100644 --- a/src/test/csrc/common/ram.h +++ b/src/test/csrc/common/ram.h @@ -214,6 +214,7 @@ class LinearizedFootprintsMemory : public FootprintsMemory { extern SimMemory *simMemory; // This is to initialize the common mmap RAM void init_ram(const char *image, uint64_t n_bytes); +void overwrite_ram(const char *gcpt_restore, uint64_t overwrite_nbytes); #ifdef WITH_DRAMSIM3 diff --git a/src/test/csrc/vcs/vcs_main.cpp b/src/test/csrc/vcs/vcs_main.cpp index 9bb85eb06..0e0237818 100644 --- a/src/test/csrc/vcs/vcs_main.cpp +++ b/src/test/csrc/vcs/vcs_main.cpp @@ -32,9 +32,11 @@ static bool has_reset = false; static char bin_file[256] = "/dev/zero"; static char *flash_bin_file = NULL; +static char *gcpt_restore_bin = NULL; static bool enable_difftest = true; static uint64_t max_instrs = 0; static char *workload_list = NULL; +static uint64_t overwrite_nbytes = 0xe00; enum { SIMV_RUN, @@ -53,6 +55,11 @@ extern "C" void set_flash_bin(char *s) { strcpy(flash_bin_file, s); } +extern "C" void set_gcpt_bin(char *s) { + gcpt_restore_bin = (char *)malloc(256); + strcpy(gcpt_restore_bin, s); +} + extern "C" void set_max_instrs(uint64_t mc) { printf("set max instrs: %lu\n", mc); max_instrs = mc; @@ -117,6 +124,9 @@ extern "C" uint8_t simv_init() { init_goldenmem(); init_nemuproxy(DEFAULT_EMU_RAM_SIZE); } + if (gcpt_restore_bin != NULL) { + overwrite_ram(gcpt_restore_bin, overwrite_nbytes); + } return 0; } diff --git a/src/test/csrc/verilator/emu.cpp b/src/test/csrc/verilator/emu.cpp index ec2421d2d..aa55cb5ac 100644 --- a/src/test/csrc/verilator/emu.cpp +++ b/src/test/csrc/verilator/emu.cpp @@ -382,10 +382,7 @@ Emulator::Emulator(int argc, const char *argv[]) } if (args.gcpt_restore) { - InputReader *reader = new FileReader(args.gcpt_restore); - int overwrite_size = reader->read_all(simMemory->as_ptr(), args.overwrite_nbytes); - Info("Overwrite %d bytes from file %s.\n", overwrite_size, args.gcpt_restore); - delete reader; + overwrite_ram(args.gcpt_restore, args.overwrite_nbytes); } #ifdef ENABLE_CHISEL_DB diff --git a/src/test/vsrc/vcs/top.v b/src/test/vsrc/vcs/top.v index 9dae5db99..3f05390c0 100644 --- a/src/test/vsrc/vcs/top.v +++ b/src/test/vsrc/vcs/top.v @@ -20,6 +20,7 @@ module tb_top(); `ifndef TB_NO_DPIC import "DPI-C" function void set_bin_file(string bin); import "DPI-C" function void set_flash_bin(string bin); +import "DPI-C" function void set_gcpt_bin(string bin); import "DPI-C" function void set_diff_ref_so(string diff_so); import "DPI-C" function void set_no_diff(); import "DPI-C" function byte simv_init(); @@ -63,6 +64,7 @@ wire [`CONFIG_DIFFTEST_STEPWIDTH - 1:0] difftest_step; string bin_file; string flash_bin_file; +string gcpt_bin_file; string wave_type; string diff_ref_so; string workload_list; @@ -126,6 +128,11 @@ initial begin $value$plusargs("flash=%s", flash_bin_file); set_flash_bin(flash_bin_file); end + // overwrite gcpt on ram: bin file + if ($test$plusargs("gcpt-restore")) begin + $value$plusargs("gcpt-restore=%s", gcpt_bin_file); + set_gcpt_bin(gcpt_bin_file); + end // diff-test golden model: nemu-so if ($test$plusargs("diff")) begin $value$plusargs("diff=%s", diff_ref_so);