13 return EFI_INVALID_PARAMETER;
16 Print(L
"Loading kernel... ");
18 EFI_FILE* kernelDir =
NULL;
20 EFI_STATUS status = EFI_SUCCESS;
23 status = uefi_call_wrapper(rootHandle->Open, 5, rootHandle, &kernelDir, L
"kernel", EFI_FILE_MODE_READ, 0);
24 if (EFI_ERROR(status))
26 Print(L
"failed to open boot directory (0x%x)!\n", status);
30 status = uefi_call_wrapper(kernelDir->Open, 5, kernelDir, &
file, L
"kernel", EFI_FILE_MODE_READ, 0);
31 if (EFI_ERROR(status))
33 Print(L
"failed to open kernel file (0x%x)!\n", status);
37 EFI_FILE_INFO* fileInfo = LibFileInfo(
file);
40 Print(L
"failed to get kernel file info (0x%x)!\n", status);
41 status = EFI_LOAD_ERROR;
44 uint64_t fileSize = fileInfo->FileSize;
47 void* fileData = AllocatePool(fileSize);
50 Print(L
"failed to allocate memory for kernel file (0x%x)!\n", status);
51 status = EFI_OUT_OF_RESOURCES;
56 status = uefi_call_wrapper(
file->Read, 3,
file, &readSize, fileData);
57 if (EFI_ERROR(status) || readSize != fileSize)
59 Print(L
"failed to read kernel file (0x%x)!\n", status);
67 Print(L
"invalid kernel ELF file %d!\n", result);
69 status = EFI_LOAD_ERROR;
78 Print(L
"allocating %llu pages... ", kernelPageAmount);
80 uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiReservedMemoryType, kernelPageAmount, &physStart);
81 if (EFI_ERROR(status))
83 Print(L
"failed to allocate pages for kernel (0x%x)!\n", status);
87 Print(L
"loading segments to 0x%p... ", physStart);
95 if (EFI_ERROR(status) && physStart !=
NULL)
97 uefi_call_wrapper(BS->FreePages, 2, (EFI_PHYSICAL_ADDRESS)(
uintptr_t)physStart,
103 uefi_call_wrapper(
file->Close, 1,
file);
105 if (kernelDir !=
NULL)
107 uefi_call_wrapper(kernelDir->Close, 1, kernelDir);
uint64_t elf64_validate(Elf64_File *elf, void *data, uint64_t size)
Validate a files content and initalize a ELF64_File structure using it.