From 6b5f105ae4ece69f22646bd6a77bba1a9077d81a Mon Sep 17 00:00:00 2001 From: ChinYikMing Date: Sat, 2 Nov 2024 17:44:36 +0800 Subject: [PATCH] Introduce ENABLE_USE_ELF Currently, the system test suite is compiled into a single ELF executable, leading to discrepancies between the inputs for Linux kernel emulation and the system test suite. By introducing ENABLE_USE_ELF, we can allow the use of the ELF executable when running the system test suite. This might be a temporarily solution, need to refactor more. --- .github/workflows/main.yml | 4 ++-- Makefile | 7 +++++-- src/main.c | 18 +++++++++++------- src/riscv.c | 6 ++++-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6de9879d..8efdcfdf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,11 +67,11 @@ jobs: - name: misalignment test in block emulation run: | make -C tests/system/alignment/ - make distclean && make ENABLE_EXT_C=0 ENABLE_SYSTEM=1 misalign-in-blk-emu -j$(nproc) + make distclean && make ENABLE_USE_ELF=1 ENABLE_EXT_C=0 ENABLE_SYSTEM=1 misalign-in-blk-emu -j$(nproc) - name: MMU test run: | make -C tests/system/mmu/ - make distclean && make ENABLE_SYSTEM=1 mmu-test -j$(nproc) + make distclean && make ENABLE_USE_ELF=1 ENABLE_SYSTEM=1 mmu-test -j$(nproc) - name: gdbstub test run: | make distclean && make ENABLE_GDBSTUB=1 gdbstub-test -j$(nproc) diff --git a/Makefile b/Makefile index 5c80c2ef..9d5f9aac 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,10 @@ CFLAGS += -include src/common.h # However, the Linux kernel emulation includes the Image, DT, and # root filesystem (rootfs). Therefore, the test suite needs this # flag to load the ELF and differentiate it from the kernel emulation. -USE_ELF ?= 0 +ENABLE_USE_ELF ?= 0 +ifeq ($(call has, USE_ELF), 1) +DEFINE_USE_ELF := -DUSE_ELF +endif ENABLE_SYSTEM ?= 0 $(call set-feature, SYSTEM) @@ -248,7 +251,7 @@ endif $(OUT)/%.o: src/%.c $(deps_emcc) $(VECHO) " CC\t$@\n" - $(Q)$(CC) -o $@ $(CFLAGS) $(CFLAGS_emcc) -c -MMD -MF $@.d $< + $(Q)$(CC) $(DEFINE_USE_ELF) -o $@ $(CFLAGS) $(CFLAGS_emcc) -c -MMD -MF $@.d $< $(BIN): $(OBJS) $(DEV_OBJS) $(VECHO) " LD\t$@\n" diff --git a/src/main.c b/src/main.c index 897bbe15..3d37a51f 100644 --- a/src/main.c +++ b/src/main.c @@ -209,7 +209,11 @@ int main(int argc, char **args) run_flag |= opt_prof_data << 2; vm_attr_t attr = { +#if RV32_HAS(SYSTEM) && !defined(USE_ELF) .mem_size = 512 * 1024 * 1024, /* FIXME: variadic size */ +#else + .mem_size = MEM_SIZE, /* FIXME: variadic size */ +#endif .stack_size = STACK_SIZE, .args_offset_size = ARGS_OFFSET_SIZE, .argc = prog_argc, @@ -217,7 +221,7 @@ int main(int argc, char **args) .log_level = 0, .run_flag = run_flag, .profile_output_file = prof_out_file, -#if RV32_HAS(SYSTEM) +#if RV32_HAS(SYSTEM) && !defined(USE_ELF) .data.system = malloc(sizeof(vm_system_t)), #else .data.user = malloc(sizeof(vm_user_t)), @@ -225,14 +229,14 @@ int main(int argc, char **args) .cycle_per_step = CYCLE_PER_STEP, .allow_misalign = opt_misaligned, }; -#if defined(USE_ELF) +#if RV32_HAS(SYSTEM) && !defined(USE_ELF) + assert(attr.data.system); + attr.data.system->kernel = "build/Image"; /* FIXME: hardcoded */ + attr.data.system->initrd = "build/rootfs.cpio"; /* FIXME: hardcoded */ + attr.data.system->dtb = "build/minimal.dtb"; /* FIXME: hardcoded */ +#else assert(attr.data.user); attr.data.user->elf_program = opt_prog_name; -#elif RV32_HAS(SYSTEM) - assert(attr.data.system); - attr.data.system->kernel = "build/Image"; /* FIXME: hardcoded */ - attr.data.system->initrd = "build/rootfs.cpio";/* FIXME: hardcoded */ - attr.data.system->dtb = "build/minimal.dtb";/* FIXME: hardcoded */ #endif /* create the RISC-V runtime */ diff --git a/src/riscv.c b/src/riscv.c index 8e3ec098..6596b286 100644 --- a/src/riscv.c +++ b/src/riscv.c @@ -307,6 +307,8 @@ riscv_t *rv_create(riscv_user_t rv_attr) elf_delete(elf); #if RV32_HAS(SYSTEM) + /* this variable has external linkage to mmu_io defined in system.c */ + extern riscv_io_t mmu_io; /* install the MMU I/O handlers */ memcpy(&rv->io, &mmu_io, sizeof(riscv_io_t)); #else @@ -333,7 +335,7 @@ riscv_t *rv_create(riscv_user_t rv_attr) memcpy(&rv->io, &io, sizeof(riscv_io_t)); #endif /* RV32_HAS(SYSTEM) */ } -#if RV32_HAS(SYSTEM) && !defined(USE_ELF) +#if RV32_HAS(SYSTEM) else { /* *-----------------------------------------* * | Memory layout | @@ -464,7 +466,7 @@ void rv_run(riscv_t *rv) vm_attr_t *attr = PRIV(rv); assert(attr && -#if RV32_HAS(SYSTEM) +#if RV32_HAS(SYSTEM) && !defined(USE_ELF) attr->data.system && attr->data.system->kernel && attr->data.system->initrd && attr->data.system->dtb #else