nemu: use NEMU_IMAGES_PATH as image search paths

This commit is contained in:
xinyangli 2024-07-09 17:06:15 +08:00
parent 7f0d1ba75a
commit f38674ce79
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
7 changed files with 52 additions and 7 deletions

View file

@ -0,0 +1,6 @@
#ifndef _AM_NPC_NPC_H_
#define _AM_NPC_NPC_H_
#define SERIAL_PORT 0x10000000
#define RTC_ADDR 0x10001000
#endif

View file

@ -86,7 +86,8 @@
inputsFrom = [ inputsFrom = [
self.packages.${system}.nemu 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; } { devShells.npc = with pkgs; mkShell.override { stdenv = ccacheStdenv; } {

View file

@ -43,7 +43,7 @@ stdenv.mkDerivation rec {
doCheck = (defconfig == "alldefconfig"); doCheck = (defconfig == "alldefconfig");
checkPhase = if doCheck then '' checkPhase = if doCheck then ''
export IMAGES_PATH=${am-kernels}/share/binary export NEMU_IMAGES_PATH=${am-kernels}/share/am-kernels
make test make test
'' else ""; '' else "";

View file

@ -1 +0,0 @@
riscv32

View file

@ -1,3 +1,3 @@
DIRS-y += src/monitor/monitor.c DIRS-y += src/monitor
CXXSRC += src/monitor/gdbstub.cc CXXSRC += src/monitor/gdbstub.cc

View file

@ -13,8 +13,10 @@
* See the Mulan PSL v2 for more details. * See the Mulan PSL v2 for more details.
***************************************************************************************/ ***************************************************************************************/
#include <errno.h>
#include <isa.h> #include <isa.h>
#include <memory/paddr.h> #include <memory/paddr.h>
#include <strings.h>
#include <utils.h> #include <utils.h>
void init_rand(); void init_rand();
@ -48,13 +50,50 @@ static char *img_file = NULL;
static int difftest_port = 1234; static int difftest_port = 1234;
static long load_img() { static long load_img() {
FILE *fp = NULL;
size_t img_filename_len = strlen(img_file);
if (img_file == NULL) { if (img_file == NULL) {
Log("No image is given. Use the default build-in image."); Log("No image is given. Use the default build-in image.");
return 4096; // built-in image size return 4096; // built-in image size
} }
FILE *fp = fopen(img_file, "rb"); // Image file is searched from paths in environment variable NEMU_IMAGES_PATH if it's a relative path
Assert(fp, "Can not open '%s'", img_file); 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); fseek(fp, 0, SEEK_END);
long size = ftell(fp); long size = ftell(fp);

View file

@ -14,7 +14,7 @@
#**************************************************************************************/ #**************************************************************************************/
ifneq ($(CONFIG_ITRACE)$(CONFIG_IQUEUE),) ifneq ($(CONFIG_ITRACE)$(CONFIG_IQUEUE),)
CXXSRC = src/utils/disasm.cc CXXSRC += src/utils/disasm.cc
CXXFLAGS += $(shell llvm-config --cxxflags) -fPIE CXXFLAGS += $(shell llvm-config --cxxflags) -fPIE
LIBS += $(shell llvm-config --libs) LIBS += $(shell llvm-config --libs)
endif endif