summaryrefslogtreecommitdiff
path: root/boot/x86_64/entry.cpp
blob: b9f710d501506ffce268b59a3cc429a86720be45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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");
}