-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMakefile
More file actions
129 lines (104 loc) · 3.18 KB
/
Makefile
File metadata and controls
129 lines (104 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Building
export LOG := trace
ARCH := riscv64
ifeq ($(ARCH), x86_64)
TARGET := x86_64-unknown-none
QEMU_EXEC += qemu-system-x86_64 \
-machine q35 \
-kernel $(KERNEL_ELF) \
-cpu IvyBridge-v2
BUS := pci
else ifeq ($(ARCH), riscv64)
TARGET := riscv64gc-unknown-none-elf
QEMU_EXEC += qemu-system-$(ARCH) \
-machine virt \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-kernel $(KERNEL_BIN)
else ifeq ($(ARCH), aarch64)
TARGET := aarch64-unknown-none-softfloat
QEMU_EXEC += qemu-system-$(ARCH) \
-cpu cortex-a72 \
-machine virt \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-kernel $(KERNEL_BIN)
else ifeq ($(ARCH), loongarch64)
TARGET := loongarch64-unknown-none
QEMU_EXEC += qemu-system-$(ARCH) -kernel $(KERNEL_ELF) -m 1G
BUS := pci
else
$(error "ARCH" must be one of "x86_64", "riscv64", "aarch64" or "loongarch64")
endif
MODE := release
KERNEL_ELF := target/$(TARGET)/$(MODE)/os
KERNEL_BIN := $(KERNEL_ELF).bin
DISASM_TMP := target/$(TARGET)/$(MODE)/asm
FS_IMG := target/$(TARGET)/$(MODE)/fs.img
# FS_IMG := fs-img.img
APPS := user/src/bin/*
# BOARD
BOARD := qemu
SBI ?= rustsbi
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
# Building mode argument
ifeq ($(MODE), release)
MODE_ARG := --release
endif
# KERNEL ENTRY
KERNEL_ENTRY_PA := 0x80200000
# Binutils
OBJDUMP := rust-objdump --arch-name=riscv64
OBJCOPY := rust-objcopy --binary-architecture=riscv64
# Disassembly
DISASM ?= -x
# Run usertests or usershell
TEST ?=
build: env fs-img $(KERNEL_BIN)
env:
(rustup target list | grep "$(TARGET) (installed)") || rustup target add $(TARGET)
cargo install cargo-binutils
rustup component add rust-src
rustup component add llvm-tools-preview
$(KERNEL_BIN): kernel
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@
fs-img: $(APPS)
@cd user && make build TARGET=$(TARGET) TEST=$(TEST)
@rm -f $(FS_IMG)
@cargo install easyfs-packer && easyfs-packer -s user/src/bin/ -t target/$(TARGET)/release/
cp target/$(TARGET)/$(MODE)/fs.img fs-img.img
$(APPS):
kernel:
@echo Platform: $(BOARD)
@cargo build --release --target $(TARGET)
clean:
@cargo clean
disasm: kernel
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) | less
disasm-vim: kernel
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) > $(DISASM_TMP)
@vim $(DISASM_TMP)
@rm $(DISASM_TMP)
run: run-inner
# QEMU_ARGS := -machine virt \
# -nographic \
# -bios default \
# -kernel $(KERNEL_BIN) \
# -drive file=$(FS_IMG),if=none,format=raw,id=x0 \
# -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
# -smp 1 \
# -D qemu.log -d in_asm,int,pcall,cpu_reset,guest_errors
QEMU_EXEC += -nographic \
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
-smp 1 \
-D qemu.log -d in_asm,int,pcall,cpu_reset,guest_errors
run-inner: build
$(QEMU_EXEC)
debug: build
@tmux new-session -d \
"$(QEMU_EXEC) -s -S" && \
tmux split-window -h "gdb -ex 'file $(KERNEL_ELF)' -ex 'target remote localhost:1234'" && \
tmux -2 attach-session -d
gdbserver: build
@$(QEMU_EXEC) -s -S
gdbclient:
@gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'
.PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient