1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 08:26:17 +04:00
rCore/kernel/Makefile

165 lines
4.0 KiB
Makefile
Raw Normal View History

# Examples:
# make run Run in debug
2018-07-04 12:23:11 +04:00
# make justrun Run in debug without build
# make run int=1 Run with interrupt info by QEMU
# make run mode=release Run in release
2018-05-21 21:11:37 +04:00
# make run LOG=error Run with log level: error
# LOG = off | error | warn | info | debug | trace
# make doc Generate docs
# make asm Open the deassemble file of the last build
# make clean Clean
2018-07-04 12:23:11 +04:00
arch ?= riscv32
2018-07-14 11:09:13 +04:00
kernel := build/$(arch)/kernel.bin
iso := build/$(arch)/os.iso
target ?= $(arch)-blog_os
mode ?= debug
rust_lib := target/$(target)/$(mode)/ucore
2017-04-11 11:02:09 +04:00
boot_src := src/arch/$(arch)/boot
linker_script := $(boot_src)/linker.ld
grub_cfg := $(boot_src)/grub.cfg
assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \
2018-07-14 11:09:13 +04:00
build/$(arch)/boot/%.o, $(assembly_source_files))
2018-07-13 21:11:47 +04:00
user_bin_path := ../user/target/$(arch)-ucore/debug
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
ifeq ($(arch), x86_64)
2018-05-23 20:25:27 +04:00
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback
endif
2018-07-04 12:23:11 +04:00
ifeq ($(arch), riscv32)
qemu_opts := -machine virt -kernel $(iso) -nographic
endif
2018-04-14 21:01:44 +04:00
features := use_apic
2018-04-09 17:20:47 +04:00
2018-05-21 21:11:37 +04:00
LOG ?= debug
# Link user binaries at ../user
ifdef link_user
features := $(features) link_user_program
assembly_object_files := $(assembly_object_files) $(user_obj)
endif
# Link user-riscv.img for RV32
ifeq ($(arch), riscv32)
riscv_user_img_obj := build/riscv32/user-riscv.o
assembly_object_files := $(assembly_object_files) $(riscv_user_img_obj)
endif
2018-04-09 17:20:47 +04:00
ifdef travis
test := 1
features := $(features) qemu_auto_exit
2018-04-09 17:20:47 +04:00
endif
ifdef test
features := $(features) test
# enable shutdown inside the qemu
qemu_opts := $(qemu_opts) -device isa-debug-exit
2018-04-09 17:20:47 +04:00
endif
2017-04-11 11:02:09 +04:00
ifdef int
qemu_opts := $(qemu_opts) -d int
endif
build_args := --target $(target).json --features "$(features)"
ifeq ($(mode), release)
build_args := $(build_args) --release
endif
2018-04-19 11:57:34 +04:00
ifeq ($(OS),Windows_NT)
uname := Win32
2018-04-19 11:57:34 +04:00
else
uname := $(shell uname)
2018-04-19 11:57:34 +04:00
endif
2018-07-04 12:23:11 +04:00
ifeq ($(uname), Darwin)
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-08-04 19:02:50 +04:00
prefix := riscv64-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-07-04 18:04:59 +04:00
.PHONY: all clean run iso build asm doc justrun kernel
2017-04-11 11:02:09 +04:00
all: $(kernel)
clean:
2018-04-12 19:44:25 +04:00
@rm -r build target
2017-04-11 11:02:09 +04:00
doc:
@cargo rustdoc -- --document-private-items
2018-07-04 12:23:11 +04:00
run: $(iso) justrun
justrun:
@qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 11 ] # run qemu and assert it exit 11
2017-04-11 11:02:09 +04:00
debug: $(iso)
@qemu-system-$(arch) $(qemu_opts) -s -S &
2017-04-11 11:02:09 +04:00
iso: $(iso)
2018-04-09 17:20:47 +04:00
build: iso
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-07-14 11:09:13 +04:00
build/x86_64/os.iso: $(kernel) $(grub_cfg)
2017-04-11 11:02:09 +04:00
@mkdir -p build/isofiles/boot/grub
@cp $(kernel) build/isofiles/boot/kernel.bin
@cp $(grub_cfg) build/isofiles/boot/grub
@grub-mkrescue -o $(iso) build/isofiles 2> /dev/null
@rm -r build/isofiles
build/riscv32/os.iso: kernel
2018-07-13 08:25:39 +04:00
@cd ../riscv-pk && \
2018-07-04 12:23:11 +04:00
mkdir -p build && \
cd build && \
../configure \
2018-08-04 19:02:50 +04:00
--enable-32bit \
2018-07-04 12:23:11 +04:00
--enable-logo \
--disable-fp-emulation \
2018-08-04 19:02:50 +04:00
--host=riscv64-unknown-elf \
--with-payload=$(abspath $(rust_lib)) && \
2018-07-04 12:23:11 +04:00
make && \
2018-07-13 08:25:39 +04:00
cp bbl ../../kernel/$@
2018-07-04 12:23:11 +04:00
2018-07-04 18:04:59 +04:00
$(kernel): kernel $(assembly_object_files) $(linker_script)
2018-04-02 13:48:07 +04:00
@$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \
2018-07-04 12:23:11 +04:00
$(assembly_object_files) $(rust_lib)
2018-07-04 18:04:59 +04:00
kernel:
@CC=$(cc) cargo xbuild $(build_args)
2017-04-11 11:02:09 +04:00
# compile assembly files
2018-07-14 11:09:13 +04:00
build/x86_64/boot/%.o: $(boot_src)/%.asm
2017-04-11 11:02:09 +04:00
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@
2018-04-02 11:28:32 +04:00
2018-07-14 11:09:13 +04:00
build/riscv32/boot/%.o: $(boot_src)/%.asm
2018-07-04 21:13:52 +04:00
@mkdir -p $(shell dirname $@)
@$(as) -march=rv32i $< -o $@
# make user.o from binary files
$(user_obj): $(user_bins)
2018-07-13 21:11:47 +04:00
@cd $(user_bin_path) && \
$(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins)))
$(riscv_user_img_obj): ../user/user-riscv.img
@cd ../user && $(ld) -o $(abspath $@) -b binary $(notdir $<)
# patch Rust core for RISCV32I atomic
patch-core:
2018-07-16 09:37:26 +04:00
@patch -p0 /rust/rust-riscv-rust-1.26.0-1-dev/src/libcore/sync/atomic.rs src/arch/riscv32/atomic.patch