From 4b86e6272166236c9283004f6a060d5174165796 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 7 Sep 2021 10:48:33 +0200 Subject: Initial commit: bootstrap --- Makefile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/linker.ld | 34 ++++++++++++++++++++++++++++++++++ src/main.c | 3 +++ src/start.s | 11 +++++++++++ 4 files changed, 95 insertions(+) create mode 100644 Makefile create mode 100644 src/linker.ld create mode 100644 src/main.c create mode 100644 src/start.s diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..475c160 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +.POSIX: +.SUFFIXES: +.PHONY: clean run + +# Compiler. +AS := arm-none-eabi-as +CC := arm-none-eabi-gcc +OBJCOPY := arm-none-eabi-objcopy + +# Paths. +SRC_DIR := src +BUILD_DIR := build + +# Output files. +ELF := $(BUILD_DIR)/kernel7.elf +IMG := $(BUILD_DIR)/kernel7.img + +# Bootstrapping files. +OBJ_START = $(BUILD_DIR)/start.o +OBJ_MAIN = $(BUILD_DIR)/main.o +SRC_LINK = $(SRC_DIR)/linker.ld + +CFLAGS := -Wall -ffreestanding -O2 -nostdlib -lgcc -mgeneral-regs-only +AFLAGS := + +default: $(IMG) + +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.s + $(AS) $(AFLAGS) -o $@ -c $< + +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c + $(CC) $(CFLAGS) -o $@ -c $< + +$(IMG): $(BUILD_DIR) $(ELF) + $(OBJCOPY) $(ELF) -O binary $(IMG) + +$(ELF): $(OBJ_START) $(OBJ_MAIN) + $(CC) $(CFLAGS) -T $(SRC_LINK) -o $(ELF) $(OBJ_START) $(OBJ_MAIN) + +clean: + rm -rf $(BUILD_DIR) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +run: $(IMG) + qemu-system-aarch64 -M raspi3 -kernel $(IMG) -d in_asm -serial null -serial stdio diff --git a/src/linker.ld b/src/linker.ld new file mode 100644 index 0000000..f3482e9 --- /dev/null +++ b/src/linker.ld @@ -0,0 +1,34 @@ +ENTRY(_start) + +SECTIONS +{ + . = 0x8000; + __start = .; + .text : + { + KEEP(*(.text.boot)) + *(.text) + } + . = ALIGN(4096); + .rodata : + { + *(.rodata) + } + . = ALIGN(4096); + .data : + { + *(.data) + } + . = ALIGN(4096); + __bss_start = .; + .bss : + { + bss = .; + *(.bss) + } + . = ALIGN(4096); + __bss_end = .; + __bss_size = __bss_end - __bss_start; + __end = .; +} + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..1ce2dd1 --- /dev/null +++ b/src/main.c @@ -0,0 +1,3 @@ +void main(void) { + while(1); +} diff --git a/src/start.s b/src/start.s new file mode 100644 index 0000000..0fd2a5f --- /dev/null +++ b/src/start.s @@ -0,0 +1,11 @@ +.section ".text.boot" + +.global _start + +_start: + ldr r3, =main + blx r3 + +halt: + wfe + b halt -- cgit v1.2.1