| 1 |
#include <efi.h> |
| 2 |
#include <efilib.h> |
| 3 |
|
| 4 |
extern EFI_GUID GraphicsOutputProtocol; |
| 5 |
|
| 6 |
static void |
| 7 |
fill_boxes(UINT32 *PixelBuffer, UINT32 Width, UINT32 Height) |
| 8 |
{ |
| 9 |
UINT32 y, x = 0; |
| 10 |
/* |
| 11 |
* This assums BGRR, but it doesn't really matter; we pick red and |
| 12 |
* green so it'll just be blue/green if the pixel format is backwards. |
| 13 |
*/ |
| 14 |
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Red = {0, 0, 0xff, 0}, |
| 15 |
Green = {0, 0xff, 0, 0}, |
| 16 |
*Color; |
| 17 |
|
| 18 |
for (y = 0; y < Height; y++) { |
| 19 |
Color = ((y / 32) % 2 == 0) ? &Red : &Green; |
| 20 |
for (x = 0; x < Width; x++) { |
| 21 |
if (x % 32 == 0 && x != 0) |
| 22 |
Color = (Color == &Red) ? &Green : &Red; |
| 23 |
PixelBuffer[y * Width + x] = *(UINT32 *)Color; |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
static void |
| 29 |
draw_boxes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) |
| 30 |
{ |
| 31 |
int i, imax; |
| 32 |
EFI_STATUS rc; |
| 33 |
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; |
| 34 |
UINTN NumPixels; |
| 35 |
UINT32 *PixelBuffer; |
| 36 |
UINT32 BufferSize; |
| 37 |
|
| 38 |
if (gop->Mode) { |
| 39 |
imax = gop->Mode->MaxMode; |
| 40 |
} else { |
| 41 |
Print(L"gop->Mode is NULL\n"); |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
for (i = 0; i < imax; i++) { |
| 46 |
UINTN SizeOfInfo; |
| 47 |
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo, |
| 48 |
&info); |
| 49 |
if (EFI_ERROR(rc) && rc == EFI_NOT_STARTED) { |
| 50 |
Print(L"gop->QueryMode() returned %r\n", rc); |
| 51 |
Print(L"Trying to start GOP with SetMode().\n"); |
| 52 |
rc = uefi_call_wrapper(gop->SetMode, 2, gop, |
| 53 |
gop->Mode ? gop->Mode->Mode : 0); |
| 54 |
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, |
| 55 |
&SizeOfInfo, &info); |
| 56 |
} |
| 57 |
|
| 58 |
if (EFI_ERROR(rc)) { |
| 59 |
Print(L"%d: Bad response from QueryMode: %r (%d)\n", |
| 60 |
i, rc, rc); |
| 61 |
continue; |
| 62 |
} |
| 63 |
|
| 64 |
if (CompareMem(info, gop->Mode->Info, sizeof (*info))) |
| 65 |
continue; |
| 66 |
|
| 67 |
NumPixels = (UINTN)info->VerticalResolution |
| 68 |
* (UINTN)info->HorizontalResolution; |
| 69 |
BufferSize = NumPixels * sizeof(UINT32); |
| 70 |
|
| 71 |
PixelBuffer = AllocatePool(BufferSize); |
| 72 |
if (!PixelBuffer) { |
| 73 |
Print(L"Allocation of 0x%08lx bytes failed.\n", |
| 74 |
sizeof(UINT32) * NumPixels); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
fill_boxes(PixelBuffer, |
| 79 |
info->HorizontalResolution, info->VerticalResolution); |
| 80 |
|
| 81 |
uefi_call_wrapper(gop->Blt, 10, gop, |
| 82 |
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)PixelBuffer, |
| 83 |
EfiBltBufferToVideo, |
| 84 |
0, 0, 0, 0, |
| 85 |
info->HorizontalResolution, |
| 86 |
info->VerticalResolution, |
| 87 |
0); |
| 88 |
return; |
| 89 |
} |
| 90 |
Print(L"Never found the active video mode?\n"); |
| 91 |
} |
| 92 |
|
| 93 |
static EFI_STATUS |
| 94 |
SetWatchdog(UINTN seconds) |
| 95 |
{ |
| 96 |
EFI_STATUS rc; |
| 97 |
rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff, |
| 98 |
0, NULL); |
| 99 |
if (EFI_ERROR(rc)) { |
| 100 |
CHAR16 Buffer[64]; |
| 101 |
StatusToString(Buffer, rc); |
| 102 |
Print(L"Bad response from QueryMode: %s (%d)\n", Buffer, rc); |
| 103 |
} |
| 104 |
return rc; |
| 105 |
} |
| 106 |
|
| 107 |
EFI_STATUS |
| 108 |
efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) |
| 109 |
{ |
| 110 |
EFI_STATUS rc; |
| 111 |
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; |
| 112 |
|
| 113 |
InitializeLib(image_handle, systab); |
| 114 |
|
| 115 |
SetWatchdog(10); |
| 116 |
|
| 117 |
rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop); |
| 118 |
if (EFI_ERROR(rc)) { |
| 119 |
Print(L"Could not locate GOP: %r\n", rc); |
| 120 |
return rc; |
| 121 |
} |
| 122 |
|
| 123 |
if (!gop) { |
| 124 |
Print(L"LocateProtocol(GOP, &gop) returned %r but GOP is NULL\n", rc); |
| 125 |
return EFI_UNSUPPORTED; |
| 126 |
} |
| 127 |
|
| 128 |
draw_boxes(gop); |
| 129 |
|
| 130 |
SetWatchdog(0); |
| 131 |
return EFI_SUCCESS; |
| 132 |
} |