diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-19 16:36:51 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-19 16:37:54 -0400 |
commit | 472ec944d2ed81d0304cc6cac80946a6a44776be (patch) | |
tree | f6cae641c143a0b45bb289d9d9fc6145706025b0 /kernel/efi/gop.c | |
parent | set mmap limit (diff) | |
download | comus-472ec944d2ed81d0304cc6cac80946a6a44776be.tar.gz comus-472ec944d2ed81d0304cc6cac80946a6a44776be.tar.bz2 comus-472ec944d2ed81d0304cc6cac80946a6a44776be.zip |
UEFI and republicans
Diffstat (limited to 'kernel/efi/gop.c')
-rw-r--r-- | kernel/efi/gop.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/kernel/efi/gop.c b/kernel/efi/gop.c new file mode 100644 index 0000000..899bbee --- /dev/null +++ b/kernel/efi/gop.c @@ -0,0 +1,52 @@ +#include <lib.h> +#include <efi.h> +#include <comus/efi.h> + +static EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL; + +EFI_STATUS efi_load_gop(EFI_SYSTEM_TABLE *ST) +{ + EFI_STATUS status = EFI_SUCCESS; + EFI_GUID gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; + UINTN SizeOfInfo, numModes, nativeMode; + + status = ST->BootServices->LocateProtocol(&gopGuid, NULL, (void **)&gop); + if (EFI_ERROR(status)) + return status; + + status = gop->QueryMode(gop, gop->Mode == NULL ? 0 : gop->Mode->Mode, + &SizeOfInfo, &info); + if (status == EFI_NOT_STARTED) + status = gop->SetMode(gop, 0); + if (EFI_ERROR(status)) + return status; + + nativeMode = gop->Mode->Mode; + numModes = gop->Mode->MaxMode; + + // find the best mode + UINTN best = nativeMode; + UINTN width = 0; + for (UINTN i = 0; i < numModes; i++) { + status = gop->QueryMode(gop, i, &SizeOfInfo, &info); + if (info->PixelFormat != PixelBlueGreenRedReserved8BitPerColor && + info->PixelFormat != PixelRedGreenBlueReserved8BitPerColor) + continue; + if (info->HorizontalResolution > width) { + width = info->HorizontalResolution; + best = i; + } + } + + gop->SetMode(gop, best); + if (EFI_ERROR(status)) + return status; + + return status; +} + +EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop(void) +{ + return gop; +} |