From 0381ae5acb25ae248fd28b634e3707eb1ce416a6 Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Mon, 14 Oct 2019 14:49:38 +0800 Subject: [PATCH] noop,IFU: change reset vector to 0x80000000 * also put mainargs at 0x80001000 to match AM --- Makefile | 2 +- src/main/scala/noop/IFU.scala | 2 +- src/test/csrc/difftest.cpp | 7 +++---- src/test/csrc/emu.h | 9 ++++----- src/test/csrc/main.cpp | 13 +++++++------ src/test/csrc/ram.cpp | 9 ++++++--- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 2e0d73622..de41df00b 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ $(EMU): $(EMU_MK) $(EMU_DEPS) $(EMU_HEADERS) $(REF_SO) CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) -C $(dir $(EMU_MK)) -f $(abspath $(EMU_MK)) ifdef mainargs -MAINARGS = -a $(mainargs) +MAINARGS = -m $(mainargs) endif emu: $(EMU) diff --git a/src/main/scala/noop/IFU.scala b/src/main/scala/noop/IFU.scala index c7018bde6..5481e12d5 100644 --- a/src/main/scala/noop/IFU.scala +++ b/src/main/scala/noop/IFU.scala @@ -8,7 +8,7 @@ import utils._ import bus.simplebus._ trait HasResetVector { - val resetVector = 0x80100000L//TODO: set reset vec + val resetVector = 0x80000000L//TODO: set reset vec } class IFU extends NOOPModule with HasResetVector { diff --git a/src/test/csrc/difftest.cpp b/src/test/csrc/difftest.cpp index 10adfebbb..8ed9c3342 100644 --- a/src/test/csrc/difftest.cpp +++ b/src/test/csrc/difftest.cpp @@ -34,7 +34,7 @@ void difftest_skip_dut() { is_skip_dut = true; } -void init_difftest(uint64_t *reg, const char *mainargs) { +void init_difftest(uint64_t *reg) { void *handle; handle = dlopen(REF_SO, RTLD_LAZY | RTLD_DEEPBIND); assert(handle); @@ -63,14 +63,13 @@ void init_difftest(uint64_t *reg, const char *mainargs) { ref_difftest_init(); void* get_img_start(); long get_img_size(); - ref_difftest_memcpy_from_dut(0x100000, get_img_start(), get_img_size()); - ref_difftest_memcpy_from_dut(0x0, (void *)mainargs, strlen(mainargs) + 1); + ref_difftest_memcpy_from_dut(0x0, get_img_start(), get_img_size()); ref_difftest_setregs(reg); } int difftest_step(uint64_t *reg_scala, uint64_t this_pc, int isMMIO, uint64_t intrNO) { uint64_t ref_r[33]; - static uint64_t nemu_pc = 0x80100000; + static uint64_t nemu_pc = 0x80000000; if (isMMIO) { // printf("diff pc: %x\n", this_pc); // MMIO accessing should not be a branch or jump, just +4 to get the next pc diff --git a/src/test/csrc/emu.h b/src/test/csrc/emu.h index 7add099c1..07109eae1 100644 --- a/src/test/csrc/emu.h +++ b/src/test/csrc/emu.h @@ -9,7 +9,6 @@ #include "common.h" #include "VNOOPSimTop.h" - class Emulator { const char *image; const char *mainargs; @@ -37,7 +36,7 @@ class Emulator { // argv decay to the secondary pointer Emulator(int argc, const char *argv[]): image(nullptr), - mainargs(""), + mainargs(NULL), dut_ptr(new std::remove_reference::type), seed(0), max_cycles(-1), cycles(0) { @@ -60,11 +59,11 @@ class Emulator { // init core reset_ncycles(10); - extern void init_difftest(uint64_t *reg, const char *mainargs); + extern void init_difftest(uint64_t *reg); uint64_t reg[33]; read_emu_regs(reg); - reg[32] = 0x80100000; - init_difftest(reg, mainargs); + reg[32] = 0x80000000; + init_difftest(reg); } void reset_ncycles(size_t cycles) { diff --git a/src/test/csrc/main.cpp b/src/test/csrc/main.cpp index 021c332c3..e062728a7 100644 --- a/src/test/csrc/main.cpp +++ b/src/test/csrc/main.cpp @@ -20,8 +20,9 @@ const struct option Emulator::long_options[] = { { "seed", 1, NULL, 's' }, { "max-cycles", 1, NULL, 'C' }, { "image", 1, NULL, 'i' }, - { "mainargs", 1, NULL, 'a' }, - { "help", 0, NULL, 'h' } + { "mainargs", 1, NULL, 'm' }, + { "help", 0, NULL, 'h' }, + { 0, 0, NULL, 0 } }; void Emulator::print_help(const char *file) { @@ -30,15 +31,15 @@ void Emulator::print_help(const char *file) { printf(" -s, --seed=NUM use this seed\n"); printf(" -C, --max-cycles=NUM execute at most NUM cycles\n"); printf(" -i, --image=FILE run with this image file\n"); + printf(" -m, --mainargs=ARGS run with this mainargs (AM only)\n"); printf(" -h, --help print program help info\n"); printf("\n"); - printf("Report bugs to 141242068@smail.nju.edu.cn.\n"); } std::vector Emulator::parse_args(int argc, const char *argv[]) { std::vector args = { argv[0] }; int o; - while ( (o = getopt_long(argc, const_cast(argv), "-s:C:hi:a:", long_options, NULL)) != -1) { + while ( (o = getopt_long(argc, const_cast(argv), "-s:C:hi:m:", long_options, NULL)) != -1) { switch (o) { case 's': if(std::string(optarg) != "NO_SEED") @@ -49,8 +50,8 @@ std::vector Emulator::parse_args(int argc, const char *argv[]) { args.push_back("-i"); args.push_back(optarg); break; - case 'a': mainargs = optarg; - args.push_back("-a"); + case 'm': mainargs = optarg; + args.push_back("-m"); args.push_back(optarg); break; default: diff --git a/src/test/csrc/ram.cpp b/src/test/csrc/ram.cpp index 783cb9dbe..f81065c4e 100644 --- a/src/test/csrc/ram.cpp +++ b/src/test/csrc/ram.cpp @@ -1,10 +1,11 @@ #include "common.h" #define RAMSIZE (128 * 1024 * 1024) +#define MAINARGS_START 0x1000 static uint64_t ram[RAMSIZE / sizeof(uint64_t)]; static long img_size = 0; -void* get_img_start() { return &ram[0x100000 / sizeof(uint64_t)]; } +void* get_img_start() { return &ram[0]; } long get_img_size() { return img_size; } void init_ram(const char *img, const char *mainargs) { @@ -21,11 +22,13 @@ void init_ram(const char *img, const char *mainargs) { img_size = ftell(fp); fseek(fp, 0, SEEK_SET); - int ret = fread(get_img_start(), img_size, 1, fp); + int ret = fread(ram, img_size, 1, fp); assert(ret == 1); fclose(fp); - strcpy((char *)ram, mainargs); + if (mainargs != NULL) { + strcpy((char *)ram + MAINARGS_START, mainargs); + } } extern "C" void ram_helper( -- GitLab