From 1140d32aaa16081c0a97b8876e5ecec9ba0bf553 Mon Sep 17 00:00:00 2001 From: equation314 Date: Fri, 26 Oct 2018 11:20:03 +0800 Subject: [PATCH] add arch=aarch64 & board=raspi3 to Makefile --- kernel/Cargo.toml | 2 + kernel/Makefile | 91 +++++++++++++++++++++---------------- kernel/aarch64-blog_os.json | 29 ++++++++++++ 3 files changed, 84 insertions(+), 38 deletions(-) create mode 100644 kernel/aarch64-blog_os.json diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 0afa030..7bde15d 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -8,6 +8,8 @@ use_apic = [] link_user_program = [] no_bbl = [] +board_raspi3 = [] + [profile.dev] # MUST >= 1 : Enable RVO to avoid stack overflow # MUST <= 1 : Avoid double fault at -O2 T_T diff --git a/kernel/Makefile b/kernel/Makefile index 0053184..9f54a19 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -8,13 +8,16 @@ # make clean Clean # # Options: -# arch = x86_64 | riscv32 +# arch = x86_64 | riscv32 | aarch64 # d = int | in_asm | ... QEMU debug info # mode = debug | release # LOG = off | error | warn | info | debug | trace -# board Only available on riscv32, build without bbl, run on board +# board = fpga Only available on riscv32, build without bbl, run on board +# | raspi3 Only available on aarch64, run on Raspberry Pi 3 Model B/B+ -arch ?= riscv32 +arch ?= aarch64 +board ?= raspi3 +prefix ?= $(arch)-none-elf mode ?= debug LOG ?= debug @@ -27,21 +30,41 @@ 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 SFSIMG := ../user/ucore32.img + +### qemu options ### ifeq ($(arch), x86_64) qemu_opts := \ -drive format=raw,file=$(bootimage) \ -drive format=raw,file=$(SFSIMG),media=disk,cache=writeback \ -smp 4 \ -serial mon:stdio \ - -device isa-debug-exit + -device isa-debug-exit \ + -nographic +else ifeq ($(arch), riscv32) +qemu_opts := \ + -machine virt \ + -nographic \ + -kernel $(bin) +else ifeq ($(arch), aarch64) +qemu_opts := \ + -machine $(board) \ + -serial null -serial mon:stdio \ + -nographic \ + -kernel $(bin) endif -ifeq ($(arch), riscv32) -qemu_opts := -machine virt -kernel $(bin) -nographic + +ifdef d +qemu_opts := $(qemu_opts) -d $(d) endif -ifdef board + + +### build args ### +ifeq ($(arch), riscv32) +ifeq ($(board), fpga) features := $(features) no_bbl endif +endif # Link user binaries at ../user ifdef link_user @@ -49,37 +72,25 @@ features := $(features) link_user_program assembly_object_files := $(assembly_object_files) $(user_obj) endif -ifdef d -qemu_opts := $(qemu_opts) -d $(d) -endif - +features := $(features) board_$(board) build_args := --target $(target).json --features "$(features)" ifeq ($(mode), release) build_args := $(build_args) --release endif -ifeq ($(OS),Windows_NT) -uname := Win32 -else -uname := $(shell uname) -endif -ifeq ($(uname), Darwin) -prefix := x86_64-elf- -endif -ifeq ($(arch), riscv32) -prefix := riscv64-unknown-elf- -endif -ld := $(prefix)ld -objdump := $(prefix)objdump -cc := $(prefix)gcc -as := $(prefix)as +### prefix ### +ld := $(prefix)-ld +objdump := $(prefix)-objdump +objcopy := $(prefix)-objcopy +cc := $(prefix)-gcc +as := $(prefix)-as .PHONY: all clean run build asm doc justrun kernel -all: $(kernel) +all: kernel clean: @cargo clean @@ -108,20 +119,24 @@ elf-h: @$(objdump) -h $(kernel) $(bin): kernel -ifdef board +ifeq ($(arch), riscv32) +ifeq ($(board), fpga) @cp $(kernel) $@ else @cd ../riscv-pk && \ - mkdir -p build && \ - cd build && \ - ../configure \ - --enable-32bit \ - --enable-logo \ - --disable-fp-emulation \ - --host=riscv64-unknown-elf \ - --with-payload=$(abspath $(kernel)) && \ - make && \ - cp bbl ../../kernel/$@ + mkdir -p build && \ + cd build && \ + ../configure \ + --enable-32bit \ + --enable-logo \ + --disable-fp-emulation \ + --host=riscv64-unknown-elf \ + --with-payload=$(abspath $(kernel)) && \ + make && \ + cp bbl ../../kernel/$@ +endif +else ifeq ($(arch), aarch64) + $(objcopy) $(kernel) -O binary $@ endif kernel: diff --git a/kernel/aarch64-blog_os.json b/kernel/aarch64-blog_os.json new file mode 100644 index 0000000..048db11 --- /dev/null +++ b/kernel/aarch64-blog_os.json @@ -0,0 +1,29 @@ +{ + "abi-blacklist": [ + "stdcall", + "fastcall", + "vectorcall", + "thiscall", + "win64", + "sysv64" + ], + "arch": "aarch64", + "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", + "executables": true, + "linker": "aarch64-none-elf-ld", + "linker-flavor": "ld", + "linker-is-gnu": true, + "llvm-target": "aarch64-unknown-none", + "no-compiler-rt": true, + "features": "+a53,+strict-align", + "max-atomic-width": 128, + "os": "none", + "panic": "abort", + "panic-strategy": "abort", + "position-independent-executables": true, + "target-c-int-width": "32", + "target-endian": "little", + "target-pointer-width": "64", + "target-family": "unix", + "disable-redzone": true +}