Automate kernel example for RISC-V

This commit is contained in:
Alex Kotov 2022-01-15 12:57:15 +05:00
parent 0f3747e5b6
commit 536c1f44f7
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 31 additions and 2 deletions

19
config/riscv64 Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
set -e
ARCH='riscv64'
HOST="$ARCH-elf"
REPO="$(realpath "$(dirname "$(realpath "$0")")/..")"
PREFIX="$REPO/vendor/cross"
BIN="$PREFIX/bin"
if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi
export AR="$BIN/$HOST-ar"
export CC="$BIN/$HOST-gcc"
export RANLIB="$BIN/$HOST-ranlib"
export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector'
"$REPO/configure" --host="$HOST" --enable-assert --enable-guard --with-libc

View File

@ -1 +1,4 @@
/build-libkernaux/*
!/build-libkernaux/.keep
/kernel.elf

View File

@ -5,8 +5,10 @@ CCPREFIX = ../../vendor/cross/bin/riscv64-elf-
AS = $(CCPREFIX)as
CC = $(CCPREFIX)gcc
CONFIG_LIBKERNAUX = ../../config/riscv64
QEMU = qemu-system-riscv64
BUILD_LIBKERNAUX = build-libkernaux
KERNEL = kernel.elf
LINKERSCR = linker.ld
@ -25,10 +27,15 @@ run: $(KERNEL)
$(QEMU) -machine virt -bios $< -serial stdio -display none
clean:
make -C $(BUILD_LIBKERNAUX) distclean || true
rm -f $(KERNEL) $(OBJS)
$(KERNEL): $(LINKERSCR) $(OBJS)
$(CC) -T $(LINKERSCR) -o $@ $(OBJS) -nostdlib -lgcc
$(KERNEL): $(LINKERSCR) $(OBJS) build-libkernaux.a
$(CC) -T $(LINKERSCR) -o $@ $(OBJS) -nostdlib -lgcc -lkernaux -Wl,-L$(BUILD_LIBKERNAUX)
build-libkernaux.a:
cd $(BUILD_LIBKERNAUX) && ../$(CONFIG_LIBKERNAUX)
cd $(BUILD_LIBKERNAUX) && make libkernaux.a
%.c.o: %.c
$(CC) -c $< -o $@ $(CFLAGS)