34 lines
934 B
Makefile
34 lines
934 B
Makefile
TOOLCHAIN = riscv64-linux-gnu-
|
|
QEMU=qemu-system-riscv64
|
|
KERNEL = kernel.elf
|
|
|
|
CFLAGS=-march=rv64i_zicsr_d -mabi=lp64d -Wall -Wextra -Werror -O2 -Iinclude -g
|
|
LDFLAGS=-T linker.ld --no-dynamic-linker -m elf64lriscv -static -nostdlib
|
|
QEMUFLAGS=-nographic -serial mon:stdio --no-reboot
|
|
|
|
CFILES = $(shell find -L -type f -name "*.c")
|
|
SFILES = $(shell find -L -type f -iname "*.s")
|
|
OBJ := $(addsuffix .o,$(CFILES)) $(addsuffix .o,$(SFILES))
|
|
|
|
$(KERNEL): $(OBJ) linker.ld
|
|
${TOOLCHAIN}ld $(LDFLAGS) -o $(KERNEL) $(OBJ)
|
|
|
|
%.c.o: %.c
|
|
$(TOOLCHAIN)gcc $(CFLAGS) -o $@ -c $<
|
|
|
|
%.s.o: %.s
|
|
$(TOOLCHAIN)gcc $(CFLAGS) -o $@ -c $<
|
|
|
|
%.S.o: %.S
|
|
$(TOOLCHAIN)gcc $(CFLAGS) -o $@ -c $<
|
|
|
|
run: $(KERNEL)
|
|
qemu-system-riscv64 $(QEMUFLAGS) -kernel $(KERNEL)
|
|
|
|
run-debug: $(KERNEL)
|
|
$(QEMU) -monitor none -s -S -kernel $(KERNEL) &
|
|
$(TOOLCHAIN)gdb $(KERNEL) -q -ex "target remote :1234" -ex "b *_start" -ex "c" -tui
|
|
killall $(QEMU)
|
|
|
|
clean:
|
|
@rm $(OBJ) $(KERNEL)
|