Last Updated: February 25, 2016
·
2.712K
· daiakushi

UEFI Shell - Graphics Output Protocol

Make use of GOP to write a GUI application under UEFI shell.

#include <Uefi.h>
#include <Protocol/GraphicsOutput.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>

EFI_GRAPHICS_OUTPUT_PROTOCOL        *Gop;

EFI_STATUS Init() {
    EFI_STATUS      status;
    UINTN           handleCount;
    EFI_HANDLE      *handleBuffer;

    status = gBS->LocateHandleBuffer(
                    ByProtocol,
                    &gEfiGraphicsOutputProtocolGuid,
                    NULL,
                    &handleCount,
                    &handleBuffer);
    if (EFI_ERROR(status)) return status;

    status = gBS->HandleProtocol(
                    handleBuffer[0],    // TODO
                    &gEfiGraphicsOutputProtocolGuid,
                    (VOID **)&(Gop));
    if (EFI_ERROR(status)) return status;

    FreePool(handleBuffer);
    return status;
}