nemu: use NEMU_IMAGES_PATH as image search paths
This commit is contained in:
parent
7f0d1ba75a
commit
f38674ce79
7 changed files with 52 additions and 7 deletions
6
abstract-machine/am/src/riscv/npc/npc.h
Normal file
6
abstract-machine/am/src/riscv/npc/npc.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef _AM_NPC_NPC_H_
|
||||
#define _AM_NPC_NPC_H_
|
||||
#define SERIAL_PORT 0x10000000
|
||||
#define RTC_ADDR 0x10001000
|
||||
|
||||
#endif
|
|
@ -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; } {
|
||||
|
|
|
@ -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 "";
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
riscv32
|
|
@ -1,3 +1,3 @@
|
|||
DIRS-y += src/monitor/monitor.c
|
||||
DIRS-y += src/monitor
|
||||
|
||||
CXXSRC += src/monitor/gdbstub.cc
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
* See the Mulan PSL v2 for more details.
|
||||
***************************************************************************************/
|
||||
|
||||
#include <errno.h>
|
||||
#include <isa.h>
|
||||
#include <memory/paddr.h>
|
||||
#include <strings.h>
|
||||
#include <utils.h>
|
||||
|
||||
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");
|
||||
// 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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue