#*************************************************************************************** # Copyright (c) 2014-2022 Zihao Yu, Nanjing University # # NEMU is licensed under Mulan PSL v2. # You can use this software according to the terms and conditions of the Mulan PSL v2. # You may obtain a copy of Mulan PSL v2 at: # http://license.coscl.org.cn/MulanPSL2 # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. # # See the Mulan PSL v2 for more details. #**************************************************************************************/
# Sanity check ifeq ($(wildcard$(NEMU_HOME)/src/nemu-main.c),) $(error NEMU_HOME=$(NEMU_HOME) is not a NEMU repo) endif
# Include variables and rules generated by menuconfig -include$(NEMU_HOME)/include/config/auto.conf -include$(NEMU_HOME)/include/config/auto.conf.cmd
remove_quote = $(patsubst "%",%,$(1))
# Extract variabls from menuconfig GUEST_ISA ?= $(call remove_quote,$(CONFIG_ISA)) ENGINE ?= $(call remove_quote,$(CONFIG_ENGINE)) NAME = $(GUEST_ISA)-nemu-$(ENGINE)
# Include all filelist.mk to merge file lists FILELIST_MK = $(shell find -L ./src -name "filelist.mk") include$(FILELIST_MK)
# Filter out directories and files in blacklist to obtain the final set of source files DIRS-BLACKLIST-y += $(DIRS-BLACKLIST) SRCS-BLACKLIST-y += $(SRCS-BLACKLIST) $(shell find -L $(DIRS-BLACKLIST-y) -name "*.c") SRCS-y += $(shell find -L $(DIRS-y) -name "*.c") SRCS = $(filter-out $(SRCS-BLACKLIST-y),$(SRCS-y))
# Include rules for menuconfig include$(NEMU_HOME)/scripts/config.mk
ifdef CONFIG_TARGET_AM include$(AM_HOME)/Makefile LINKAGE += $(ARCHIVES) else # Include rules to build NEMU include$(NEMU_HOME)/scripts/native.mk endif
由于我们的 nemu 依然要在 native 上跑,因此这里依然要 native.mk 来干这事。编译好了之后,设置 IMG 为刚才编译的 bin,就好了:
$ make ARCH=riscv32-nemu ALL=add run # Building add-run [riscv32-nemu] + CC tests/add.c # Building am-archive [riscv32-nemu] + CC src/platform/nemu/trm.c + CC src/platform/nemu/ioe/ioe.c + CC src/platform/nemu/ioe/timer.c + CC src/platform/nemu/ioe/input.c + CC src/platform/nemu/ioe/gpu.c + CC src/platform/nemu/ioe/audio.c + CC src/platform/nemu/ioe/disk.c + CC src/platform/nemu/mpe.c + AS src/riscv/nemu/start.S + CC src/riscv/nemu/cte.c + AS src/riscv/nemu/trap.S + CC src/riscv/nemu/vme.c + AR -> build/am-riscv32-nemu.a # Building klib-archive [riscv32-nemu] + CC src/stdlib.c + CC src/string.c + CC src/int64.c + CC src/stdio.c + CC src/cpp.c + AR -> build/klib-riscv32-nemu.a + LD -> build/add-riscv32-nemu.elf # Creating image [riscv32-nemu] + OBJCOPY -> build/add-riscv32-nemu.bin + CC src/device/device.c + CC src/device/alarm.c + CC src/device/intr.c + CC src/device/serial.c + CC src/device/timer.c + CC src/device/keyboard.c + CC src/device/vga.c + CC src/device/audio.c + CC src/device/disk.c + CC src/nemu-main.c + CC src/engine/interpreter/init.c + CC src/engine/interpreter/hostcall.c + CC src/isa/riscv32/system/mmu.c + CC src/isa/riscv32/system/intr.c + CC src/isa/riscv32/inst.c + CC src/isa/riscv32/init.c + CC src/isa/riscv32/difftest/dut.c + CC src/isa/riscv32/logo.c + CC src/isa/riscv32/reg.c + CC src/device/io/port-io.c + CC src/device/io/mmio.c + CC src/device/io/map.c + CC src/cpu/difftest/dut.c + CC src/cpu/difftest/ref.c + CC src/cpu/cpu-exec.c + CC src/monitor/sdb/expr.c + CC src/monitor/sdb/watchpoint.c + CC src/monitor/sdb/sdb.c + CC src/monitor/monitor.c + CC src/utils/timer.c + CC src/utils/trace.c + CC src/utils/log.c + CC src/utils/state.c + CC src/memory/vaddr.c + CC src/memory/paddr.c + LD /home/luyoung/ysyx-workbench/nemu/build/riscv32-nemu-interpreter