Skip to content

Commit

Permalink
Introduce ENABLE_USE_ELF
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChinYikMing committed Nov 2, 2024
1 parent 05d991d commit 6b5f105
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 11 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,34 @@ 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,
.argv = prog_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)),
#endif
.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 */
Expand Down
6 changes: 4 additions & 2 deletions src/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 |
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6b5f105

Please sign in to comment.