From d57ad4d9eed9e627e5d492d46f14bc2d87649324 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Thu, 26 Jun 2025 01:07:04 +0200 Subject: [PATCH] Readme, makefile, clang-format --- .clang-format | 8 ++++++++ Makefile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++++ 3 files changed, 63 insertions(+) create mode 100644 .clang-format create mode 100644 Makefile diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c59dfdc --- /dev/null +++ b/.clang-format @@ -0,0 +1,8 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ColumnLimit: 80 +AllowShortLoopsOnASingleLine: true +AlwaysBreakTemplateDeclarations: true +BreakConstructorInitializers: BeforeComma diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..21524e8 --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +# Makefile for the Fusion operating system. +# Make things fixable, not autocorrecting + +# TODO: Toolchain installation should be documented in the README +# https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack +TOOLPREFIX = riscv-none-elf + +CC = $(TOOLPREFIX)-gcc +AS = $(TOOLPREFIX)-gas +LD = $(TOOLPREFIX)-ld +OBJCOPY = $(TOOLPREFIX)-objcopy +OBJDUMP = $(TOOLPREFIX)-objdump + +# TODO: Document these options with clear descriptions, it should be readable +# by people not intimately familiar with machine code and/or gcc tooling. +CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb -gdwarf-2 +CFLAGS += -MD +CFLAGS += -mcmodel=medany +CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax +CFLAGS += -I. +CFLAGS += -fno-pie -no-pie +CFLAGS += -fno-stack-protector +CFLAGS += -march=rv64gc -mabi=lp64 + +LDFLAGS = -z max-page-size=4096 +LDFLAGS += -m elf64lriscv + +all: kernel.elf + +%.o: %.c + @echo CC $@ + @$(CC) $(CFLAGS) -nostdinc -I. -c $< -o $@ + +%.o: %.S + @echo CC-AS $@ + @$(CC) $(CFLAGS) -c $< -o $@ + +kernel.elf: trap.o kernelvec.o entry.o start.o kernel.o spinlock.o + @echo LD $@ + @$(LD) $(LDFLAGS) -T kernel.ld -o $@ $^ + +kernel.bin: kernel.elf + $(OBJCOPY) -O binary $< $@ + +clean: + rm -f *.o *.d *.elf *.bin + +-include *.d + diff --git a/README.md b/README.md index b00b23e..cd2134f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # fusion +For a quick reference on RISC-V assembly: +- https://risc-v.guru/instructions/ + +Toolchains: +- https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack +- https://github.com/xpack-dev-tools/qemu-riscv-xpack/