提交 cb52c370 编写于 作者: Z Zihao Yu

emu: support loading snapshot from command line

* But difftest is disabled when running with a snapshot. This will be
  fixed in the future.
上级 f5b9dcb4
......@@ -107,10 +107,11 @@ SEED ?= $(shell shuf -i 1-10000 -n 1)
# use 'emu -h' to see more details
B ?= 0
E ?= -1
#SNAPSHOT = --load-snapshot=$(NOOP_HOME)/build/2020-07-25@22:19:17.snapshot
emu: $(EMU)
ifeq ($(REMOTE),localhost)
@$(EMU) -i $(IMAGE) -s $(SEED) -b $(B) -e $(E)
@$(EMU) -i $(IMAGE) -s $(SEED) -b $(B) -e $(E) $(SNAPSHOT)
else
ssh -tt $(REMOTE) "cd $(REMOTE_PRJ_HOME) && $(EMU) -i $(REMOTE_PREFIX)/$(realpath $(IMAGE)) -s $(SEED) -b $(B) -e $(E)"
endif
......
......@@ -32,10 +32,10 @@ class Emulator {
uint32_t seed;
uint64_t max_cycles, cycles;
uint64_t log_begin, log_end;
const char *snapshot_path;
std::vector<const char *> parse_args(int argc, const char *argv[]);
static const struct option long_options[];
static void print_help(const char *file);
void read_emu_regs(uint64_t *r) {
......@@ -76,7 +76,8 @@ class Emulator {
image(nullptr),
dut_ptr(new std::remove_reference<decltype(*dut_ptr)>::type),
seed(0), max_cycles(-1), cycles(0),
log_begin(0), log_end(-1)
log_begin(0), log_end(-1),
snapshot_path(NULL)
{
// init emu
auto args = parse_args(argc, argv);
......@@ -88,10 +89,6 @@ class Emulator {
srand48(seed);
Verilated::randReset(2);
// set log time range and log level
dut_ptr->io_logCtrl_log_begin = log_begin;
dut_ptr->io_logCtrl_log_end = log_end;
// init ram
extern void init_ram(const char *img);
init_ram(image);
......@@ -235,6 +232,14 @@ class Emulator {
eprintf(ANSI_COLOR_MAGENTA "This is random test for cache.\n" ANSI_COLOR_RESET);
cache_test(max_cycles);
#else
if (snapshot_path != NULL) {
snapshot_load(snapshot_path);
}
// set log time range and log level
dut_ptr->io_logCtrl_log_begin = log_begin;
dut_ptr->io_logCtrl_log_end = log_end;
execute_cycles(max_cycles);
#endif
}
......
......@@ -15,16 +15,6 @@
std::function<double()> get_sc_time_stamp = []() -> double { return 0; };
double sc_time_stamp() { return get_sc_time_stamp(); }
const struct option Emulator::long_options[] = {
{ "seed", 1, NULL, 's' },
{ "max-cycles", 1, NULL, 'C' },
{ "image", 1, NULL, 'i' },
{ "log-begin", 1, NULL, 'b' },
{ "log-end", 1, NULL, 'e' },
{ "help", 0, NULL, 'h' },
{ 0, 0, NULL, 0 }
};
void Emulator::print_help(const char *file) {
printf("Usage: %s [OPTION...]\n", file);
printf("\n");
......@@ -39,9 +29,31 @@ void Emulator::print_help(const char *file) {
std::vector<const char *> Emulator::parse_args(int argc, const char *argv[]) {
std::vector<const char *> args = { argv[0] };
int long_index = 0;
const struct option long_options[] = {
{ "load-snapshot", 1, NULL, 0 },
{ "seed", 1, NULL, 's' },
{ "max-cycles", 1, NULL, 'C' },
{ "image", 1, NULL, 'i' },
{ "log-begin", 1, NULL, 'b' },
{ "log-end", 1, NULL, 'e' },
{ "help", 0, NULL, 'h' },
{ 0, 0, NULL, 0 }
};
int o;
while ( (o = getopt_long(argc, const_cast<char *const*>(argv), "-s:C:hi:m:b:e:", long_options, NULL)) != -1) {
while ( (o = getopt_long(argc, const_cast<char *const*>(argv),
"-s:C:hi:m:b:e:", long_options, &long_index)) != -1) {
switch (o) {
case 0:
if (long_index == 0) {
snapshot_path = optarg;
break;
}
// fall through
default:
print_help(argv[0]);
exit(0);
case 's':
if(std::string(optarg) != "NO_SEED") {
seed = atoll(optarg);
......@@ -55,9 +67,6 @@ std::vector<const char *> Emulator::parse_args(int argc, const char *argv[]) {
break;
case 'b': log_begin = atoll(optarg); break;
case 'e': log_end = atoll(optarg); break;
default:
print_help(argv[0]);
exit(0);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册