Fill in kernel initialization block
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
2022-12-21 20:04:20 +01:00
parent 652e3293b1
commit cf828a6896
6 changed files with 116 additions and 4 deletions

View File

@@ -156,27 +156,58 @@ XtpInitializeLoaderBlock(IN PLIST_ENTRY MemoryMappings, IN PVOID *VirtualAddress
{
PKERNEL_INITIALIZATION_BLOCK LoaderBlock;
EFI_PHYSICAL_ADDRESS Address;
PVOID RuntimeServices;
EFI_STATUS Status;
UINT BlockPages;
/* Calculate number of pages needed for initialization block */
BlockPages = EFI_SIZE_TO_PAGES(sizeof(KERNEL_INITIALIZATION_BLOCK));
/* Allocate memory for kernel initialization block */
Status = XtLdrProtocol->AllocatePages(BlockPages, &Address);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
return Status;
}
/* Initialize and zero-fill kernel initialization block */
LoaderBlock = (PKERNEL_INITIALIZATION_BLOCK)(UINT_PTR)Address;
RtlZeroMemory(LoaderBlock, sizeof(KERNEL_INITIALIZATION_BLOCK));
LoaderBlock->LoaderInformation.DbgPrint = XtLdrProtocol->DbgPrint;
/* Set basic loader block properties */
LoaderBlock->Size = sizeof(KERNEL_INITIALIZATION_BLOCK);
LoaderBlock->Version = INITIALIZATION_BLOCK_VERSION;
XtLdrProtocol->AddVirtualMemoryMapping(MemoryMappings, *VirtualAddress, (PVOID)LoaderBlock, BlockPages, LoaderSystemBlock);
/* No kernel stack available now */
LoaderBlock->KernelStack = (ULONG_PTR)NULL;
/* Set LoaderInformation block properties */
LoaderBlock->LoaderInformation.DbgPrint = XtLdrProtocol->DbgPrint;
/* Attempt to find virtual address of the EFI Runtime Services */
Status = XtLdrProtocol->GetVirtualAddress(MemoryMappings, &EfiSystemTable->RuntimeServices->Hdr, &RuntimeServices);
if(Status == STATUS_EFI_SUCCESS)
{
/* Set FirmwareInformation block properties */
LoaderBlock->FirmwareInformation.FirmwareType = SystemFirmwareEfi;
LoaderBlock->FirmwareInformation.EfiFirmware.EfiVersion = EfiSystemTable->Hdr.Revision;
LoaderBlock->FirmwareInformation.EfiFirmware.EfiRuntimeServices = RuntimeServices;
}
else
{
/* Set invalid firmware type to indicate that kernel cannot rely on FirmwareInformation block */
LoaderBlock->FirmwareInformation.FirmwareType = SystemFirmwareInvalid;
}
/* Map kernel initialization block */
XtLdrProtocol->AddVirtualMemoryMapping(MemoryMappings, *VirtualAddress, (PVOID)LoaderBlock,
BlockPages, LoaderSystemBlock);
/* Calculate next valid virtual address */
*VirtualAddress += (UINT_PTR)(BlockPages * EFI_PAGE_SIZE);
/* Return success */
return STATUS_EFI_SUCCESS;
}