This repository has been archived by the owner on Oct 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vidmodes.c
63 lines (58 loc) · 2.49 KB
/
vidmodes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <uefi.h>
#include <vidmodes.h>
efi_gop_t *get_gop(void)
{
efi_status_t status;
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
efi_gop_t *gop = NULL;
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
if(!EFI_ERROR(status) && gop)
{
/* changing the resolution might mess up ConOut and StdErr, better to reset them */
return gop;
}
else
{
fprintf(stderr, "[ERROR] Unable to get graphics output protocol \n");
return gop;
}
printf("[INFO] Graphic output protocol located \n");
return gop;
}
int print_info(efi_gop_t *gop)
{
efi_status_t status;
uintn_t isiz = sizeof(efi_gop_mode_info_t), currentMode, i;
efi_gop_mode_info_t *info = NULL;
/* we got the interface, get current mode */
status = gop->QueryMode(gop, gop->Mode ? gop->Mode->Mode : 0, &isiz, &info);
if(status == EFI_NOT_STARTED || !gop->Mode) {
status = gop->SetMode(gop, 0);
ST->ConOut->Reset(ST->ConOut, 0);
ST->StdErr->Reset(ST->StdErr, 0);
}
if(EFI_ERROR(status)) {
fprintf(stderr, "[ERROR] Unable to get current video mode\n");
return 1;
}
printf("[INFO] Here the available graphical modes: \n");
currentMode = gop->Mode->Mode;
/* iterate on modes and print info */
for(i = 0; i < gop->Mode->MaxMode; i++) {
status = gop->QueryMode(gop, i, &isiz, &info);
if(EFI_ERROR(status) || info->PixelFormat > PixelBitMask) continue;
printf(" %c%3d. %4d x%4d (pitch %4d fmt %d r:%06x g:%06x b:%06x)\n",
i == currentMode ? '*' : ' ', i,
info->HorizontalResolution, info->VerticalResolution, info->PixelsPerScanLine, info->PixelFormat,
info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor?0xff:(
info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff0000:(
info->PixelFormat==PixelBitMask?info->PixelInformation.RedMask:0)),
info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor ||
info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff00:(
info->PixelFormat==PixelBitMask?info->PixelInformation.GreenMask:0),
info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor?0xff0000:(
info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff:(
info->PixelFormat==PixelBitMask?info->PixelInformation.BlueMask:0)));
}
return 0;
}