Skip to content

Commit d3c493d

Browse files
committed
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.
1 parent 3cd4460 commit d3c493d

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ jobs:
6767
- name: misalignment test in block emulation
6868
run: |
6969
make -C tests/system/alignment/
70-
make distclean && make ENABLE_EXT_C=0 ENABLE_SYSTEM=1 misalign-in-blk-emu -j$(nproc)
70+
make distclean && make ENABLE_USE_ELF=1 ENABLE_EXT_C=0 ENABLE_SYSTEM=1 misalign-in-blk-emu -j$(nproc)
7171
- name: MMU test
7272
run: |
7373
make -C tests/system/mmu/
74-
make distclean && make ENABLE_SYSTEM=1 mmu-test -j$(nproc)
74+
make distclean && make ENABLE_USE_ELF=1 ENABLE_SYSTEM=1 mmu-test -j$(nproc)
7575
- name: gdbstub test
7676
run: |
7777
make distclean && make ENABLE_GDBSTUB=1 gdbstub-test -j$(nproc)

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ CFLAGS += -include src/common.h
1515
# However, the Linux kernel emulation includes the Image, DT, and
1616
# root filesystem (rootfs). Therefore, the test suite needs this
1717
# flag to load the ELF and differentiate it from the kernel emulation.
18-
USE_ELF ?= 0
18+
ENABLE_USE_ELF ?= 0
19+
ifeq ($(call has, USE_ELF), 1)
20+
DEFINE_USE_ELF := -DUSE_ELF
21+
endif
1922

2023
ENABLE_SYSTEM ?= 0
2124
$(call set-feature, SYSTEM)
@@ -248,7 +251,7 @@ endif
248251

249252
$(OUT)/%.o: src/%.c $(deps_emcc)
250253
$(VECHO) " CC\t$@\n"
251-
$(Q)$(CC) -o $@ $(CFLAGS) $(CFLAGS_emcc) -c -MMD -MF $@.d $<
254+
$(Q)$(CC) $(DEFINE_USE_ELF) -o $@ $(CFLAGS) $(CFLAGS_emcc) -c -MMD -MF $@.d $<
252255

253256
$(BIN): $(OBJS) $(DEV_OBJS)
254257
$(VECHO) " LD\t$@\n"

src/main.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,30 +209,34 @@ int main(int argc, char **args)
209209
run_flag |= opt_prof_data << 2;
210210

211211
vm_attr_t attr = {
212+
#if RV32_HAS(SYSTEM) && !defined(USE_ELF)
212213
.mem_size = 512 * 1024 * 1024, /* FIXME: variadic size */
214+
#else
215+
.mem_size = MEM_SIZE, /* FIXME: variadic size */
216+
#endif
213217
.stack_size = STACK_SIZE,
214218
.args_offset_size = ARGS_OFFSET_SIZE,
215219
.argc = prog_argc,
216220
.argv = prog_args,
217221
.log_level = 0,
218222
.run_flag = run_flag,
219223
.profile_output_file = prof_out_file,
220-
#if RV32_HAS(SYSTEM)
224+
#if RV32_HAS(SYSTEM) && !defined(USE_ELF)
221225
.data.system = malloc(sizeof(vm_system_t)),
222226
#else
223227
.data.user = malloc(sizeof(vm_user_t)),
224228
#endif
225229
.cycle_per_step = CYCLE_PER_STEP,
226230
.allow_misalign = opt_misaligned,
227231
};
228-
#if defined(USE_ELF)
232+
#if RV32_HAS(SYSTEM) && !defined(USE_ELF)
233+
assert(attr.data.system);
234+
attr.data.system->kernel = "build/Image"; /* FIXME: hardcoded */
235+
attr.data.system->initrd = "build/rootfs.cpio"; /* FIXME: hardcoded */
236+
attr.data.system->dtb = "build/minimal.dtb"; /* FIXME: hardcoded */
237+
#else
229238
assert(attr.data.user);
230239
attr.data.user->elf_program = opt_prog_name;
231-
#elif RV32_HAS(SYSTEM)
232-
assert(attr.data.system);
233-
attr.data.system->kernel = "build/Image"; /* FIXME: hardcoded */
234-
attr.data.system->initrd = "build/rootfs.cpio";/* FIXME: hardcoded */
235-
attr.data.system->dtb = "build/minimal.dtb";/* FIXME: hardcoded */
236240
#endif
237241

238242
/* create the RISC-V runtime */

src/riscv.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ riscv_t *rv_create(riscv_user_t rv_attr)
307307
elf_delete(elf);
308308

309309
#if RV32_HAS(SYSTEM)
310+
/* this variable has external linkage to mmu_io defined in system.c */
311+
extern riscv_io_t mmu_io;
310312
/* install the MMU I/O handlers */
311313
memcpy(&rv->io, &mmu_io, sizeof(riscv_io_t));
312314
#else
@@ -333,7 +335,7 @@ riscv_t *rv_create(riscv_user_t rv_attr)
333335
memcpy(&rv->io, &io, sizeof(riscv_io_t));
334336
#endif /* RV32_HAS(SYSTEM) */
335337
}
336-
#if RV32_HAS(SYSTEM) && !defined(USE_ELF)
338+
#if RV32_HAS(SYSTEM)
337339
else {
338340
/* *-----------------------------------------*
339341
* | Memory layout |
@@ -464,7 +466,7 @@ void rv_run(riscv_t *rv)
464466

465467
vm_attr_t *attr = PRIV(rv);
466468
assert(attr &&
467-
#if RV32_HAS(SYSTEM)
469+
#if RV32_HAS(SYSTEM) && !defined(USE_ELF)
468470
attr->data.system && attr->data.system->kernel &&
469471
attr->data.system->initrd && attr->data.system->dtb
470472
#else

0 commit comments

Comments
 (0)