diff --git a/crate/riscv b/crate/riscv deleted file mode 160000 index a37a65f..0000000 --- a/crate/riscv +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a37a65fa13a00c5aa0068c3f2b5d55af6a37dd93 diff --git a/kernel/Makefile b/kernel/Makefile index 0e1a2e8..ef57cea 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -27,16 +27,20 @@ kernel := target/$(target)/$(mode)/ucore bin := target/$(target)/$(mode)/kernel.bin bootimage := target/$(target)/bootimage.bin -user_bin_path := ../user/target/$(arch)-ucore/debug +user_dir := ../user +user_bin_path := $(user_dir)/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 -SFSIMG := ../user/ucore32.img +sfsimg := $(user_dir)/build/user-$(arch).img + +export ARCH = $(arch) +export SFSIMG = $(sfsimg) ### qemu options ### ifeq ($(arch), x86_64) qemu_opts := \ -drive format=raw,file=$(bootimage) \ - -drive format=raw,file=$(SFSIMG),media=disk,cache=writeback \ + -drive format=raw,file=$(sfsimg),media=disk,cache=writeback \ -smp cores=$(smp) \ -serial mon:stdio \ -device isa-debug-exit \ @@ -99,7 +103,7 @@ cc := $(prefix)gcc as := $(prefix)as gdb := $(prefix)gdb -.PHONY: all clean run build asm doc justrun kernel +.PHONY: all clean run build asm doc justrun debug kernel install all: kernel @@ -112,10 +116,10 @@ doc: run: build justrun -justrun: +justrun: $(sfsimg) @qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 11 ] # run qemu and assert it exit 11 -debug: $(kernel) $(bin) +debug: $(kernel) $(bin) $(sfsimg) @qemu-system-$(arch) $(qemu_opts) -s -S & @sleep 1 @$(gdb) $(kernel) -x ../tools/gdbinit @@ -156,16 +160,25 @@ else ifeq ($(arch), aarch64) @$(objcopy) $(kernel) --strip-all -O binary $@ endif -kernel: ifeq ($(arch), x86_64) +kernel: @bootimage build $(build_args) else +kernel: $(sfsimg) +ifeq ($(arch), riscv32) @-patch -p0 -N -b \ $(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \ src/arch/riscv32/atomic.patch +endif @CC=$(cc) cargo xbuild $(build_args) endif + + +### user programs ### +$(sfsimg): + @cd $(user_dir) && make sfsimg + # make user.o from binary files $(user_obj): $(user_bins) @cd $(user_bin_path) && \ diff --git a/user/Makefile b/user/Makefile index 185ca0f..9b0648b 100644 --- a/user/Makefile +++ b/user/Makefile @@ -1,5 +1,55 @@ -# arch = {riscv32, x86_64} -arch := riscv32 +# arch = {riscv32, x86_64, aarch64} +# mode = {debug, release} +arch ?= riscv32 +mode ?= debug -all: - cargo xbuild --target $(arch)-ucore.json \ No newline at end of file +rust_src_dir := src/bin +rust_bin_path := target/$(arch)-ucore/$(mode) +user_rust_bins := $(patsubst $(rust_src_dir)/%.rs, $(rust_bin_path)/%, $(wildcard $(rust_src_dir)/*.rs)) +c_src_dir := +c_bin_path := +user_c_bins := +user_bins := $(user_rust_bins) $(user_c_bins) + +build_path := build +sfsroot := $(build_path)/sfsroot-$(arch) +sfsimg := $(build_path)/user-$(arch).img + +mksfs := mksfs + +build_args := --target $(arch)-ucore.json +ifeq ($(mode), release) +build_args := $(build_args) --release +endif + +.PHONY: all clean build-rust build-c build mksfs sfsimg + +all: $(sfsimg) + +build-rust: + @echo Building user rust programs + @cargo xbuild $(build_args) + +build-c: + @echo Building user C programs + +build: build-rust build-c + +mksfs: +ifeq ($(shell which $(mksfs)),) + @cargo install --git https://github.com/wangrunji0408/SimpleFileSystem-Rust --features="std" +endif + +$(sfsroot): build + @mkdir -p $(sfsroot)/ + @cp $(user_bins) $(sfsroot)/ + +$(sfsimg): mksfs $(sfsroot) + @echo Creating SFS image at $@ + @$(mksfs) zip $(sfsroot) $@ + +sfsimg: $(sfsimg) + +clean: + @cargo clean + @rm -rf $(build_path) diff --git a/user/x86_64-ucore.json b/user/x86_64-ucore.json index c587146..6510efa 100644 --- a/user/x86_64-ucore.json +++ b/user/x86_64-ucore.json @@ -7,8 +7,9 @@ "target-c-int-width": "32", "os": "none", "executables": true, + "linker": "rust-lld", "linker-flavor": "ld.lld", "panic-strategy": "abort", "disable-redzone": true, "features": "-mmx,-sse,+soft-float" -} \ No newline at end of file +}