This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (66 loc) · 1.53 KB
/
Makefile
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
.DEFAULT_GOAL := all
ifeq ($(OS),Windows_NT)
# Windows-specific
PREFIX = riscv64-unknown-elf-
else ifeq ($(shell uname),Linux)
# Linux-specific
PREFIX = riscv64-unknown-linux-gnu-
else
$(error Unsupported operating system: $(OS))
endif
GCC = ${PREFIX}gcc
C_FLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QEMU_FLAGS = -nographic -machine virt -bios none
GDB = ${PREFIX}gdb
OBJDUMP = ${PREFIX}objdump
ASM_FILE = \
boot.s \
memory.s \
timer.s \
switch.s \
traps.s \
riscv.s \
syscalls.s
C_FILE = \
enter.c \
uart.c \
print.c \
page.c \
sched.c \
user.c \
kernel.c \
trap.c \
plic.c \
lock.c \
delay.c \
syscall.c
OBJ_FILE = $(ASM_FILE:.s=.o)
OBJ_FILE += $(C_FILE:.c=.o)
all: os.elf
os.elf: ${OBJ_FILE}
${GCC} ${C_FLAGS} -T kernel.ld -o $@ $^
%.o: %.S
${GCC} ${C_FLAGS} -c -o $@ $^
%.o: %.s
${GCC} ${C_FLAGS} -c -o $@ $^
%.o: %.c
${GCC} ${C_FLAGS} -c -o $@ $^
run: all
@echo Press Ctrl-A and then X to exit QEMU
@echo ------------------------------------
${QEMU} ${QEMU_FLAGS} -kernel os.elf
debug: all
@echo Press Ctrl-A and then X to exit QEMU
@echo ------------------------------------
${QEMU} ${QEMU_FLAGS} -kernel os.elf -s -S
gdb: all
@echo Type 'quit' to exit GNU DGB
@echo ---------------------------
${GDB} os.elf -q -x gdbinit
disassemble: all
@echo Check out disassembled code at `os.txt`
${OBJDUMP} -D os.elf > os.txt
.PHONY: clean
clean:
del *.o *.bin *.elf os.txt