2020-11-11 12:50:00 +04:00
|
|
|
# Building
|
|
|
|
TARGET := riscv64gc-unknown-none-elf
|
|
|
|
MODE := release
|
|
|
|
KERNEL_ELF := target/$(TARGET)/$(MODE)/os
|
|
|
|
KERNEL_BIN := $(KERNEL_ELF).bin
|
|
|
|
DISASM_TMP := target/$(TARGET)/$(MODE)/asm
|
2020-12-19 20:52:14 +04:00
|
|
|
FS_IMG := ../user/target/$(TARGET)/$(MODE)/fs.img
|
2021-02-26 08:06:55 +04:00
|
|
|
APPS := ../user/src/bin/*
|
2020-11-11 12:50:00 +04:00
|
|
|
|
|
|
|
# BOARD
|
2022-12-13 19:52:27 +04:00
|
|
|
BOARD := qemu
|
2021-02-02 14:00:55 +04:00
|
|
|
SBI ?= rustsbi
|
|
|
|
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
|
2021-02-07 14:39:52 +04:00
|
|
|
|
2022-12-19 15:55:58 +04:00
|
|
|
# GUI
|
|
|
|
GUI ?= off
|
|
|
|
ifeq ($(GUI), off)
|
|
|
|
GUI_OPTION := -display none
|
|
|
|
endif
|
|
|
|
|
2022-04-17 02:59:10 +04:00
|
|
|
# Building mode argument
|
|
|
|
ifeq ($(MODE), release)
|
|
|
|
MODE_ARG := --release
|
|
|
|
endif
|
|
|
|
|
2021-02-07 14:39:52 +04:00
|
|
|
# KERNEL ENTRY
|
2023-03-30 18:53:41 +04:00
|
|
|
KERNEL_ENTRY_PA := 0x80200000
|
2020-11-11 12:50:00 +04:00
|
|
|
|
|
|
|
# Binutils
|
|
|
|
OBJDUMP := rust-objdump --arch-name=riscv64
|
|
|
|
OBJCOPY := rust-objcopy --binary-architecture=riscv64
|
|
|
|
|
|
|
|
# Disassembly
|
|
|
|
DISASM ?= -x
|
|
|
|
|
2022-05-13 14:19:17 +04:00
|
|
|
# Run usertests or usershell
|
|
|
|
TEST ?=
|
|
|
|
|
2022-12-13 19:52:27 +04:00
|
|
|
build: env $(KERNEL_BIN) fs-img
|
2021-01-02 06:05:33 +04:00
|
|
|
|
|
|
|
env:
|
2021-02-02 14:00:55 +04:00
|
|
|
(rustup target list | grep "riscv64gc-unknown-none-elf (installed)") || rustup target add $(TARGET)
|
2022-07-25 07:47:07 +04:00
|
|
|
cargo install cargo-binutils
|
2021-02-02 14:00:55 +04:00
|
|
|
rustup component add rust-src
|
|
|
|
rustup component add llvm-tools-preview
|
2020-12-19 20:52:14 +04:00
|
|
|
|
2020-11-11 12:50:00 +04:00
|
|
|
$(KERNEL_BIN): kernel
|
|
|
|
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@
|
|
|
|
|
2021-07-21 15:10:04 +04:00
|
|
|
fs-img: $(APPS)
|
2022-05-13 14:19:17 +04:00
|
|
|
@cd ../user && make build TEST=$(TEST)
|
2021-11-27 13:57:11 +04:00
|
|
|
@rm -f $(FS_IMG)
|
2021-02-23 23:34:59 +04:00
|
|
|
@cd ../easy-fs-fuse && cargo run --release -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/
|
2020-12-19 20:52:14 +04:00
|
|
|
|
2020-12-20 09:52:38 +04:00
|
|
|
$(APPS):
|
|
|
|
|
2020-11-11 12:50:00 +04:00
|
|
|
kernel:
|
2021-02-07 14:39:52 +04:00
|
|
|
@echo Platform: $(BOARD)
|
|
|
|
@cp src/linker-$(BOARD).ld src/linker.ld
|
2022-12-13 19:52:27 +04:00
|
|
|
@cargo build --release
|
2021-02-07 14:39:52 +04:00
|
|
|
@rm src/linker.ld
|
2020-11-11 12:50:00 +04:00
|
|
|
|
|
|
|
clean:
|
|
|
|
@cargo clean
|
|
|
|
|
|
|
|
disasm: kernel
|
|
|
|
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) | less
|
|
|
|
|
|
|
|
disasm-vim: kernel
|
|
|
|
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) > $(DISASM_TMP)
|
2022-03-04 21:02:32 +04:00
|
|
|
@nvim $(DISASM_TMP)
|
2020-11-11 12:50:00 +04:00
|
|
|
@rm $(DISASM_TMP)
|
|
|
|
|
2023-01-03 06:05:40 +04:00
|
|
|
run: run-inner
|
2023-01-02 07:28:06 +04:00
|
|
|
|
|
|
|
run-inner-none: build
|
|
|
|
@qemu-system-riscv64 \
|
|
|
|
-M 128m \
|
|
|
|
-machine virt \
|
|
|
|
-bios none \
|
|
|
|
$(GUI_OPTION) \
|
|
|
|
-kernel $(KERNEL_ELF) \
|
|
|
|
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
|
|
|
|
-device virtio-blk-device,drive=x0 \
|
|
|
|
# -device virtio-gpu-device \
|
|
|
|
-device virtio-keyboard-device \
|
|
|
|
-device virtio-mouse-device \
|
2023-02-06 15:21:43 +04:00
|
|
|
-device virtio-net-device,netdev=net0 \
|
2023-03-03 12:58:07 +04:00
|
|
|
-netdev user,id=net0,hostfwd=udp::6200-:2000,hostfwd=tcp::6201-:80 \
|
2023-01-02 07:28:06 +04:00
|
|
|
-serial stdio
|
2021-02-08 07:22:25 +04:00
|
|
|
|
2020-11-11 12:50:00 +04:00
|
|
|
run-inner: build
|
|
|
|
@qemu-system-riscv64 \
|
2022-06-22 20:11:44 +04:00
|
|
|
-M 128m \
|
2020-11-11 12:50:00 +04:00
|
|
|
-machine virt \
|
|
|
|
-bios $(BOOTLOADER) \
|
2022-12-19 15:55:58 +04:00
|
|
|
$(GUI_OPTION) \
|
2020-12-16 06:18:38 +04:00
|
|
|
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) \
|
2020-12-19 20:52:14 +04:00
|
|
|
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
|
2022-06-22 20:11:44 +04:00
|
|
|
-device virtio-blk-device,drive=x0 \
|
|
|
|
-device virtio-gpu-device \
|
|
|
|
-device virtio-keyboard-device \
|
|
|
|
-device virtio-mouse-device \
|
2023-02-06 15:21:43 +04:00
|
|
|
-device virtio-net-device,netdev=net0 \
|
2023-03-03 12:58:07 +04:00
|
|
|
-netdev user,id=net0,hostfwd=udp::6200-:2000,hostfwd=tcp::6201-:80 \
|
2022-06-22 20:11:44 +04:00
|
|
|
-serial stdio
|
2020-11-11 12:50:00 +04:00
|
|
|
|
2022-12-19 15:55:58 +04:00
|
|
|
fdt:
|
|
|
|
@qemu-system-riscv64 -M 128m -machine virt,dumpdtb=virt.out
|
|
|
|
fdtdump virt.out
|
|
|
|
|
2020-11-11 12:59:44 +04:00
|
|
|
debug: build
|
|
|
|
@tmux new-session -d \
|
|
|
|
"qemu-system-riscv64 -machine virt -nographic -bios $(BOOTLOADER) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) -s -S" && \
|
|
|
|
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
|
|
|
|
tmux -2 attach-session -d
|
|
|
|
|
2022-04-17 02:59:10 +04:00
|
|
|
|
|
|
|
gdbserver: build
|
|
|
|
@qemu-system-riscv64 -machine virt -nographic -bios $(BOOTLOADER) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) -s -S
|
|
|
|
|
|
|
|
gdbclient:
|
|
|
|
@riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'
|
|
|
|
|
2022-12-19 15:55:58 +04:00
|
|
|
.PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient fdt
|