2018-05-21 20:31:50 +04:00
|
|
|
# Examples:
|
|
|
|
# make run Run in debug
|
2018-07-04 12:23:11 +04:00
|
|
|
# make justrun Run in debug without build
|
2018-05-21 20:31:50 +04:00
|
|
|
# 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
|
2018-05-21 20:31:50 +04:00
|
|
|
# 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
|
2017-04-11 11:02:09 +04:00
|
|
|
kernel := build/kernel-$(arch).bin
|
|
|
|
iso := build/os-$(arch).iso
|
2017-04-11 20:23:27 +04:00
|
|
|
target ?= $(arch)-blog_os
|
2018-07-04 12:23:11 +04:00
|
|
|
ifeq ($(arch), riscv32)
|
2018-07-03 18:27:55 +04:00
|
|
|
target := riscv32i-unknown-none
|
|
|
|
endif
|
2018-05-21 20:31:50 +04:00
|
|
|
mode ?= debug
|
2018-07-04 12:23:11 +04:00
|
|
|
rust_lib := target/$(target)/$(mode)/librust_ucore.a
|
2017-04-11 11:02:09 +04:00
|
|
|
|
2018-04-04 16:56:56 +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, \
|
|
|
|
build/arch/$(arch)/boot/%.o, $(assembly_source_files))
|
2018-05-21 18:49:22 +04:00
|
|
|
user_image_files := $(wildcard user/*.img)
|
|
|
|
user_object_files := $(patsubst user/%.img, build/user/%.o, $(user_image_files))
|
2018-05-23 20:25:27 +04:00
|
|
|
SFSIMG := user/ucore32.img
|
|
|
|
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback
|
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
|
2018-04-28 06:40:31 +04:00
|
|
|
|
|
|
|
ifdef link_user
|
|
|
|
features := $(features) link_user_program
|
|
|
|
assembly_object_files := $(assembly_object_files) $(user_object_files)
|
|
|
|
endif
|
|
|
|
|
2018-04-09 17:20:47 +04:00
|
|
|
ifdef travis
|
2018-04-17 20:07:43 +04:00
|
|
|
test := 1
|
|
|
|
features := $(features) qemu_auto_exit
|
2018-04-09 17:20:47 +04:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef test
|
2018-04-17 20:07:43 +04:00
|
|
|
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
|
|
|
|
2018-05-20 11:37:48 +04:00
|
|
|
ifdef int
|
|
|
|
qemu_opts := $(qemu_opts) -d int
|
|
|
|
endif
|
|
|
|
|
2018-05-21 20:31:50 +04:00
|
|
|
build_args := --target $(target) --features "$(features)"
|
|
|
|
|
|
|
|
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)
|
|
|
|
prefix := riscv32-unknown-elf-
|
|
|
|
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-04-02 13:48:07 +04:00
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
.PHONY: all clean run iso build asm doc justrun
|
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
|
|
|
|
2018-05-21 12:05:36 +04:00
|
|
|
doc:
|
|
|
|
@cargo rustdoc -- --document-private-items
|
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
run: $(iso) justrun
|
|
|
|
|
|
|
|
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-05-18 07:49:27 +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
|
|
|
|
|
2018-05-21 20:31:50 +04:00
|
|
|
asm:
|
2018-04-12 19:44:25 +04:00
|
|
|
@$(objdump) -dS $(kernel) | less
|
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
build/os-x86_64.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
|
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
build/os-riscv32.iso: $(kernel)
|
|
|
|
@cd riscv-pk && \
|
|
|
|
mkdir -p build && \
|
|
|
|
cd build && \
|
|
|
|
../configure \
|
|
|
|
--enable-logo \
|
|
|
|
--prefix=$(RISCV) \
|
|
|
|
--disable-fp-emulation \
|
|
|
|
--host=riscv32-unknown-elf \
|
|
|
|
--with-payload=../../build/kernel-riscv32.bin && \
|
|
|
|
make && \
|
|
|
|
cp bbl ../../$@
|
|
|
|
|
|
|
|
$(kernel): $(rust_lib) $(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)
|
2017-04-11 20:23:27 +04:00
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
$(rust_lib):
|
2018-05-21 20:54:18 +04:00
|
|
|
@RUST_TARGET_PATH=$(shell pwd) CC=$(cc) xargo build $(build_args)
|
2017-04-11 11:02:09 +04:00
|
|
|
|
|
|
|
# compile assembly files
|
2018-07-04 12:23:11 +04:00
|
|
|
build/arch/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-05-21 18:49:22 +04:00
|
|
|
# make .o from .img file
|
|
|
|
build/user/%.o: user/%.img
|
|
|
|
@mkdir -p $(shell dirname $@)
|
|
|
|
@$(ld) -r -b binary $< -o $@
|
|
|
|
|
2018-04-02 11:28:32 +04:00
|
|
|
# used by docker_* targets
|
|
|
|
docker_image ?= blog_os
|
|
|
|
tag ?= 0.1
|
2018-04-19 11:57:34 +04:00
|
|
|
pwd ?= $(realpath ./)
|
|
|
|
ifeq ($(OS),Windows_NT)
|
2018-04-19 17:29:28 +04:00
|
|
|
uid ?= 0
|
|
|
|
gid ?= 0
|
|
|
|
innerpwd ?= /root/blog_os
|
2018-04-19 11:57:34 +04:00
|
|
|
else
|
2018-04-19 17:29:28 +04:00
|
|
|
uid ?= $(shell id -u)
|
|
|
|
gid ?= $(shell id -g)
|
2018-05-20 20:01:53 +04:00
|
|
|
innerpwd ?= $(pwd)
|
2018-04-19 11:57:34 +04:00
|
|
|
endif
|
|
|
|
docker_cargo_volume ?= blogos-$(uid)-$(gid)-cargo
|
|
|
|
docker_rustup_volume ?= blogos-$(uid)-$(gid)-rustup
|
|
|
|
docker_args ?= -e LOCAL_UID=$(uid) -e LOCAL_GID=$(gid) -v $(docker_cargo_volume):/usr/local/cargo -v $(docker_rustup_volume):/usr/local/rustup -v $(pwd):$(innerpwd) -w $(innerpwd)
|
2018-04-02 11:28:32 +04:00
|
|
|
docker_clean_args ?= $(docker_cargo_volume) $(docker_rustup_volume)
|
|
|
|
|
2018-04-19 11:57:34 +04:00
|
|
|
# docker_* targets
|
2018-04-02 11:28:32 +04:00
|
|
|
|
|
|
|
docker_build:
|
|
|
|
@docker build docker/ -t $(docker_image):$(tag)
|
|
|
|
|
2018-04-19 11:57:34 +04:00
|
|
|
docker_iso:
|
|
|
|
docker run --rm $(docker_args) $(docker_image):$(tag) make iso
|
2018-04-02 11:28:32 +04:00
|
|
|
|
|
|
|
docker_run: docker_iso
|
2018-04-04 16:56:56 +04:00
|
|
|
@qemu-system-$(arch) -cdrom $(iso) -s
|
2018-04-02 11:28:32 +04:00
|
|
|
|
|
|
|
docker_interactive:
|
2018-04-19 11:57:34 +04:00
|
|
|
@docker run -it --rm $(docker_args) $(docker_image):$(tag)
|
2018-04-02 11:28:32 +04:00
|
|
|
|
|
|
|
docker_clean:
|
2018-07-03 18:27:55 +04:00
|
|
|
@docker volume rm $(docker_clean_args)
|
|
|
|
|
|
|
|
docker_riscv:
|
|
|
|
@docker run -it --rm $(docker_args) riscv-rust
|