Minimal viable kernel
This commit is contained in:
commit
e4d9be3aa7
5 changed files with 166 additions and 0 deletions
48
Makefile
Normal file
48
Makefile
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
TOOLPREFIX = riscv-none-elf
|
||||
|
||||
CC = $(TOOLPREFIX)-gcc
|
||||
AS = $(TOOLPREFIX)-as
|
||||
LD = $(TOOLPREFIX)-ld
|
||||
OBJCOPY = $(TOOLPREFIX)-objcopy
|
||||
OBJDUMP = $(TOOLPREFIX)-objdump
|
||||
|
||||
ASFLAGS = -march=rv64gc -mabi=lp64
|
||||
|
||||
LDFLAGS = -Tlink.ld
|
||||
LDFLAGS += -m elf64lriscv
|
||||
|
||||
CFLAGS = -Wall -Werror -O
|
||||
CFLAGS += -mcmodel=medany
|
||||
CFLAGS += -march=rv64gc -mabi=lp64
|
||||
CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
|
||||
|
||||
CFLAGS += -I.
|
||||
|
||||
CFLAGS += -fno-stack-protector # Prevents code that needs libc / runtime support
|
||||
CFLAGS += -MD # Generate header dependency files (.d)
|
||||
CFLAGS += -fno-pie -no-pie # Fixed address linking
|
||||
CFLAGS += -ggdb -gdwarf-2 # GDB debug info
|
||||
CFLAGS += -fno-omit-frame-pointer # More reliable backtraces in GDB
|
||||
|
||||
all: kernel.elf
|
||||
|
||||
kernel.elf: entry.o start.o
|
||||
@echo LD $@
|
||||
@$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
%.o: %.c
|
||||
@echo CC $@
|
||||
@$(CC) $(CFLAGS) -nostdinc -I. -c $< -o $@
|
||||
|
||||
%.o: %.S
|
||||
@echo AS $@
|
||||
@$(AS) $(ASFLAGS) -o $@ $<
|
||||
|
||||
qemu: kernel.elf
|
||||
@echo QEMU $@
|
||||
@qemu-system-riscv64 -machine virt -bios none -nographic -kernel kernel.elf
|
||||
|
||||
clean:
|
||||
rm -f *.o *.elf *.d
|
||||
|
||||
-include *.d
|
||||
Loading…
Add table
Add a link
Reference in a new issue