diff --git a/.gitmodules b/.gitmodules index d00defe..9af33af 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "boot/platform/uefi/libefi"] path = boot/platform/uefi/libefi - url = https://github.com/aurixos/efi + url = https://git.piraterna.org/Piraterna/libsefi diff --git a/Brewfile b/Brewfile index 993024a..afff3ac 100644 --- a/Brewfile +++ b/Brewfile @@ -10,6 +10,7 @@ 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 eb93a78..2c740db 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@ .DEFAULT_GOAL := all +GITREV := $(shell git rev-parse --short HEAD) + ## # Build configuration # @@ -33,7 +35,7 @@ export BUILD_DIR ?= $(ROOT_DIR)/build export SYSROOT_DIR ?= $(ROOT_DIR)/sysroot export RELEASE_DIR ?= $(ROOT_DIR)/release -NOUEFI ?= n +export NOUEFI ?= n ## # Image generation and running @@ -43,7 +45,19 @@ 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 +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 ## # General info @@ -75,16 +89,7 @@ all: boot kernel .PHONY: boot boot: @printf ">>> Building bootloader...\n" -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 + @$(MAKE) -C boot all .PHONY: kernel kernel: @@ -130,18 +135,21 @@ 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: livecd +run: livehdd @printf ">>> Running QEMU...\n" - @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -cdrom $(LIVECD) + @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -hda $(LIVEHDD) +# TODO: Maybe don't run with -hda but -drive? .PHONY: run-uefi -run-uefi: livecd ovmf +run-uefi: livehdd ovmf @printf ">>> Running QEMU (UEFI)...\n" - @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -bios ovmf/ovmf-$(ARCH).fd -cdrom $(LIVECD) + @qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -bios ovmf/ovmf-$(ARCH).fd -hda $(LIVEHDD) .PHONY: clean clean: + @$(MAKE) -C boot clean @rm -rf $(BUILD_DIR) $(SYSROOT_DIR) .PHONY: distclean diff --git a/boot/.gitignore b/boot/.gitignore new file mode 100644 index 0000000..64c59cb --- /dev/null +++ b/boot/.gitignore @@ -0,0 +1 @@ +include/sounds \ No newline at end of file diff --git a/boot/Makefile b/boot/Makefile index ea5ec46..79e063c 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -28,9 +28,11 @@ export BUILD_DIR ?= build export SYSROOT_DIR ?= sysroot export ASFLAGS := $(foreach d, $(DEFINES), -D$d) -export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP +export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -Wno-unused-local-typedef -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) @@ -40,13 +42,37 @@ CFLAGS += -O2 endif .PHONY: all -all: +all: sounds +ifneq (,$(filter $(ARCH),i686 x86_64)) + @$(MAKE) -C platform/pc-bios all +else @$(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: - @$(MAKE) -C platform/$(PLATFORM) clean + @rm -rf $(BOOT_ROOT)/include/sounds diff --git a/boot/arch/aarch64/config.mk b/boot/arch/aarch64/config.mk new file mode 100644 index 0000000..e69de29 diff --git a/boot/arch/i686/config.mk b/boot/arch/i686/config.mk new file mode 100644 index 0000000..65b82a4 --- /dev/null +++ b/boot/arch/i686/config.mk @@ -0,0 +1 @@ +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 40826fd..827201e 100644 --- a/boot/arch/x86_64/common/mm/paging.c +++ b/boot/arch/x86_64/common/mm/paging.c @@ -58,10 +58,6 @@ 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 new file mode 100644 index 0000000..f23645e --- /dev/null +++ b/boot/arch/x86_64/common/proto/aurix/handoff.c @@ -0,0 +1,115 @@ +/*********************************************************************************/ +/* 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 deleted file mode 100644 index 7c8f896..0000000 --- a/boot/arch/x86_64/common/proto/aurix_handoff.S +++ /dev/null @@ -1,24 +0,0 @@ -.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 new file mode 100644 index 0000000..7403a78 --- /dev/null +++ b/boot/arch/x86_64/common/uart/uart.c @@ -0,0 +1,56 @@ +/*********************************************************************************/ +/* 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 new file mode 100644 index 0000000..65b82a4 --- /dev/null +++ b/boot/arch/x86_64/config.mk @@ -0,0 +1 @@ +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 ccfec46..0de7fe4 100644 --- a/boot/base/axboot.cfg +++ b/boot/base/axboot.cfg @@ -1,12 +1,13 @@ -; This is a comment +;; please leave this here, the parser breaks without it -entry "AurixOS" { - PROTOCOL="aurix" - IMAGE_PATH="boot:///System/axkrnl.sys" -} +default = 0 +timeout = 30 +ui = text -;; UEFI only -entry "Windows" { - PROTOCOL="chainload" - IMAGE_PATH="boot:///EFI/Microsoft/bootmgfw.efi" -} +[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 diff --git a/boot/base/fonts/u_vga16/u_vga16.sfn b/boot/base/fonts/u_vga16/u_vga16.sfn new file mode 100644 index 0000000..5d5a4d0 Binary files /dev/null and b/boot/base/fonts/u_vga16/u_vga16.sfn differ diff --git a/boot/base/fonts/vera/Vera.sfn b/boot/base/fonts/vera/Vera.sfn new file mode 100644 index 0000000..4c4b0f3 Binary files /dev/null and b/boot/base/fonts/vera/Vera.sfn differ diff --git a/boot/common/config/config.c b/boot/common/config/config.c index 1fef728..57352e0 100644 --- a/boot/common/config/config.c +++ b/boot/common/config/config.c @@ -17,8 +17,11 @@ /* SOFTWARE. */ /*********************************************************************************/ +#include #include +#include #include +#include