Create a kernel data area for passing information
This commit is contained in:
@@ -4,11 +4,14 @@
|
||||
static CHAR16 kernel_name[] = KERNEL_FILENAME;
|
||||
|
||||
EFI_STATUS
|
||||
loader_load_kernel(void **kernel_image, uint64_t *length)
|
||||
loader_load_kernel(void **kernel_image, uint64_t *kernel_length, void **kernel_data, uint64_t *data_length)
|
||||
{
|
||||
if (kernel_image == 0 || length == 0)
|
||||
if (kernel_image == 0 || kernel_length == 0)
|
||||
CHECK_EFI_STATUS_OR_RETURN(EFI_INVALID_PARAMETER, "NULL kernel_image or length pointer");
|
||||
|
||||
if (kernel_data == 0 || data_length == 0)
|
||||
CHECK_EFI_STATUS_OR_RETURN(EFI_INVALID_PARAMETER, "NULL kernel_data or length pointer");
|
||||
|
||||
EFI_STATUS status;
|
||||
EFI_GUID guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
|
||||
EFI_HANDLE *handles = NULL;
|
||||
@@ -48,7 +51,7 @@ loader_load_kernel(void **kernel_image, uint64_t *length)
|
||||
CHECK_EFI_STATUS_OR_RETURN(status, "Freeing kernel file info memory");
|
||||
|
||||
UINTN page_count = ((buffer_size - 1) / 0x1000) + 1;
|
||||
EFI_PHYSICAL_ADDRESS addr = KERNEL_PHYS_ADDRESS; // Try to load the kernel in at 1MiB
|
||||
EFI_PHYSICAL_ADDRESS addr = KERNEL_PHYS_ADDRESS;
|
||||
EFI_MEMORY_TYPE mem_type = KERNEL_MEMTYPE; // Special value to tell the kernel it's here
|
||||
status = ST->BootServices->AllocatePages(AllocateAddress, mem_type, page_count, &addr);
|
||||
if (status == EFI_NOT_FOUND) {
|
||||
@@ -57,6 +60,7 @@ loader_load_kernel(void **kernel_image, uint64_t *length)
|
||||
ST->BootServices->AllocatePages(AllocateAnyPages, mem_type, page_count, &addr);
|
||||
}
|
||||
CHECK_EFI_STATUS_OR_RETURN(status, "Allocating kernel pages");
|
||||
Print(L"\n Allocating %u pages at 0x%x", page_count, addr);
|
||||
|
||||
buffer = (void *)addr;
|
||||
status = file->Read(file, &buffer_size, buffer);
|
||||
@@ -65,8 +69,25 @@ loader_load_kernel(void **kernel_image, uint64_t *length)
|
||||
status = file->Close(file);
|
||||
CHECK_EFI_STATUS_OR_RETURN(status, "Closing kernel file handle");
|
||||
|
||||
*length = buffer_size;
|
||||
*kernel_length = buffer_size;
|
||||
*kernel_image = buffer;
|
||||
|
||||
addr += page_count * 0x1000; // Get the next page after the kernel pages
|
||||
mem_type = KERNEL_DATA_MEMTYPE; // Special value for kernel data
|
||||
page_count = ((*data_length - 1) / 0x1000) + 1;
|
||||
status = ST->BootServices->AllocatePages(AllocateAddress, mem_type, page_count, &addr);
|
||||
if (status == EFI_NOT_FOUND) {
|
||||
// couldn't get the address we wanted, try loading anywhere
|
||||
status =
|
||||
ST->BootServices->AllocatePages(AllocateAnyPages, mem_type, page_count, &addr);
|
||||
}
|
||||
CHECK_EFI_STATUS_OR_RETURN(status, "Allocating kernel data pages");
|
||||
Print(L"\n Allocating %u pages at 0x%x", page_count, addr);
|
||||
|
||||
*data_length = page_count * 0x1000;
|
||||
*kernel_data = (void *)addr;
|
||||
ST->BootServices->SetMem(*kernel_data, *data_length, 0);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user