summaryrefslogtreecommitdiff
path: root/boot/x86_64/entry.cpp
diff options
context:
space:
mode:
authorArseney300 <Arseney300@gmail.com>2026-03-29 02:07:17 +0700
committerArseney300 <Arseney300@gmail.com>2026-04-08 01:19:07 +0700
commit4912796d2e88c6eb5d02fbf0fb9c39f8c9f7cd4c (patch)
tree9ee8110e2c090c888f23797cda56c7e2df531695 /boot/x86_64/entry.cpp
bastion: initial implementation
ready project skeleton dual-arch build system with Linux-config style configuration UEFI EFI stub loader (PE32+) for x86_64 and AArch64 ELF64 kernel parser Temporary framebuffer console freestanding string and c++ abi stubs For now, kernel boots, prints banner, memory map and go halt
Diffstat (limited to 'boot/x86_64/entry.cpp')
-rw-r--r--boot/x86_64/entry.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/boot/x86_64/entry.cpp b/boot/x86_64/entry.cpp
new file mode 100644
index 0000000..b9f710d
--- /dev/null
+++ b/boot/x86_64/entry.cpp
@@ -0,0 +1,29 @@
+// ============================================================================
+// x86_64/entry.cpp - UEFI entry point for x86_64
+//
+// Kernel entry: extern "C" [[noreturn]] void kernel_main(BootInfo*);
+// ============================================================================
+
+#include <boot/efi.h>
+#include <boot/boot_info.h>
+
+extern bool efi_loader_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE* system_table, BootInfo* boot_info);
+
+static BootInfo g_boot_info{};
+
+typedef void (*KernelEntry)(BootInfo*);
+
+extern "C" EFI_STATUS EFIAPI efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE* system_table) {
+ if (!efi_loader_main(image_handle, system_table, &g_boot_info)) {
+ return EFI_LOAD_ERROR;
+ }
+
+ // Post-ExitBootServices: compute physical entry and jump
+ uint64_t entry_offset = g_boot_info.kernel_entry_point - g_boot_info.kernel_virt_base;
+ uint64_t phys_entry = g_boot_info.kernel_phys_base + entry_offset;
+
+ auto kernel_entry = reinterpret_cast<KernelEntry>(phys_entry);
+ kernel_entry(&g_boot_info); // RDI = &g_boot_info (System V ABI)
+
+ for (;;) asm volatile("hlt");
+}