From 1fc97f9c5fa4b01be54099ff7dd90f39a4f5368a Mon Sep 17 00:00:00 2001 From: Jozef Nagy Date: Sat, 25 Jan 2025 19:53:01 +0100 Subject: [PATCH] Added build type detection, simplified legacy BIOS booting on x86_64 --- Makefile | 40 ++++++++++++++++- boot/Makefile | 9 ++-- boot/arch/aarch64/common/.gitkeep | 0 boot/arch/aarch64/linker.ld | 2 +- boot/arch/x86_64/stage1/boot-cd.asm | 39 +++-------------- boot/arch/x86_64/stage1/boot-hdd.asm | 40 +++-------------- boot/arch/x86_64/stage1/boot.inc | 43 +++++++++++++++++++ boot/arch/x86_64/stage1/diskutils.inc | 42 ++++++++++++++++++ boot/arch/x86_64/stage1/print.inc | 31 +++++++++++++ boot/common/config/config.c | 16 +++---- boot/common/menu/main_menu.c | 25 +++++++++++ boot/common/print.c | 7 ++- boot/include/lib/string.h | 34 +++++++++++++++ boot/include/menu/bootmenu.h | 25 +++++++++++ boot/platform/pc-bios/Makefile | 5 +-- boot/platform/raspi4/Makefile | 35 +++++++++------ .../aarch64/common => platform/raspi4}/boot.S | 2 +- kernel/Makefile | 10 ++--- 18 files changed, 298 insertions(+), 107 deletions(-) create mode 100644 boot/arch/aarch64/common/.gitkeep create mode 100644 boot/arch/x86_64/stage1/boot.inc create mode 100644 boot/arch/x86_64/stage1/diskutils.inc create mode 100644 boot/arch/x86_64/stage1/print.inc create mode 100644 boot/common/menu/main_menu.c create mode 100644 boot/include/lib/string.h create mode 100644 boot/include/menu/bootmenu.h rename boot/{arch/aarch64/common => platform/raspi4}/boot.S (99%) diff --git a/Makefile b/Makefile index 3a6fa9b..844c246 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,15 @@ ## SOFTWARE. ## ################################################################################### +.DEFAULT_GOAL := all + +## +# Build configuration +# + export ARCH ?= x86_64 export PLATFORM ?= generic-pc +export BUILD_TYPE ?= debug export ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) @@ -26,16 +33,45 @@ export BUILD_DIR ?= $(ROOT_DIR)/build export SYSROOT_DIR ?= $(ROOT_DIR)/sysroot export RELEASE_DIR ?= $(ROOT_DIR)/release -export GITREV := $(shell git rev-parse --short HEAD) - NOUEFI ?= y +## +# Image generation and running +# + LIVECD := $(RELEASE_DIR)/aurix-$(GITREV)-livecd_$(ARCH)-$(PLATFORM).iso LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img QEMU_FLAGS := -m 2G -smp 4 -serial stdio +## +# General info +# + +export CODENAME := "Matterhorn" +export VERSION := "0.1" +export GITREV := $(shell git rev-parse --short HEAD) + +export DEFINES := AURIX_CODENAME=$(CODENAME) \ + AURIX_VERSION=$(VERSION) \ + AURIX_GITREV=$(GITREV) \ + BUILD_TYPE=$(BUILD_TYPE) + +ifeq ($(BUILD_TYPE),debug) +DEFINES += BUILD_DEBUG +else +DEFINES += BUILD_RELEASE +endif + +## +# Recipes +# + +.PHONY: all +all: boot kernel + @: + .PHONY: boot boot: @printf ">>> Building bootloader...\n" diff --git a/boot/Makefile b/boot/Makefile index 5eb67d9..6794b6a 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -21,16 +21,19 @@ export INCLUDE_DIRS := $(BOOT_ROOT)/include +export DEFINES += __$(ARCH)__ \ + _AXBOOT + export BUILD_DIR ?= build export SYSROOT_DIR ?= sysroot -export ASFLAGS := -export CFLAGS := -D__$(ARCH) -D_AXBOOT -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP +export ASFLAGS := $(foreach d, $(DEFINES), -D$d) +export CFLAGS := $(foreach d, $(DEFINES), -D$d) -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP export LDFLAGS := -nostdlib export BOOT_ROOT := $(ROOT_DIR)/boot -ifeq ($(DEBUG),yes) +ifeq ($(BUILD_TYPE),debug) CFLAGS += -O0 -g3 else CFLAGS += -O2 diff --git a/boot/arch/aarch64/common/.gitkeep b/boot/arch/aarch64/common/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/boot/arch/aarch64/linker.ld b/boot/arch/aarch64/linker.ld index ad58a34..3839491 100644 --- a/boot/arch/aarch64/linker.ld +++ b/boot/arch/aarch64/linker.ld @@ -54,4 +54,4 @@ SECTIONS } } -/*__bss_size = (__bss_end - __bss_start) >> 3;*/ +__bss_size = (__bss_end - __bss_start) >> 3; diff --git a/boot/arch/x86_64/stage1/boot-cd.asm b/boot/arch/x86_64/stage1/boot-cd.asm index 4ee561e..a2c6bc1 100644 --- a/boot/arch/x86_64/stage1/boot-cd.asm +++ b/boot/arch/x86_64/stage1/boot-cd.asm @@ -20,7 +20,8 @@ [bits 16] [org 0x7c00] -jmp 0x0000:AxBootEntry +_start: + jmp 0x0000:AxBootEntry times 8-($-$$) db 0 @@ -37,40 +38,12 @@ bi_Reserved times 40 db 0 ;; without UEFI on x86_64. ;; +%include "boot.inc" +%include "print.inc" +%include "diskutils.inc" + %include "strings.inc" -AxBootEntry: - ;; - ;; Set 80x50 text mode and clear the screen - ;; - mov ax, 0x03 - int 0x10 - xor bx, bx - mov ax, 0x1112 - int 0x10 - mov ah, 0 - int 0x10 - - ;; - ;; Display an error message and halt - ;; - mov si, sErrorUnbootable - call PrintString - mov si, sPressToReboot - call PrintString - jmp AxBootHalt - -PrintString: - lodsb - or al, al - jz .done - mov ah, 0x0e - mov bx, 0x0007 - int 0x10 - jmp PrintString - .done: - ret - AxBootHalt: hlt jmp AxBootHalt diff --git a/boot/arch/x86_64/stage1/boot-hdd.asm b/boot/arch/x86_64/stage1/boot-hdd.asm index d784430..21ce302 100644 --- a/boot/arch/x86_64/stage1/boot-hdd.asm +++ b/boot/arch/x86_64/stage1/boot-hdd.asm @@ -20,7 +20,9 @@ [bits 16] [org 0x7c00] -jmp 0x0000:AxBootEntry +_start: + jmp short AxBootEntry + nop ;; ;; BIOS bootloader on x86_64 is just a placeholder @@ -29,40 +31,12 @@ jmp 0x0000:AxBootEntry ;; without UEFI on x86_64. ;; +%include "boot.inc" +%include "print.inc" +%include "diskutils.inc" + %include "strings.inc" -AxBootEntry: - ;; - ;; Set 80x50 text mode and clear the screen - ;; - mov ax, 0x03 - int 0x10 - xor bx, bx - mov ax, 0x1112 - int 0x10 - mov ah, 0 - int 0x10 - - ;; - ;; Display an error message and halt - ;; - mov si, sErrorUnbootable - call PrintString - mov si, sPressToReboot - call PrintString - jmp AxBootHalt - -PrintString: - lodsb - or al, al - jz .done - mov ah, 0x0e - mov bx, 0x0007 - int 0x10 - jmp PrintString - .done: - ret - AxBootHalt: hlt jmp AxBootHalt diff --git a/boot/arch/x86_64/stage1/boot.inc b/boot/arch/x86_64/stage1/boot.inc new file mode 100644 index 0000000..96e9793 --- /dev/null +++ b/boot/arch/x86_64/stage1/boot.inc @@ -0,0 +1,43 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Module Name: boot.inc ;; +;; Project: AurixOS ;; +;; ;; +;; Copyright (c) 2024-2025 Jozef Nagy ;; +;; ;; +;; This source is subject to the MIT License. ;; +;; See License.txt in the root of this repository. ;; +;; All other rights reserved. ;; +;; ;; +;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; +;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; +;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; +;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; +;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; +;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; +;; SOFTWARE. ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +AxBootEntry: + ;; + ;; Set 80x50 text mode and clear the screen + ;; + mov ax, 0x03 + int 0x10 + xor bx, bx + mov ax, 0x1112 + int 0x10 + mov ah, 0 + int 0x10 + + ;; Legacy booting is not ready for release yet +%ifdef BUILD_DEBUG + ;; + ;; Display an error message and halt + ;; + mov si, sErrorUnbootable + call PrintString + mov si, sPressToReboot + call PrintString + jmp AxBootHalt +%endif + jmp AxBootHalt diff --git a/boot/arch/x86_64/stage1/diskutils.inc b/boot/arch/x86_64/stage1/diskutils.inc new file mode 100644 index 0000000..a7f4fff --- /dev/null +++ b/boot/arch/x86_64/stage1/diskutils.inc @@ -0,0 +1,42 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Module Name: diskutils.inc ;; +;; Project: AurixOS ;; +;; ;; +;; Copyright (c) 2024-2025 Jozef Nagy ;; +;; ;; +;; This source is subject to the MIT License. ;; +;; See License.txt in the root of this repository. ;; +;; All other rights reserved. ;; +;; ;; +;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; +;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; +;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; +;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; +;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; +;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; +;; SOFTWARE. ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; dh = number of sectors to read +;; dl = drive number +;; +;; output: es:bx +LoadDisk: + push dx + mov ah, 0x02 + mov al, dh + mov ch, 0x00 + mov dh, 0x00 + mov cl, 0x02 + int 0x13 + jc .ReadError + pop dx + cmp dh, al + jne .ReadError + ret + .ReadError: + mov si, sDiskReadError + call PrintString + call AxBootHalt + +sDiskReadError: db 'ERROR: Failed to read disk!', 0 \ No newline at end of file diff --git a/boot/arch/x86_64/stage1/print.inc b/boot/arch/x86_64/stage1/print.inc new file mode 100644 index 0000000..cdd9c0a --- /dev/null +++ b/boot/arch/x86_64/stage1/print.inc @@ -0,0 +1,31 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Module Name: print.inc ;; +;; Project: AurixOS ;; +;; ;; +;; Copyright (c) 2024-2025 Jozef Nagy ;; +;; ;; +;; This source is subject to the MIT License. ;; +;; See License.txt in the root of this repository. ;; +;; All other rights reserved. ;; +;; ;; +;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; +;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; +;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; +;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; +;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; +;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; +;; SOFTWARE. ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; si = input string +PrintString: + lodsb + or al, al + cmp al, 0 + jz .done + mov ah, 0x0e + mov bx, 0x0007 + int 0x10 + jmp PrintString + .done: + ret diff --git a/boot/common/config/config.c b/boot/common/config/config.c index 9822aab..31d756e 100644 --- a/boot/common/config/config.c +++ b/boot/common/config/config.c @@ -17,8 +17,6 @@ /* SOFTWARE. */ /*********************************************************************************/ -#include -#include #include #include #include @@ -35,12 +33,12 @@ char *config_paths[] = { void config_init(void) { - FILE *config_file; + void *config_file; char *config_buffer; int filesize; for (size_t i = 0; i < ARRAY_LENGTH(config_paths); i++) { - config_file = fw_file_open(NULL, config_paths[i]); + //config_file = fw_file_open(NULL, config_paths[i]); if (config_file != NULL) { break; } @@ -52,18 +50,18 @@ void config_init(void) //console(); } - filesize = fw_file_size(config_file); - config_buffer = malloc(filesize); + //filesize = fw_file_size(config_file); + //config_buffer = malloc(filesize); if (config_buffer == NULL) { log("Entering console...\r\n\r\n"); //console(); } - fw_file_read(config_file, filesize, config_buffer); + //fw_file_read(config_file, filesize, config_buffer); // TODO: parse configuration file - free(config_buffer); + //free(config_buffer); /* if (config_errors != 0 || config_get_menu_root() == NULL) { @@ -74,5 +72,5 @@ void config_init(void) } */ - fw_file_close(config_file); + //fw_file_close(config_file); } \ No newline at end of file diff --git a/boot/common/menu/main_menu.c b/boot/common/menu/main_menu.c new file mode 100644 index 0000000..a91a5ad --- /dev/null +++ b/boot/common/menu/main_menu.c @@ -0,0 +1,25 @@ +/*********************************************************************************/ +/* Module Name: main_menu.c */ +/* Project: AurixOS */ +/* */ +/* Copyright (c) 2024-2025 Jozef Nagy */ +/* */ +/* This source is subject to the MIT License. */ +/* See License.txt in the root of this repository. */ +/* All other rights reserved. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ +/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ +/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */ +/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */ +/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */ +/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ +/* SOFTWARE. */ +/*********************************************************************************/ + +#include + +void main_menu(void) +{ + while (1); +} \ No newline at end of file diff --git a/boot/common/print.c b/boot/common/print.c index 362aff8..fcfd1fa 100644 --- a/boot/common/print.c +++ b/boot/common/print.c @@ -19,14 +19,13 @@ #define NANOPRINTF_IMPLEMENTATION #define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1 -#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 1 -#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 1 -#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1 +#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 0 +#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 0 +#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 0 #define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0 #define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0 #include -#include #include #include diff --git a/boot/include/lib/string.h b/boot/include/lib/string.h new file mode 100644 index 0000000..55ce907 --- /dev/null +++ b/boot/include/lib/string.h @@ -0,0 +1,34 @@ +/*********************************************************************************/ +/* Module Name: string.h */ +/* Project: AurixOS */ +/* */ +/* Copyright (c) 2024-2025 Jozef Nagy */ +/* */ +/* This source is subject to the MIT License. */ +/* See License.txt in the root of this repository. */ +/* All other rights reserved. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ +/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ +/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */ +/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */ +/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */ +/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ +/* SOFTWARE. */ +/*********************************************************************************/ + +#ifndef _LIB_STRING_H +#define _LIB_STRING_H + +#include + +size_t mbstowcs(wchar_t *dest, const char **src, size_t len); + +size_t strlen(const char *str); +char *strcpy(char *dest, const char *src); + +void *memset(void *dest, int val, size_t len); +void *memcpy(void *dest, void *src, size_t len); +int memcmp(const void *a, const void *b, size_t len); + +#endif /* _LIB_STRING_H */ \ No newline at end of file diff --git a/boot/include/menu/bootmenu.h b/boot/include/menu/bootmenu.h new file mode 100644 index 0000000..6870fdf --- /dev/null +++ b/boot/include/menu/bootmenu.h @@ -0,0 +1,25 @@ +/*********************************************************************************/ +/* Module Name: bootmenu.h */ +/* Project: AurixOS */ +/* */ +/* Copyright (c) 2024-2025 Jozef Nagy */ +/* */ +/* This source is subject to the MIT License. */ +/* See License.txt in the root of this repository. */ +/* All other rights reserved. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ +/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ +/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */ +/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */ +/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */ +/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ +/* SOFTWARE. */ +/*********************************************************************************/ + +#ifndef _MENU_BOOTMENU_H +#define _MENU_BOOTMENU_H + +void main_menu(void); + +#endif /* _MENU_BOOTMENU_H */ diff --git a/boot/platform/pc-bios/Makefile b/boot/platform/pc-bios/Makefile index 09281c0..3ae9f39 100644 --- a/boot/platform/pc-bios/Makefile +++ b/boot/platform/pc-bios/Makefile @@ -32,7 +32,6 @@ BOOT_CFLAGS := $(CFLAGS) \ BOOT_LDFLAGS := $(LDFLAGS) -$(shell find . -type d \( -name arch -o -name platform \) -prune -name '*.c') BOOT_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH) -type d -name arch/$(ARCH)/uefi -prune -name '*.S') BOOT_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH) -type d -name arch/$(ARCH)/uefi -prune -name '*.c') @@ -56,9 +55,9 @@ install: $(STAGE1_HDD): $(BOOT_ROOT)/arch/$(ARCH)/stage1/boot-hdd.asm @mkdir -p $(@D) @printf " AS\tboot/arch/$(ARCH)/stage1/stage1-hdd.bin\n" - @nasm -fbin -I$(BOOT_ROOT)/arch/$(ARCH)/stage1 $< -o $@ + @nasm -fbin -I$(BOOT_ROOT)/arch/$(ARCH)/stage1 $(ASFLAGS) $< -o $@ $(STAGE1_CD): $(BOOT_ROOT)/arch/$(ARCH)/stage1/boot-cd.asm @mkdir -p $(@D) @printf " AS\tboot/arch/$(ARCH)/stage1/stage1-cd.bin\n" - @nasm -fbin -I$(BOOT_ROOT)/arch/$(ARCH)/stage1 $< -o $@ + @nasm -fbin -I$(BOOT_ROOT)/arch/$(ARCH)/stage1 $(ASFLAGS) $< -o $@ diff --git a/boot/platform/raspi4/Makefile b/boot/platform/raspi4/Makefile index ce9e895..5ed3c17 100644 --- a/boot/platform/raspi4/Makefile +++ b/boot/platform/raspi4/Makefile @@ -17,7 +17,7 @@ ## SOFTWARE. ## ################################################################################### -BOOTFILE := $(BUILD_DIR)/boot/raspi4/axboot.elf +BOOTFILE := $(BUILD_DIR)/boot/raspi4/kernel8.img INCLUDE_DIRS += $(BOOT_ROOT)/include \ $(BOOT_ROOT)/include/arch/$(ARCH) \ @@ -26,14 +26,18 @@ INCLUDE_DIRS += $(BOOT_ROOT)/include \ BOOT_AS := $(ARCH)-elf-gcc BOOT_CC := $(ARCH)-elf-gcc BOOT_LD := $(ARCH)-elf-ld +BOOT_OBJCOPY := $(ARCH)-elf-objcopy BOOT_ASFLAGS := $(ASFLAGS) \ $(foreach d, $(INCLUDE_DIRS), -I$d) BOOT_CFLAGS := $(CFLAGS) \ - $(foreach d, $(INCLUDE_DIRS), -I$d) + $(foreach d, $(INCLUDE_DIRS), -I$d) \ + -mstrict-align \ + -nostartfiles -BOOT_LDFLAGS := $(LDFLAGS) +BOOT_LDFLAGS := $(LDFLAGS) \ + -T$(BOOT_ROOT)/arch/$(ARCH)/linker.ld COMMON_CFILES := $(shell find $(BOOT_ROOT)/common -name '*.c') COMMON_ARCH_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.c') @@ -41,11 +45,11 @@ COMMON_ARCH_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.S' PLATFORM_CFILES := $(shell find $(BOOT_ROOT)/platform/$(PLATFORM) -name '*.c') PLATFORM_ASFILES := $(shell find $(BOOT_ROOT)/platform/$(PLATFORM) -name '*.S') -BOOT_OBJ := $(COMMON_CFILES:$(BOOT_ROOT)/common/%.c=$(BUILD_DIR)/boot/raspi4/common/%.c.o) \ - $(COMMON_ARCH_CFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.c=$(BUILD_DIR)/boot/raspi4/arch/%.c.o) \ - $(COMMON_ARCH_ASFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.S=$(BUILD_DIR)/boot/raspi4/arch/%.S.o) \ - $(PLATFORM_CFILES:$(BOOT_ROOT)/platform/$(PLATFORM)/%.c=$(BUILD_DIR)/boot/raspi4/%.c.o) \ - $(PLATFORM_ASFILES:$(BOOT_ROOT)/platform/$(PLATFORM)/%.S=$(BUILD_DIR)/boot/raspi4/%.S.o) +BOOT_OBJ := $(COMMON_CFILES:$(BOOT_ROOT)/common/%.c=$(BUILD_DIR)/boot/$(PLATFORM)/common/%.c.o) \ + $(COMMON_ARCH_CFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.c=$(BUILD_DIR)/boot/$(PLATFORM)/arch/%.c.o) \ + $(COMMON_ARCH_ASFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.S=$(BUILD_DIR)/boot/$(PLATFORM)/arch/%.S.o) \ + $(PLATFORM_CFILES:$(BOOT_ROOT)/platform/$(PLATFORM)/%.c=$(BUILD_DIR)/boot/$(PLATFORM)/%.c.o) \ + $(PLATFORM_ASFILES:$(BOOT_ROOT)/platform/$(PLATFORM)/%.S=$(BUILD_DIR)/boot/$(PLATFORM)/%.S.o) .PHONY: all all: $(BOOTFILE) @@ -54,13 +58,15 @@ all: $(BOOTFILE) .PHONY: install install: all @mkdir -p $(SYSROOT_DIR) - @printf " INSTALL\t/kernel.elf\n" - @cp $(BOOTFILE) $(SYSROOT_DIR)/kernel.elf + @printf " INSTALL\t/kernel8.img\n" + @cp $(BOOTFILE) $(SYSROOT_DIR)/kernel8.img $(BOOTFILE): $(BOOT_OBJ) @mkdir -p $(@D) - @printf " LD\t$(notdir $@)\n" - @$(BOOT_LD) $(BOOT_LDFLAGS) $^ -o $@ + @printf " LD\taxboot.elf\n" + @$(BOOT_LD) $(BOOT_LDFLAGS) $^ -o $(BUILD_DIR)/boot/raspi4/axboot.elf + @printf " OCOPY\t$(notdir $@)\n" + @$(BOOT_OBJCOPY) -O binary $(BUILD_DIR)/boot/raspi4/axboot.elf $@ -include $(wildcard $(BUILD_DIR)/boot/*.d) @@ -69,6 +75,11 @@ $(BUILD_DIR)/boot/raspi4/%.c.o: $(BOOT_ROOT)/platform/$(PLATFORM)/%.c @printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n" @$(BOOT_CC) $(BOOT_CFLAGS) -c $< -o $@ +$(BUILD_DIR)/boot/raspi4/%.S.o: $(BOOT_ROOT)/platform/$(PLATFORM)/%.S + @mkdir -p $(@D) + @printf " AS\t$(subst $(ROOT_DIR)/,,$<)\n" + @$(BOOT_AS) $(BOOT_ASFLAGS) -c $< -o $@ + $(BUILD_DIR)/boot/raspi4/common/%.c.o: $(BOOT_ROOT)/common/%.c @mkdir -p $(@D) @printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n" diff --git a/boot/arch/aarch64/common/boot.S b/boot/platform/raspi4/boot.S similarity index 99% rename from boot/arch/aarch64/common/boot.S rename to boot/platform/raspi4/boot.S index e133ea3..8b4f7bf 100644 --- a/boot/arch/aarch64/common/boot.S +++ b/boot/platform/raspi4/boot.S @@ -58,7 +58,7 @@ _start: cbnz w2, 3b 4: - bl menu_main + bl main_menu // // crazy? i was crazy once. diff --git a/kernel/Makefile b/kernel/Makefile index b98745c..e43d71c 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -56,21 +56,19 @@ KERNEL_LDFLAGS := -Tarch/$(ARCH)/linker.ld \ -static \ -no-pie -ifeq ($(DEBUG),yes) -KERNEL_CFLAGS += -g3 +ifeq ($(BUILD_TYPE),debug) +KERNEL_CFLAGS += -O0 -g3 else KERNEL_CFLAGS += -O2 endif -KERNEL_CFILES := $(shell find . -type d \( -name arch -o -name platform \) -prune -name '*.c') -KERNEL_ASFILES := $(shell find . -type d \( -name arch -o -name platform \) -prune -name '*.S') +KERNEL_CFILES := $(shell find . -type d \( -name arch -o -name platform \) -prune -o -name '*.c' -print) KERNEL_ARCH_CFILES := $(shell find arch/$(ARCH) -name '*.c') KERNEL_ARCH_ASFILES := $(shell find arch/$(ARCH) -name '*.S') KERNEL_PLATFORM_CFILES := $(shell find platform/$(PLATFORM) -name '*.c') KERNEL_PLATFORM_ASFILES := $(shell find platform/$(PLATFORM) -name '*.S') KERNEL_OBJ := $(KERNEL_CFILES:%.c=$(BUILD_DIR)/kernel/%.c.o) \ - $(KERNEL_ASFILES:%.S=$(BUILD_DIR)/kernel/%.S.o) \ $(KERNEL_ARCH_CFILES:arch/$(ARCH)/%.c=$(BUILD_DIR)/kernel/arch/%.c.o) \ $(KERNEL_ARCH_ASFILES:arch/$(ARCH)/%.S=$(BUILD_DIR)/kernel/arch/%.S.o) \ $(KERNEL_PLATFORM_CFILES:platform/$(PLATFORM)/%.c=$(BUILD_DIR)/kernel/platform/%.c.o) \ @@ -84,7 +82,7 @@ $(KERNEL_FILE): $(KERNEL_OBJ) @mkdir -p $(@D) @printf " LD\t$(notdir $@)\n" @$(KERNEL_LD) $(KERNEL_LDFLAGS) $^ -o $@ -ifeq ($(DEBUG),yes) +ifeq ($(BUILD_TYPE),debug) @printf " OBJCOPY axkrnl.sym\n" @$(KERNEL_OBJCOPY) --only-keep-debug $@ $(BUILD_DIR)/axkrnl.sym @$(KERNEL_OBJCOPY) --strip-debug --strip-unneeded $@