-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.riscv
More file actions
204 lines (142 loc) · 4.82 KB
/
Makefile.riscv
File metadata and controls
204 lines (142 loc) · 4.82 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# --- BlueOS / Makefile.riscv (Refactored) ---
-include .config
# --- Verbosity Control ---
ifeq ($(V),1)
Q =
else
Q = @
endif
# --- Toolchain Setup ---
CC := riscv64-unknown-elf-gcc
AS := riscv64-unknown-elf-as
LD := riscv64-unknown-elf-ld
QEMU := qemu-system-riscv32
OBJDIR := obj
BINDIR := build
$(shell mkdir -p $(OBJDIR) $(BINDIR))
GCC_INC := $(shell $(CC) -print-file-name=include)
INCLUDES := -Iinclude -Iinclude/kernel -Iinclude/arch/riscv -Iinclude/drivers -I$(GCC_INC) -I.
CFLAGS := -march=rv32i_zicsr -mabi=ilp32 -ffreestanding -fno-builtin -std=gnu99 -nostdlib \
-fno-stack-protector -nostdinc -fno-pic -O0 -g -DRISCV $(INCLUDES) -march=rv32g -march=rv32imafdc_h_zicsr_zifencei_zbkb_zbkc_zbkx_zknd_zkne_zknh
CFLAGS += $(CONF_FLAGS)
ASFLAGS := -march=rv32i_zicsr -mabi=ilp32 -g
LDFLAGS := -m elf32lriscv -T arch/riscv/link.ld
KERNEL_ELF := $(BINDIR)/blueos_riscv.elf
obj-y := arch/riscv/boot.o \
arch/riscv/kernel.o \
arch/printk.o \
arch/riscv/acpi.o \
arch/riscv/plic.o \
arch/riscv/trap.o \
arch/riscv/trap_entry.o \
arch/riscv/trap_handler.o \
arch/riscv/interrupts.o \
arch/riscv/panic.o \
arch/riscv/commands.o \
arch/riscv/keyboard_io.o \
arch/riscv/shell.o \
arch/riscv/profile.o \
arch/riscv/kvm.o \
arch/riscv/mm/memory.o \
arch/riscv/vendor_h.o \
arch/riscv/intel_h.o \
arch/riscv/init_fnc.o \
arch/riscv/task.o \
arch/riscv/switch.o \
drivers/multilru.o \
drivers/vhost/vhost_net.o \
drivers/battery/battery.o \
drivers/bcma/bcma.o \
drivers/connector/connector.o \
drivers/pnp/pnp.o \
drivers/core/live_config.o \
fs/ramfs/fs.o \
fs/eventfs.o \
lib/string.o \
crypto/sha256.o \
usr/auth.o \
sound/snd.o \
kernel/sched.o \
arch/riscv/timer.o \
kernel/mm/malloc.o \
kernel/mm/vmm.o \
lib/list.o \
crypto/aes.o \
crypto/aes_riscv_glue.o \
crypto/sm3_riscv_glue.o \
arch/riscv/fpu.o \
kernel/power/hibernate.o \
arch/riscv/hibernate_asm.o \
arch/riscv/intr.o \
drivers/power/power.o \
kernel/jump_label.o \
arch/riscv/kvm/nmu.o \
kernel/net/net.o \
kernel/bpf/jit_rv64.o \
kernel/mm/fault.o \
kernel/process.o \
kernel/mm/demand_paging.o \
kernel/mm/pmm.o \
kernel/mm/ptdump.o \
drivers/xen/xen.o \
drivers/watchdog/wdt.o \
drivers/zorro/zorro.o \
drivers/android/binder.o \
drivers/android/ashmem.o \
drivers/mailbox/mbox.o \
drivers/ps3/ps3_ds3.o \
drivers/tc/tc.o \
drivers/cxl/cxl_m.o \
drivers/ptp/ptp.o \
drivers/pps/pps.o \
drivers/firmware/firmware.o \
drivers/w1/w1.o \
drivers/hal/gpio.o \
drivers/hal/timer.o \
drivers/dax/dax.o \
drivers/edac/edac.o \
drivers/uio/uio.o \
drivers/macintosh/adb.o \
drivers/hx/haptics.o \
drivers/i2c/i2c.o
obj-$(CONFIG_DRIVER_RTC) += drivers/rtc/rtc.o
obj-$(CONFIG_FS_VFS) += fs/vfs/vfs.o
obj-$(CONFIG_DRIVER_KEYBOARD) += drivers/keyboard/keyboard.o
REAL_OBJS := $(addprefix $(OBJDIR)/, $(obj-y))
RUST_LIB := rust/target/riscv32i-unknown-none-elf/release/librust.a
# --- Build Rules ---
all: version_h $(KERNEL_ELF)
version_h:
@echo " UPD include/version.h"
$(Q)sed -i 's/#define UTS_VERSION.*/#define UTS_VERSION "#1 SMP PREEMPT '"$$(date +'%Y-%m-%d %H:%M:%S')"'"/' include/version.h 2>/dev/null || true
$(KERNEL_ELF): rust_module $(REAL_OBJS)
@echo " LD $@"
$(Q)$(LD) $(LDFLAGS) -o $@ $(REAL_OBJS) --whole-archive $(RUST_LIB) --no-whole-archive
@echo " DONE BlueOS (RISC-V) Kernel is ready in $(BINDIR)/"
# Rule for C files
$(OBJDIR)/%.o: %.c
@mkdir -p $(dir $@)
@echo " CC $<"
$(Q)$(CC) $(CFLAGS) -c $< -o $@
# Rule for Assembly files (.s and .S)
$(OBJDIR)/%.o: %.s
@mkdir -p $(dir $@)
@echo " AS $<"
$(Q)$(AS) $(ASFLAGS) $< -o $@
# Rust Module for RISC-V
rust_module:
@echo " RUST Building core module (RISC-V)"
$(Q)cd rust && RUSTFLAGS="-C relocation-model=static" cargo build --release \
-Z build-std=core --target riscv32i-unknown-none-elf
run: all
$(Q)$(QEMU) -nographic -machine virt -bios $(KERNEL_ELF)
dint-run:
$(Q)$(QEMU) -nographic -machine virt -bios $(KERNEL_ELF) -d int
debug: all
@echo " GDB Waiting for connection on :1234"
$(Q)$(QEMU) -nographic -serial mon:stdio -machine virt -s -S -bios $(KERNEL_ELF)
clean:
@echo " CLEAN $(OBJDIR) $(BINDIR)"
$(Q)rm -rf $(OBJDIR) $(BINDIR)
$(Q)cd rust && cargo clean
.PHONY: all clean run rust_module version_h debug