2018-08-07 12:11:48 +04:00
|
|
|
# Commands:
|
|
|
|
# make build Build
|
|
|
|
# make run Build and run in QEMU
|
|
|
|
# make justrun Run the last build
|
2018-05-21 20:31:50 +04:00
|
|
|
# make doc Generate docs
|
|
|
|
# make asm Open the deassemble file of the last build
|
2018-08-07 12:11:48 +04:00
|
|
|
# make elf-h Open 'objdump -h' of the last build
|
2018-05-21 20:31:50 +04:00
|
|
|
# make clean Clean
|
2018-08-07 12:11:48 +04:00
|
|
|
#
|
|
|
|
# Options:
|
|
|
|
# arch = x86_64 | riscv32
|
|
|
|
# d = int | in_asm | ... QEMU debug info
|
|
|
|
# mode = debug | release
|
|
|
|
# LOG = off | error | warn | info | debug | trace
|
2018-10-14 09:50:59 +04:00
|
|
|
# smp SMP core number
|
2018-08-07 12:11:48 +04:00
|
|
|
# board Only available on riscv32, build without bbl, run on board
|
2018-05-21 20:31:50 +04:00
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
arch ?= riscv32
|
2018-08-07 12:11:48 +04:00
|
|
|
mode ?= debug
|
|
|
|
LOG ?= debug
|
2018-10-14 09:50:59 +04:00
|
|
|
smp ?= 1
|
2018-08-07 12:11:48 +04:00
|
|
|
|
|
|
|
target := $(arch)-blog_os
|
2018-09-18 14:05:37 +04:00
|
|
|
kernel := target/$(target)/$(mode)/ucore
|
|
|
|
bin := target/$(target)/$(mode)/kernel.bin
|
|
|
|
bootimage := target/$(target)/bootimage.bin
|
|
|
|
|
2018-07-13 21:11:47 +04:00
|
|
|
user_bin_path := ../user/target/$(arch)-ucore/debug
|
2018-07-14 13:41:45 +04:00
|
|
|
user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(user_bin_path)/*.d))
|
|
|
|
user_obj := build/$(arch)/user.o
|
2018-07-13 08:25:39 +04:00
|
|
|
SFSIMG := ../user/ucore32.img
|
2018-07-14 13:41:45 +04:00
|
|
|
ifeq ($(arch), x86_64)
|
2018-09-18 14:05:37 +04:00
|
|
|
qemu_opts := \
|
|
|
|
-drive format=raw,file=$(bootimage) \
|
|
|
|
-drive format=raw,file=$(SFSIMG),media=disk,cache=writeback \
|
2018-10-14 09:50:59 +04:00
|
|
|
-smp $(smp) \
|
2018-09-18 14:05:37 +04:00
|
|
|
-serial mon:stdio \
|
|
|
|
-device isa-debug-exit
|
2018-07-14 13:41:45 +04:00
|
|
|
endif
|
2018-07-04 12:23:11 +04:00
|
|
|
ifeq ($(arch), riscv32)
|
2018-10-14 09:50:59 +04:00
|
|
|
qemu_opts := -machine virt -kernel $(bin) -nographic -smp cpus=$(smp)
|
2018-07-04 12:23:11 +04:00
|
|
|
endif
|
2018-04-09 17:20:47 +04:00
|
|
|
|
2018-08-07 12:11:48 +04:00
|
|
|
ifdef board
|
|
|
|
features := $(features) no_bbl
|
|
|
|
endif
|
2018-04-28 06:40:31 +04:00
|
|
|
|
2018-07-14 13:41:45 +04:00
|
|
|
# Link user binaries at ../user
|
2018-04-28 06:40:31 +04:00
|
|
|
ifdef link_user
|
|
|
|
features := $(features) link_user_program
|
2018-07-14 13:41:45 +04:00
|
|
|
assembly_object_files := $(assembly_object_files) $(user_obj)
|
|
|
|
endif
|
|
|
|
|
2018-08-05 13:50:56 +04:00
|
|
|
ifdef d
|
|
|
|
qemu_opts := $(qemu_opts) -d $(d)
|
2018-05-20 11:37:48 +04:00
|
|
|
endif
|
|
|
|
|
2018-08-04 12:20:25 +04:00
|
|
|
build_args := --target $(target).json --features "$(features)"
|
2018-05-21 20:31:50 +04:00
|
|
|
|
|
|
|
ifeq ($(mode), release)
|
|
|
|
build_args := $(build_args) --release
|
|
|
|
endif
|
|
|
|
|
2018-04-19 11:57:34 +04:00
|
|
|
ifeq ($(OS),Windows_NT)
|
2018-04-19 17:29:28 +04:00
|
|
|
uname := Win32
|
2018-04-19 11:57:34 +04:00
|
|
|
else
|
2018-04-19 17:29:28 +04:00
|
|
|
uname := $(shell uname)
|
2018-04-19 11:57:34 +04:00
|
|
|
endif
|
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
ifeq ($(uname), Darwin)
|
2018-04-17 20:07:43 +04:00
|
|
|
prefix := x86_64-elf-
|
2018-04-02 13:48:07 +04:00
|
|
|
endif
|
2018-07-04 12:23:11 +04:00
|
|
|
ifeq ($(arch), riscv32)
|
2018-10-14 09:50:59 +04:00
|
|
|
prefix := riscv32-unknown-elf-
|
2018-07-04 12:23:11 +04:00
|
|
|
endif
|
2018-04-02 13:48:07 +04:00
|
|
|
|
|
|
|
ld := $(prefix)ld
|
2018-04-12 19:44:25 +04:00
|
|
|
objdump := $(prefix)objdump
|
2018-04-12 20:54:13 +04:00
|
|
|
cc := $(prefix)gcc
|
2018-07-04 21:13:52 +04:00
|
|
|
as := $(prefix)as
|
2018-04-02 13:48:07 +04:00
|
|
|
|
2018-09-19 16:43:49 +04:00
|
|
|
.PHONY: all clean run build asm doc justrun kernel
|
2017-04-11 11:02:09 +04:00
|
|
|
|
|
|
|
all: $(kernel)
|
|
|
|
|
|
|
|
clean:
|
2018-09-18 14:05:37 +04:00
|
|
|
@cargo clean
|
2017-04-11 11:02:09 +04:00
|
|
|
|
2018-05-21 12:05:36 +04:00
|
|
|
doc:
|
|
|
|
@cargo rustdoc -- --document-private-items
|
|
|
|
|
2018-09-18 14:05:37 +04:00
|
|
|
run: build justrun
|
2018-07-04 12:23:11 +04:00
|
|
|
|
|
|
|
justrun:
|
2018-04-09 18:22:43 +04:00
|
|
|
@qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 11 ] # run qemu and assert it exit 11
|
2017-04-11 11:02:09 +04:00
|
|
|
|
2018-09-18 14:05:37 +04:00
|
|
|
debug: $(bin)
|
2018-05-18 07:49:27 +04:00
|
|
|
@qemu-system-$(arch) $(qemu_opts) -s -S &
|
|
|
|
|
2018-09-18 14:05:37 +04:00
|
|
|
ifeq ($(arch), x86_64)
|
2018-09-19 16:43:49 +04:00
|
|
|
build: kernel
|
2018-09-18 14:05:37 +04:00
|
|
|
else
|
|
|
|
build: $(bin)
|
|
|
|
endif
|
2018-04-09 17:20:47 +04:00
|
|
|
|
2018-05-21 20:31:50 +04:00
|
|
|
asm:
|
2018-04-12 19:44:25 +04:00
|
|
|
@$(objdump) -dS $(kernel) | less
|
|
|
|
|
2018-07-13 21:11:47 +04:00
|
|
|
elf-h:
|
|
|
|
@$(objdump) -h $(kernel)
|
|
|
|
|
2018-09-19 16:43:49 +04:00
|
|
|
$(bin): kernel
|
2018-08-07 12:11:48 +04:00
|
|
|
ifdef board
|
2018-09-18 14:05:37 +04:00
|
|
|
@cp $(kernel) $@
|
2018-08-07 12:11:48 +04:00
|
|
|
else
|
|
|
|
@cd ../riscv-pk && \
|
|
|
|
mkdir -p build && \
|
|
|
|
cd build && \
|
|
|
|
../configure \
|
|
|
|
--enable-32bit \
|
|
|
|
--enable-logo \
|
|
|
|
--disable-fp-emulation \
|
2018-10-14 09:50:59 +04:00
|
|
|
--host=riscv32-unknown-elf \
|
2018-09-18 14:05:37 +04:00
|
|
|
--with-payload=$(abspath $(kernel)) && \
|
2018-08-07 12:11:48 +04:00
|
|
|
make && \
|
|
|
|
cp bbl ../../kernel/$@
|
|
|
|
endif
|
2018-07-04 12:23:11 +04:00
|
|
|
|
2018-09-19 16:43:49 +04:00
|
|
|
kernel:
|
2018-09-18 14:05:37 +04:00
|
|
|
ifeq ($(arch), x86_64)
|
|
|
|
@bootimage build $(build_args)
|
|
|
|
else
|
|
|
|
@cargo xbuild $(build_args)
|
|
|
|
endif
|
2018-04-02 11:28:32 +04:00
|
|
|
|
2018-07-14 13:41:45 +04:00
|
|
|
# make user.o from binary files
|
|
|
|
$(user_obj): $(user_bins)
|
2018-07-13 21:11:47 +04:00
|
|
|
@cd $(user_bin_path) && \
|
2018-07-14 13:41:45 +04:00
|
|
|
$(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins)))
|