blob: df823423f8b6b9f1d376cf2cb18e7895f7daea48 (
plain)
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
|
##
# By default everything is silent. If you want to change this behavior simply
# assign V=1 when calling make.
V =
ifeq ($(strip $(V)),)
E = @echo
Q = @
else
E = @\#
Q =
endif
##
# Compile options. You can use CROSS_COMPILE just like on the Linux Kernel. You
# can also determine the ISA to be used, which defaults to my VisionFive2 board.
# I did not go too much into the rabbit hole of platform-specific flags. Hence
# no `-mcpu`, no `-mtune`, no funny business.
CC = $(CROSS_COMPILE)gcc$(CC_SUFFIX)
LD = $(CROSS_COMPILE)ld
QEMU ?= qemu-system-riscv64
ISA ?= rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd_zba_zbb
CCFLAGS = -march=$(ISA) -Iinclude/ -mabi=lp64d
CCFLAGS += -Werror -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual -Winit-self \
-Wmissing-include-dirs -Wredundant-decls -Wshadow -Wsign-conversion \
-Wswitch-default -Wundef -Wunreachable-code -Wmissing-noreturn
LDFLAGS = -Iinclude/ -static -nostdlib -melf64lriscv -z noexecstack
##
# Optional parameters for QEMU and gdb.
QEMU_FLAGS ?=
QEMU_BIOS ?=
GDB_EXTRA_FLAGS ?=
##
# You can pass an optional `DEBUG` variable to manipulate the build type. This
# will also affect how QEMU is run.
DEBUG =
ifeq ($(strip $(DEBUG)),)
CCFLAGS += -O3
else
CCFLAGS += -g
QEMU_FLAGS += -s -S
endif
##
# Paths.
SRC = $(wildcard kernel/head.S kernel/*.c)
OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SRC)))
LINKER = kernel/fbos.ld
KRNL = fbos
LDFLAGS += -T $(LINKER)
##
# Targets
.PHONY: all
all: clean $(KRNL)
.PHONY: $(KRNL)
$(KRNL): $(OBJ) $(LINKER).S
$(Q) $(CC) -E $(LINKER).S -Iinclude/ -o $(LINKER)
$(E) " LD " $@
$(Q) $(LD) $(LDFLAGS) $(OBJ) -o $(KRNL)
.c.o:
$(E) " CC " $(*F)
$(Q) $(CC) $(CCFLAGS) -c $< -o $@
.S.o:
$(E) " CC " $(*F)
$(Q) $(CC) $(CCFLAGS) -c $< -o $@
.PHONY: qemu
qemu: $(KRNL)
ifeq ($(strip $(QEMU_BIOS)),)
$(Q) $(QEMU) $(QEMU_FLAGS) -machine virt -kernel $(KRNL) -nographic
else
$(Q) $(QEMU) $(QEMU_FLAGS) -machine virt -bios $(QEMU_BIOS) -kernel $(KRNL) -nographic
endif
.PHONY: gdb
gdb:
$(Q) gdb --command utils/init.gdb $(GDB_EXTRA_FLAGS) $(KRNL)
.PHONY: clean
clean:
$(Q) rm -f $(OBJ) $(KRNL) $(LINKER)
.PHONY: lint
lint:
$(Q) git ls-files *.c *.h | xargs clang-format --dry-run --Werror
|