diff --git a/.gitmodules b/.gitmodules index 9af33af..d00defe 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "boot/platform/uefi/libefi"] path = boot/platform/uefi/libefi - url = https://git.piraterna.org/Piraterna/libsefi + url = https://github.com/aurixos/efi diff --git a/Brewfile b/Brewfile index afff3ac..993024a 100644 --- a/Brewfile +++ b/Brewfile @@ -10,7 +10,6 @@ brew "make" brew "gptfdisk" brew "xorriso" brew "qemu" -brew "ffmpeg" brew "llvm" brew "lld" brew "util-linux" if OS.mac? diff --git a/Makefile b/Makefile index 2c740db..eb93a78 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,6 @@ .DEFAULT_GOAL := all -GITREV := $(shell git rev-parse --short HEAD) - ## # Build configuration # @@ -35,7 +33,7 @@ export BUILD_DIR ?= $(ROOT_DIR)/build export SYSROOT_DIR ?= $(ROOT_DIR)/sysroot export RELEASE_DIR ?= $(ROOT_DIR)/release -export NOUEFI ?= n +NOUEFI ?= n ## # Image generation and running @@ -45,19 +43,7 @@ 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 -rtc base=localtime -serial stdio - -# QEMU Audio support -#QEMU_FLAGS += -audiodev coreaudio,id=coreaudio0 -device ich9-intel-hda -device hda-output,audiodev=coreaudio0 - -# QEMU Mouse support -QEMU_FLAGS += -usb -device usb-mouse - -# x86_64 -# TODO: Move this elsewhere -ifeq ($(ARCH),x86_64) -QEMU_FLAGS += -machine q35 -endif +QEMU_FLAGS := -m 2G -smp 4 -serial stdio ## # General info @@ -89,7 +75,16 @@ all: boot kernel .PHONY: boot boot: @printf ">>> Building bootloader...\n" - @$(MAKE) -C boot all +ifneq (,$(filter $(ARCH),i686 x86_64)) + @$(MAKE) -C boot PLATFORM=pc-bios +else + @$(MAKE) -C boot +endif +ifneq (,$(filter $(ARCH),i686 x86_64 arm32 aarch64)) +ifeq ($(NOUEFI),n) + @$(MAKE) -C boot PLATFORM=uefi +endif +endif .PHONY: kernel kernel: @@ -135,21 +130,18 @@ livesd: install @mkdir -p $(RELEASE_DIR) @utils/arch/$(ARCH)/generate-sd.sh $(LIVESD) -# TODO: Maybe don't run with -hda but -drive? .PHONY: run -run: livehdd +run: livecd @printf ">>> Running QEMU...\n" - @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -hda $(LIVEHDD) + @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -cdrom $(LIVECD) -# TODO: Maybe don't run with -hda but -drive? .PHONY: run-uefi -run-uefi: livehdd ovmf +run-uefi: livecd ovmf @printf ">>> Running QEMU (UEFI)...\n" - @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -bios ovmf/ovmf-$(ARCH).fd -hda $(LIVEHDD) + @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -bios ovmf/ovmf-$(ARCH).fd -cdrom $(LIVECD) .PHONY: clean clean: - @$(MAKE) -C boot clean @rm -rf $(BUILD_DIR) $(SYSROOT_DIR) .PHONY: distclean diff --git a/boot/.gitignore b/boot/.gitignore deleted file mode 100644 index 64c59cb..0000000 --- a/boot/.gitignore +++ /dev/null @@ -1 +0,0 @@ -include/sounds \ No newline at end of file diff --git a/boot/Makefile b/boot/Makefile index 79e063c..ea5ec46 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -28,11 +28,9 @@ export BUILD_DIR ?= build export SYSROOT_DIR ?= sysroot export ASFLAGS := $(foreach d, $(DEFINES), -D$d) -export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -Wno-unused-local-typedef -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP +export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP export LDFLAGS := -nostdlib -include arch/$(ARCH)/config.mk - export BOOT_ROOT := $(ROOT_DIR)/boot ifeq ($(BUILD_TYPE),debug) @@ -42,37 +40,13 @@ CFLAGS += -O2 endif .PHONY: all -all: sounds -ifneq (,$(filter $(ARCH),i686 x86_64)) - @$(MAKE) -C platform/pc-bios all -else +all: @$(MAKE) -C platform/$(PLATFORM) all -endif -ifneq (,$(filter $(ARCH),i686 x86_64 arm32 aarch64)) -ifeq ($(NOUEFI),n) - @$(MAKE) -C platform/uefi all -# @$(MAKE) -C drivers all -endif -endif - -.PHONY: sounds -sounds: - @mkdir -p $(BUILD_DIR)/boot/sounds - @mkdir -p $(BOOT_ROOT)/include/sounds - @for f in $(BOOT_ROOT)/sound/*.mp3; do \ - file=$$(basename $$f ".$${f##*.}") ; \ - printf " GEN\t$$file.h\n" ; \ - ffmpeg -i "$$f" -acodec pcm_s16le -f s16le -ac 2 "$(BUILD_DIR)/boot/sounds/$$file.raw" -y 2>/dev/null ; \ - python3 $(ROOT_DIR)/utils/bin_to_header.py "$(BUILD_DIR)/boot/sounds/$$file.raw" "$(BOOT_ROOT)/include/sounds/$$file.h" $$file ; \ - done .PHONY: install install: @$(MAKE) -C platform/$(PLATFORM) install -# @$(MAKE) -C drivers install - @mkdir -p $(SYSROOT_DIR)/AxBoot - @cp -r base/* $(SYSROOT_DIR)/AxBoot .PHONY: clean clean: - @rm -rf $(BOOT_ROOT)/include/sounds + @$(MAKE) -C platform/$(PLATFORM) clean diff --git a/boot/arch/aarch64/config.mk b/boot/arch/aarch64/config.mk deleted file mode 100644 index e69de29..0000000 diff --git a/boot/arch/i686/config.mk b/boot/arch/i686/config.mk deleted file mode 100644 index 65b82a4..0000000 --- a/boot/arch/i686/config.mk +++ /dev/null @@ -1 +0,0 @@ -CFLAGS += -DARCH_ACPI_AVAILABLE -DARCH_SMBIOS_AVAILABLE \ No newline at end of file diff --git a/boot/arch/x86_64/common/mm/paging.c b/boot/arch/x86_64/common/mm/paging.c index 827201e..40826fd 100644 --- a/boot/arch/x86_64/common/mm/paging.c +++ b/boot/arch/x86_64/common/mm/paging.c @@ -58,6 +58,10 @@ static void _map(pagetable *pm, uintptr_t virt, uintptr_t phys, uint64_t flags) } pagetable *pml1_table = (pagetable *)(pml2_table->entries[pml2_idx] & 0x000FFFFFFFFFF000); + if ((pml1_table->entries[pml1_idx] & 1)) { + // debug("_map(): Remapping present page\n"); + } + pml1_table->entries[pml1_idx] = (phys & 0x000FFFFFFFFFF000) | flags; } diff --git a/boot/arch/x86_64/common/proto/aurix/handoff.c b/boot/arch/x86_64/common/proto/aurix/handoff.c deleted file mode 100644 index f23645e..0000000 --- a/boot/arch/x86_64/common/proto/aurix/handoff.c +++ /dev/null @@ -1,115 +0,0 @@ -/*********************************************************************************/ -/* Module Name: handoff.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 -#include -#include -#include -#include -#include - -struct gdt { - struct gdt_descriptor null; - struct gdt_descriptor kcode; - struct gdt_descriptor kdata; - struct gdt_descriptor ucode; - struct gdt_descriptor udata; - struct tss_descriptor tss; -}; - -void aurix_arch_handoff(void *kernel_entry, pagetable *pm, void *stack, uint32_t stack_size, struct aurix_parameters *parameters) -{ - struct tss tss = { - .iomap_base = sizeof(struct tss), - }; - - struct gdt gdt = { - .tss = { - .gdt = { - .base_low = ((uintptr_t)&tss) & 0xFFFF, - .base_mid = (((uintptr_t)&tss) >> 16) & 0xFF, - .base_high = (((uintptr_t)&tss) >> 24) & 0xFF, - .access = 0b10001001 - }, - .base_high = (((uintptr_t)&tss) >> 32) & 0xFFFF - }, - }; - - struct gdtr gdtr = { - .base = (uint64_t)&gdt, - .limit = sizeof(gdt) - 1 - }; - - gdt_set_entry(&gdt.null, 0, 0, 0, 0); - gdt_set_entry(&gdt.kcode, 0, 0, 0x9a, 0xaf); - gdt_set_entry(&gdt.kdata, 0, 0, 0x92, 0xcf); - gdt_set_entry(&gdt.ucode, 0, 0, 0xfa, 0xaf); - gdt_set_entry(&gdt.udata, 0, 0, 0xf2, 0xcf); - - struct idtr idtr = { - .base = (uint64_t)0, - .limit = 0 - }; - - __asm__ volatile( - "cli\n" - //"lgdt %[gdtr]\n" - //"ltr %[tss]\n" - //"pushq $0x08\n" - //"lea 1f(%%rip), %%rax\n" - //"pushq %%rax\n" - //"lretq\n" - //"1:\n" - //"movq $0x10, %%rax\n" - //"movq %%rax, %%ds\n" - //"movq %%rax, %%es\n" - //"movq %%rax, %%ss\n" - //"movq %%rax, %%fs\n" - //"movq %%rax, %%gs\n" - - //"lidt %[idt]\n" - - "movq %[pml4], %%cr3\n" - "movq %[stack], %%rsp\n" - "movq %[params], %%rdi\n" - "movq %[entry], %%rsi\n" - - // rsi = kernel entry point addr - // rdi = kernel parameters - "xor %%rax, %%rax\n" - "xor %%rbx, %%rbx\n" - "xor %%rcx, %%rcx\n" - "xor %%rdx, %%rdx\n" - //"xor %%rdi, %%rdi\n" - //"xor %%rsi, %%rsi\n" - "xor %%r8, %%r8\n" - "xor %%r9, %%r9\n" - "xor %%r10, %%r10\n" - "xor %%r11, %%r11\n" - "xor %%r12, %%r12\n" - "xor %%r13, %%r13\n" - "xor %%r14, %%r14\n" - "xor %%r15, %%r15\n" - - "callq *%%rsi\n" - :: [gdtr]"g"(gdtr), [tss]"r"((uint16_t)__builtin_offsetof(struct gdt, tss)), - [idt]"g"(idtr), - [pml4]"r"(pm), [stack]"r"(stack + stack_size), - [entry]"r"(kernel_entry), [params]"d"(parameters) : "rax", "memory"); -} \ No newline at end of file diff --git a/boot/arch/x86_64/common/proto/aurix_handoff.S b/boot/arch/x86_64/common/proto/aurix_handoff.S new file mode 100644 index 0000000..7c8f896 --- /dev/null +++ b/boot/arch/x86_64/common/proto/aurix_handoff.S @@ -0,0 +1,24 @@ +.globl _aurix_handoff_start +.globl _aurix_handoff_end +.globl aurix_handoff + +_aurix_handoff_start: +aurix_handoff: + cli + movq %rsi, %rsp +.section _aurix_handoff + movq %rdi, %cr3 + xor %rax, %rax + xor %rbx, %rbx + xor %rcx, %rcx + xor %rdi, %rdi + xor %r8, %r8 + xor %r9, %r9 + xor %r10, %r10 + xor %r11, %r11 + xor %r12, %r12 + xor %r13, %r13 + xor %r14, %r14 + xor %r15, %r15 + callq *%rdx +_aurix_handoff_end: \ No newline at end of file diff --git a/boot/arch/x86_64/common/uart/uart.c b/boot/arch/x86_64/common/uart/uart.c deleted file mode 100644 index 7403a78..0000000 --- a/boot/arch/x86_64/common/uart/uart.c +++ /dev/null @@ -1,56 +0,0 @@ -/*********************************************************************************/ -/* Module Name: uart.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 - -#include -#include - -#define COM1 0x3f8 - -void uart_init(uint32_t baud_rate) -{ - uint8_t divisor = 115200 / baud_rate; - - outb(COM1 + 1, 0x00); - outb(COM1 + 3, 0x80); - outb(COM1 + 0, divisor & 0xFF); - outb(COM1 + 1, (divisor >> 8) & 0xFF); - outb(COM1 + 3, 0x03); - outb(COM1 + 2, 0xC7); - outb(COM1 + 4, 0x0B); - outb(COM1 + 4, 0x0F); -} - -void uart_send(char c) -{ - while ((inb(COM1 + 5) & 0x20) == 0); - outb(COM1, c); -} - -void uart_sendstr(char *str) -{ - while (*str != '\0') { - if (*str == '\n') { - uart_send('\r'); - } - uart_send(*str); - str++; - } -} \ No newline at end of file diff --git a/boot/arch/x86_64/config.mk b/boot/arch/x86_64/config.mk deleted file mode 100644 index 65b82a4..0000000 --- a/boot/arch/x86_64/config.mk +++ /dev/null @@ -1 +0,0 @@ -CFLAGS += -DARCH_ACPI_AVAILABLE -DARCH_SMBIOS_AVAILABLE \ No newline at end of file diff --git a/boot/base/axboot.cfg b/boot/base/axboot.cfg index 0de7fe4..ccfec46 100644 --- a/boot/base/axboot.cfg +++ b/boot/base/axboot.cfg @@ -1,13 +1,12 @@ -;; please leave this here, the parser breaks without it +; This is a comment -default = 0 -timeout = 30 -ui = text +entry "AurixOS" { + PROTOCOL="aurix" + IMAGE_PATH="boot:///System/axkrnl.sys" +} -[AurixOS] -protocol = aurix -image = boot:///System/axkrnl.sys - -[Windows 10] -protocol = efi-chainload -image = boot:///EFI/Microsoft/bootmgfw.efi \ No newline at end of file +;; UEFI only +entry "Windows" { + PROTOCOL="chainload" + IMAGE_PATH="boot:///EFI/Microsoft/bootmgfw.efi" +} diff --git a/boot/base/fonts/u_vga16/u_vga16.sfn b/boot/base/fonts/u_vga16/u_vga16.sfn deleted file mode 100644 index 5d5a4d0..0000000 Binary files a/boot/base/fonts/u_vga16/u_vga16.sfn and /dev/null differ diff --git a/boot/base/fonts/vera/Vera.sfn b/boot/base/fonts/vera/Vera.sfn deleted file mode 100644 index 4c4b0f3..0000000 Binary files a/boot/base/fonts/vera/Vera.sfn and /dev/null differ diff --git a/boot/common/config/config.c b/boot/common/config/config.c index 57352e0..1fef728 100644 --- a/boot/common/config/config.c +++ b/boot/common/config/config.c @@ -17,11 +17,8 @@ /* SOFTWARE. */ /*********************************************************************************/ -#include #include -#include #include -#include