diff --git a/Makefile b/Makefile index 2582f48..2c740db 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@ .DEFAULT_GOAL := all +GITREV := $(shell git rev-parse --short HEAD) + ## # Build configuration # @@ -52,7 +54,10 @@ QEMU_FLAGS := -m 2G -smp 4 -rtc base=localtime -serial stdio QEMU_FLAGS += -usb -device usb-mouse # x86_64 +# TODO: Move this elsewhere +ifeq ($(ARCH),x86_64) QEMU_FLAGS += -machine q35 +endif ## # General info @@ -130,15 +135,17 @@ 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: diff --git a/boot/Makefile b/boot/Makefile index e1fb122..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) 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/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/common/config/config.c b/boot/common/config/config.c index c0d5a21..57352e0 100644 --- a/boot/common/config/config.c +++ b/boot/common/config/config.c @@ -18,10 +18,10 @@ /*********************************************************************************/ #include -#include #include #include #include +#include