diff --git a/abstract-machine/am/src/riscv/npc/npc.h b/abstract-machine/am/src/riscv/npc/npc.h new file mode 100644 index 0000000..e6c0241 --- /dev/null +++ b/abstract-machine/am/src/riscv/npc/npc.h @@ -0,0 +1,6 @@ +#ifndef _AM_NPC_NPC_H_ +#define _AM_NPC_NPC_H_ +#define SERIAL_PORT 0x10000000 +#define RTC_ADDR 0x10001000 + +#endif \ No newline at end of file diff --git a/flake.nix b/flake.nix index 58652b3..0ea12c7 100644 --- a/flake.nix +++ b/flake.nix @@ -86,7 +86,8 @@ inputsFrom = [ self.packages.${system}.nemu ]; - IMAGES_PATH = "${self.packages.${system}.am-kernels}/share/binary"; + NEMU_HOME = "/home/xin/repo/ysyx-workbench/nemu"; + NEMU_IMAGES_PATH = self.packages.${system}.am-kernels + "/share/am-kernels"; }; devShells.npc = with pkgs; mkShell.override { stdenv = ccacheStdenv; } { diff --git a/nemu/default.nix b/nemu/default.nix index e6ffb2b..785d77e 100644 --- a/nemu/default.nix +++ b/nemu/default.nix @@ -43,7 +43,7 @@ stdenv.mkDerivation rec { doCheck = (defconfig == "alldefconfig"); checkPhase = if doCheck then '' - export IMAGES_PATH=${am-kernels}/share/binary + export NEMU_IMAGES_PATH=${am-kernels}/share/am-kernels make test '' else ""; diff --git a/nemu/src/isa/riscv64 b/nemu/src/isa/riscv64 deleted file mode 120000 index 4eb3f6d..0000000 --- a/nemu/src/isa/riscv64 +++ /dev/null @@ -1 +0,0 @@ -riscv32 \ No newline at end of file diff --git a/nemu/src/monitor/filelist.mk b/nemu/src/monitor/filelist.mk index 4094bee..07c4fe5 100644 --- a/nemu/src/monitor/filelist.mk +++ b/nemu/src/monitor/filelist.mk @@ -1,3 +1,3 @@ -DIRS-y += src/monitor/monitor.c +DIRS-y += src/monitor CXXSRC += src/monitor/gdbstub.cc diff --git a/nemu/src/monitor/monitor.c b/nemu/src/monitor/monitor.c index 9f49786..b9b343e 100644 --- a/nemu/src/monitor/monitor.c +++ b/nemu/src/monitor/monitor.c @@ -13,8 +13,10 @@ * See the Mulan PSL v2 for more details. ***************************************************************************************/ +#include #include #include +#include #include void init_rand(); @@ -48,13 +50,50 @@ static char *img_file = NULL; static int difftest_port = 1234; static long load_img() { + FILE *fp = NULL; + size_t img_filename_len = strlen(img_file); if (img_file == NULL) { Log("No image is given. Use the default build-in image."); return 4096; // built-in image size } - FILE *fp = fopen(img_file, "rb"); - Assert(fp, "Can not open '%s'", img_file); + // Image file is searched from paths in environment variable NEMU_IMAGES_PATH if it's a relative path + if (img_file[0] != '/') { + char *search_paths = getenv("NEMU_IMAGES_PATH"); + if(search_paths == NULL) search_paths = "./"; + search_paths = strdup(search_paths); + Trace("NEMU_IMAGES_PATH=%s", search_paths); + + char *paths_end = strchr(search_paths, '\0'); + char *p_start = search_paths; + do { + char *p = strchr(p_start, ':'); + if (p != NULL) *p = '\0'; + else p = paths_end; + + char *file_path = malloc(p - p_start + img_filename_len + 2); + strcpy(file_path, p_start); + strcat(file_path, "/"); + strcat(file_path, img_file); + + fp = fopen(file_path, "rb"); + free(file_path); + + if (fp) { + Log("Found '%s' in '%s'", img_file, p_start); + break; + } + + Assert(fp != NULL || errno == ENOENT, "Cannot open '%s'", img_file); + p_start = p + 1; + } while(p_start < paths_end); + free(search_paths); + + Assert(fp, "Cannot find '%s'", img_file); + } else { + fp = fopen(img_file, "rb"); + Assert(fp, "Cannot open '%s'", img_file); + } fseek(fp, 0, SEEK_END); long size = ftell(fp); diff --git a/nemu/src/utils/filelist.mk b/nemu/src/utils/filelist.mk index bcd69c5..2537b81 100644 --- a/nemu/src/utils/filelist.mk +++ b/nemu/src/utils/filelist.mk @@ -14,7 +14,7 @@ #**************************************************************************************/ ifneq ($(CONFIG_ITRACE)$(CONFIG_IQUEUE),) -CXXSRC = src/utils/disasm.cc +CXXSRC += src/utils/disasm.cc CXXFLAGS += $(shell llvm-config --cxxflags) -fPIE LIBS += $(shell llvm-config --libs) endif