From d496ffcd94c89803d8ef26d325c86c4a86f0ef29 Mon Sep 17 00:00:00 2001 From: xiaokamikami <1317379456@qq.com> Date: Fri, 22 Mar 2024 15:23:25 +0800 Subject: [PATCH] ram: overwrite gcpt --- src/test/csrc/common/ram.cpp | 7 +++++++ src/test/csrc/common/ram.h | 1 + src/test/csrc/vcs/vcs_main.cpp | 10 ++++++++++ src/test/csrc/verilator/emu.cpp | 5 +---- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/test/csrc/common/ram.cpp b/src/test/csrc/common/ram.cpp index 289764cbf..f90ab2ab4 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(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..cb870e640 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(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..78aa0c351 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_bin_file = 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_file(char *s) { + gcpt_bin_file = (char *)malloc(256); + strcpy(gcpt_bin_file, 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_bin_file != NULL) { + overwrite_ram(gcpt_bin_file, 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