@@ -30,6 +30,34 @@ $(call set-feature, BLOCK_CHAINING)
3030ENABLE_SYSTEM ?= 0
3131$(call set-feature, SYSTEM)
3232
33+ # Definition that bridges:
34+ # Device Tree(initrd, memory range)
35+ # src/io.c(memory init)
36+ # src/riscv.c(system emulation layout init)
37+ ifeq ($(call has, SYSTEM) , 1)
38+ ifeq ($(call has, ELF_LOADER) , 0)
39+ MiB = 1024*1024
40+ MEM_START ?= 0
41+ MEM_SIZE ?= 512 # unit in MiB
42+ DTB_SIZE ?= 1 # unit in MiB
43+ INITRD_SIZE ?= 8 # unit in MiB
44+
45+ compute_size = $(shell echo "obase=16; ibase=10; $(1 ) * $(MiB ) " | bc)
46+ REAL_MEM_SIZE = $(call compute_size, $(MEM_SIZE ) )
47+ REAL_DTB_SIZE = $(call compute_size, $(DTB_SIZE ) )
48+ REAL_INITRD_SIZE = $(call compute_size, $(INITRD_SIZE ) )
49+
50+ CFLAGS_dt += -DMEM_START=0x$(MEM_START ) \
51+ -DMEM_END=0x$(shell echo "obase=16; ibase=16; $(MEM_START ) +$(REAL_MEM_SIZE ) " | bc) \
52+ -DINITRD_START=0x$(shell echo "obase=16; ibase=16; \
53+ $(REAL_MEM_SIZE ) - $(call compute_size, ($(INITRD_SIZE ) +$(DTB_SIZE ) ) ) " | bc) \
54+ -DINITRD_END=0x$(shell echo "obase=16; ibase=16; \
55+ $(REAL_MEM_SIZE ) - $(call compute_size, $(DTB_SIZE ) ) - 1" | bc)
56+
57+ CFLAGS += -DMEM_SIZE=0x$(REAL_MEM_SIZE ) -DDTB_SIZE=0x$(REAL_DTB_SIZE ) -DINITRD_SIZE=0x$(REAL_INITRD_SIZE )
58+ endif
59+ endif
60+
3361# Enable link-time optimization (LTO)
3462ENABLE_LTO ?= 1
3563ifeq ($(call has, LTO) , 1)
@@ -149,6 +177,14 @@ LDFLAGS += $(shell pkg-config --libs SDL2_mixer)
149177endif
150178endif
151179
180+ # If SYSTEM is enabled and ELF_LOADER is not, then skip FULL4G bacause guestOS
181+ # has dedicated memory mapping range.
182+ ifeq ($(call has, SYSTEM) , 1)
183+ ifeq ($(call has, ELF_LOADER) , 0)
184+ override ENABLE_FULL4G := 0
185+ endif
186+ endif
187+
152188# Full access to a 4 GiB address space, necessitating more memory mapping
153189# during emulator initialization.
154190$(call set-feature, FULL4G)
0 commit comments