8#include <kernel/version.h>
13#define EXIT_BOOT_SERVICES_MAX_RETRY 5
18 Print(L
"Start %a-bootloader %a (Built %a %a)\n", OS_NAME, OS_VERSION, __DATE__, __TIME__);
20 Print(L
"Start %a-bootloader DEBUG %a (Built %a %a)\n", OS_NAME, OS_VERSION, __DATE__, __TIME__);
22 Print(L
"Copyright (C) 2025 Kai Norberg. MIT Licensed. See /usr/license/LICENSE for details.\n");
27 EFI_LOADED_IMAGE* loaded_image = 0;
28 EFI_GUID lipGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
29 EFI_FILE_IO_INTERFACE* IOVolume;
30 EFI_GUID fsGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
32 EFI_STATUS status = uefi_call_wrapper(BS->HandleProtocol, 3, imageHandle, &lipGuid, (
void**)&loaded_image);
33 if (EFI_ERROR(status))
38 status = uefi_call_wrapper(BS->HandleProtocol, 3, loaded_image->DeviceHandle, &fsGuid, (VOID*)&IOVolume);
39 if (EFI_ERROR(status))
44 status = uefi_call_wrapper(IOVolume->OpenVolume, 2, IOVolume,
file);
45 if (EFI_ERROR(status))
53static void*
rsdp_get(EFI_SYSTEM_TABLE* systemTable)
55 Print(L
"Searching for RSDP... ");
56 EFI_CONFIGURATION_TABLE* configTable = systemTable->ConfigurationTable;
57 EFI_GUID acpi2TableGuid = ACPI_20_TABLE_GUID;
60 for (
uint64_t i = 0; i < systemTable->NumberOfTableEntries; i++)
62 if (CompareGuid(&configTable[i].VendorGuid, &acpi2TableGuid) &&
63 CompareMem(
"RSD PTR ", configTable->VendorTable, 8) == 0)
65 rsdp = configTable->VendorTable;
72 Print(L
"failed to locate rsdp!\n");
76 Print(L
"found at %p!\n", rsdp);
84 if (EFI_ERROR(status))
99 if (EFI_ERROR(status))
101 Print(L
"failed to open root volume (0x%x)!\n", status);
102 return EFI_LOAD_ERROR;
106 if (EFI_ERROR(status))
112 if (EFI_ERROR(status))
129 Print(L
"Exiting boot services (attempt %d)...\n", retries + 1);
137 if (EFI_ERROR(status))
139 Print(L
"Failed to initialize memory map (0x%x)!\n", status);
143 status = uefi_call_wrapper(BS->ExitBootServices, 2, imageHandle, bootInfo->
memory.
map.
key);
144 if (EFI_ERROR(status))
146 if (status == EFI_INVALID_PARAMETER)
151 Print(L
"Too many retries!\n");
156 uefi_call_wrapper(BS->Stall, 1, 1000);
161 Print(L
"Failed to exit boot services (0x%x)!\n", status);
172EFI_STATUS
efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable)
174 InitializeLib(imageHandle, systemTable);
179 if (EFI_ERROR(status))
181 Print(L
"Failed to initialize memory (0x%x)!\n", status);
186 if (bootInfo ==
NULL)
188 Print(L
"Failed to allocate boot info!\n");
189 return EFI_OUT_OF_RESOURCES;
193 if (EFI_ERROR(status))
195 Print(L
"Failed to populate boot info (0x%x)!\n", status);
200 if (EFI_ERROR(status))
202 Print(L
"Failed to exit boot services (0x%x)!\n", status);
EFI_STATUS gop_buffer_init(boot_gop_t *buffer)
#define EXIT_BOOT_SERVICES_MAX_RETRY
static void * rsdp_get(EFI_SYSTEM_TABLE *systemTable)
static void splash_screen(void)
EFI_STATUS efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable)
static EFI_STATUS boot_info_populate(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable, boot_info_t *bootInfo)
static EFI_STATUS open_root_volume(EFI_FILE **file, EFI_HANDLE imageHandle)
static EFI_STATUS exit_boot_services(EFI_HANDLE imageHandle, boot_info_t *bootInfo)
EFI_STATUS disk_load(boot_disk_t *disk, EFI_FILE *rootHandle)
EFI_STATUS mem_map_init(boot_memory_map_t *map)
Initialize and load the memory map provided by the UEFI firmware.
void mem_page_table_init(page_table_t *table, boot_memory_map_t *map, boot_gop_t *gop, boot_kernel_t *kernel)
Initializes a page table for use by the kernel.
void mem_map_deinit(boot_memory_map_t *map)
Deinitializes the memory map and frees any allocated resources.
EFI_STATUS mem_init(void)
Initializes the basic memory allocator.
static void page_table_load(page_table_t *table)
Loads the page table into the CR3 register if it is not already loaded.
#define NULL
Pointer error value.
EFI_STATUS kernel_load(boot_kernel_t *kernel, EFI_FILE *rootHandle)
void(* entry)(boot_info_t *)