Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ram: add gcpt-restore option for VCS #322

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/test/csrc/common/ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/test/csrc/common/ram.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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_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;
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 1 addition & 4 deletions src/test/csrc/verilator/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/test/vsrc/vcs/top.v
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")) begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the same argument name as Verilator. Use gcpt-restore instead of gcpt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

$value$plusargs("gcpt=%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);
Expand Down
Loading