43 if (KernelSetup ==
NULL) {
44 return EFI_INVALID_PARAMETER;
47 if (KernelSetupSize <
sizeof (*Bp)) {
48 return EFI_UNSUPPORTED;
53 if ((Bp->hdr.signature != 0xAA55) ||
54 (Bp->hdr.header != SETUP_HDR) ||
55 (Bp->hdr.version < 0x205) ||
56 (!Bp->hdr.relocatable_kernel)
59 return EFI_UNSUPPORTED;
80 if (Bp->hdr.version > 0x20a) {
81 return Bp->hdr.init_size;
86 return 3 * KernelSize;
100 Status =
gBS->AllocatePages (
106 if (!EFI_ERROR (Status)) {
107 return (VOID *)(
UINTN)Address;
124 if (EFI_ERROR (Status)) {
130 SetupEnd = 0x202 + (Bp->hdr.jump & 0xff);
136 ZeroMem (((UINT8 *)KernelSetup) + SetupEnd, 4096 - SetupEnd);
139 "Cleared kernel setup 0-0x1f1, 0x%Lx-0x1000\n",
149 IN VOID *KernelSetup,
164 for (Loop = 1; Loop < 512; Loop++) {
166 2 * Bp->hdr.kernel_alignment,
169 Status =
gBS->AllocatePages (
175 if (!EFI_ERROR (Status)) {
176 return (VOID *)(
UINTN)KernelAddress;
193 Status =
gBS->AllocatePages (
199 if (!EFI_ERROR (Status)) {
200 return (VOID *)(
UINTN)Address;
209 IN VOID *KernelSetup,
225 Status =
gBS->AllocatePages (
231 if (!EFI_ERROR (Status)) {
232 return (VOID *)(
UINTN)Address;
245 UINT8 TmpMemoryMap[1];
247 UINTN DescriptorSize;
248 UINT32 DescriptorVersion;
256 UINTN E820EntryCount;
262 MemoryMapSize =
sizeof (TmpMemoryMap);
263 Status =
gBS->GetMemoryMap (
270 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
274 MemoryMapSize += EFI_PAGE_SIZE;
275 Status =
gBS->AllocatePool (
285 Status =
gBS->GetMemoryMap (
295 E820 = &Bp->e820_map[0];
298 MemoryMapPtr = MemoryMap;
299 for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
302 if (MemoryMap->NumberOfPages == 0) {
306 switch (MemoryMap->Type) {
313 E820Type = E820_RESERVED;
317 E820Type = E820_UNUSABLE;
321 E820Type = E820_ACPI;
339 "Invalid EFI memory descriptor type (0x%x)!\n",
345 if ((LastE820 !=
NULL) &&
346 (LastE820->type == (UINT32)E820Type) &&
347 (MemoryMap->PhysicalStart == LastEndAddr))
352 if (E820EntryCount >=
ARRAY_SIZE (Bp->e820_map)) {
356 E820->type = (UINT32)E820Type;
357 E820->addr = MemoryMap->PhysicalStart;
360 LastEndAddr = E820->addr + E820->size;
371 Bp->e820_entries = (UINT8)E820EntryCount;
374 Efi->efi_systab = (UINT32)(
UINTN)
gST;
375 Efi->efi_memdesc_size = (UINT32)DescriptorSize;
376 Efi->efi_memdesc_version = DescriptorVersion;
377 Efi->efi_memmap = (UINT32)(
UINTN)MemoryMapPtr;
378 Efi->efi_memmap_size = (UINT32)MemoryMapSize;
380 Efi->efi_loader_signature =
SIGNATURE_32 (
'E',
'L',
'3',
'2');
382 Efi->efi_systab_hi = (UINT32)(((UINT64)(
UINTN)
gST) >> 32);
383 Efi->efi_memmap_hi = (UINT32)(((UINT64)(
UINTN)MemoryMapPtr) >> 32);
384 Efi->efi_loader_signature =
SIGNATURE_32 (
'E',
'L',
'6',
'4');
393 IN OUT VOID *KernelSetup,
394 IN CHAR8 *CommandLine
401 if (EFI_ERROR (Status)) {
407 Bp->hdr.cmd_line_ptr = (UINT32)(
UINTN)CommandLine;
415 IN OUT VOID *KernelSetup,
424 if (EFI_ERROR (Status)) {
430 Bp->hdr.ramdisk_start = (UINT32)(
UINTN)Initrd;
431 Bp->hdr.ramdisk_len = (UINT32)InitrdSize;
449 while (!(Mask & 0x1)) {
466SetupGraphicsFromGop (
475 Status = Gop->QueryMode (Gop, Gop->
Mode->
Mode, &Size, &Info);
476 if (EFI_ERROR (Status)) {
483 Si->orig_video_isVGA = 0x70;
487 Si->orig_video_page = 0;
488 Si->orig_video_mode = 0;
489 Si->orig_video_cols = 0;
490 Si->orig_video_lines = 0;
491 Si->orig_video_ega_bx = 0;
492 Si->orig_video_points = 0;
545 Si->lfb_depth = Si->red_size + Si->green_size +
546 Si->blue_size + Si->rsvd_size;
558 Si->lfb_linelength = Si->lfb_width / 2;
576 ZeroMem ((VOID *)&Bp->screen_info, sizeof (Bp->screen_info));
578 Status =
gBS->LocateHandleBuffer (
580 &gEfiGraphicsOutputProtocolGuid,
585 if (!EFI_ERROR (Status)) {
586 for (Index = 0; Index < HandleCount; Index++) {
587 Status =
gBS->HandleProtocol (
589 &gEfiGraphicsOutputProtocolGuid,
592 if (EFI_ERROR (Status)) {
596 Status = SetupGraphicsFromGop (&Bp->screen_info, Gop);
597 if (!EFI_ERROR (Status)) {
606 return EFI_NOT_FOUND;
611SetupLinuxBootParams (
617 SetupLinuxMemmap (Bp);
626 IN OUT VOID *KernelSetup
633 if (EFI_ERROR (Status)) {
639 if ((Bp->hdr.version < 0x205) || !Bp->hdr.relocatable_kernel) {
643 return EFI_UNSUPPORTED;
648 Bp->hdr.code32_start = (UINT32)(
UINTN)Kernel;
649 if ((Bp->hdr.version >= 0x20c) && Bp->hdr.handover_offset &&
650 (Bp->hdr.xloadflags & ((
sizeof (
UINTN) == 4) ? BIT2 : BIT3)))
652 DEBUG ((DEBUG_INFO,
"Jumping to kernel EFI handover point at ofs %x\n", Bp->hdr.handover_offset));
655 JumpToUefiKernel ((VOID *)
gImageHandle, (VOID *)
gST, KernelSetup, Kernel);
661 SetupLinuxBootParams (KernelSetup);
663 DEBUG ((DEBUG_INFO,
"Jumping to kernel\n"));
666 JumpToKernel (Kernel, (VOID *)KernelSetup);
VOID EFIAPI DisableInterrupts(VOID)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI LoadLinuxInitializeKernelSetup(IN VOID *KernelSetup)
VOID *EFIAPI LoadLinuxAllocateCommandLinePages(IN UINTN Pages)
UINTN EFIAPI LoadLinuxGetKernelSize(IN VOID *KernelSetup, IN UINTN KernelSize)
STATIC EFI_STATUS EFIAPI BasicKernelSetupCheck(IN VOID *KernelSetup)
VOID *EFIAPI LoadLinuxAllocateKernelPages(IN VOID *KernelSetup, IN UINTN Pages)
EFI_STATUS EFIAPI LoadLinuxSetCommandLine(IN OUT VOID *KernelSetup, IN CHAR8 *CommandLine)
EFI_STATUS EFIAPI LoadLinux(IN VOID *Kernel, IN OUT VOID *KernelSetup)
EFI_STATUS EFIAPI LoadLinuxCheckKernelSetup(IN VOID *KernelSetup, IN UINTN KernelSetupSize)
VOID *EFIAPI LoadLinuxAllocateKernelSetupPages(IN UINTN Pages)
VOID *EFIAPI LoadLinuxAllocateInitrdPages(IN VOID *KernelSetup, IN UINTN Pages)
EFI_STATUS EFIAPI LoadLinuxSetInitrd(IN OUT VOID *KernelSetup, IN VOID *Initrd, IN UINTN InitrdSize)
VOID InitLinuxDescriptorTables(VOID)
VOID SetLinuxDescriptorTables(VOID)
#define ARRAY_SIZE(Array)
#define SIGNATURE_32(A, B, C, D)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
@ PixelRedGreenBlueReserved8BitPerColor
@ PixelBlueGreenRedReserved8BitPerColor
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
@ EfiMemoryMappedIOPortSpace
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
UINT32 VerticalResolution
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
UINT32 HorizontalResolution
EFI_PIXEL_BITMASK PixelInformation
EFI_PHYSICAL_ADDRESS FrameBufferBase