You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
|
|
TARGET := riscv64gc-unknown-none-elf
|
|
|
|
KERNEL_ENTRY := 0x80200000
|
|
|
|
MODE := release
|
|
|
|
KERNEL_ELF := target/$(TARGET)/$(MODE)/os
|
|
|
|
KERNEL_BIN := $(KERNEL_ELF).bin
|
|
|
|
QEMU_CMD_PATH := /Users/zhangxinyu/Downloads/qemu-7.0.0/build/qemu-system-riscv64
|
|
|
|
OBJDUMP := rust-objdump --arch-name=riscv64
|
|
|
|
OBJCOPY := rust-objcopy --binary-architecture=riscv64
|
|
|
|
|
|
|
|
RUST_FLAGS := -Clink-arg=-Tsrc/linker.ld # 使用我们自己的链接脚本
|
|
|
|
RUST_FLAGS += -Cforce-frame-pointers=yes # 强制编译器生成帧指针
|
|
|
|
RUST_FLAGS:=$(strip ${RUST_FLAGS})
|
|
|
|
|
|
|
|
# 编译elf文件
|
|
|
|
build:
|
|
|
|
CARGO_BUILD_RUSTFLAGS="$(RUST_FLAGS)" \
|
|
|
|
cargo build --$(MODE) --target=$(TARGET)
|
|
|
|
|
|
|
|
# 丢弃内核可执行elf文件中的元数据得到内核镜像
|
|
|
|
$(KERNEL_BIN): build
|
|
|
|
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@
|
|
|
|
|
|
|
|
|
|
|
|
run:build $(KERNEL_BIN)
|
|
|
|
$(QEMU_CMD_PATH) \
|
|
|
|
-machine virt \
|
|
|
|
-nographic \
|
|
|
|
-bios ../bootloader/rustsbi-qemu.bin \
|
|
|
|
-device loader,file=$(KERNEL_ELF),addr=$(KERNEL_ENTRY) \
|
|
|
|
-s -S
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf ./target
|