GOP: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
mNo edit summary |
|||
(9 intermediate revisions by 8 users not shown) | |||
Line 2:
== Graphics Output Protocol ==
It has
NOTE: UEFI uses
=== Detecting GOP ===
As with other UEFI protocols, you have to locate a structure with the function pointers first using the protocol's GUID.
<
EFI_GUID gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
Line 15:
if(EFI_ERROR(status))
PrintLn(L"Unable to locate GOP");
</syntaxhighlight>
GOP is the default protocol, so you should be able to locate it on all UEFI firmware. It can probably only fail if you're on an old EFI (pre-UEFI) machine, like
If your kernel uses GRUB, you need to insert a module called "all_video" before loading the kernel to add UEFI GOP compatibility. Not doing so will display a message saying "WARNING: no console will be available to OS".
<syntaxhighlight lang="c">
insmod all_video
menuentry "Example OS" {
multiboot2 /boot/kernel.bin
boot
}
</syntaxhighlight>
=== Get the Current Mode ===
In order to get the mode code for the current video mode, you must set the mode as well to circumvent some buggy UEFI firmware. Otherwise this is done using the QueryMode function, and then gop->Mode->Mode will contain the code
<
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
UINTN SizeOfInfo, numModes, nativeMode;
Line 34 ⟶ 44:
numModes = gop->Mode->MaxMode;
}
</syntaxhighlight>
=== Query Available Video Modes ===
Similarly to VESA, there's no standard mode codes, rather you have a function to query the available modes. Now you know how many modes there are (numModes above), and which one is currently set (nativeMode). You can iterate on the modes and query the information structure for each:
<
for (i = 0; i < numModes; i++) {
status = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo, &info);
Line 49 ⟶ 59:
);
}
</syntaxhighlight>
=== Set Video Mode and Get the Framebuffer ===
This is pretty easy. The mode argument is between 0 and numModes.
<
status = uefi_call_wrapper(gop->SetMode, 2, gop, mode);
if(EFI_ERROR(status)) {
Line 67 ⟶ 77:
);
}
</syntaxhighlight>
To get the same value as scanline in VESA (also
<
pitch = 4 * gop->Mode->Info->PixelsPerScanLine;
</syntaxhighlight>
=== Plotting Pixels ===
Line 77 ⟶ 87:
Now you can use the returned framebuffer exactly the same way as you would with VESA, there's absolutely no difference.
To calculate the offset for an (X,Y) coordinate on screen, do pitch*Y+pixelbytes*X. For example for 32 bit true-color (where pixelbytes is 4):
<
static inline void PlotPixel_32bpp(int x, int y, uint32_t pixel)
{
*((uint32_t*)(gop->Mode->FrameBufferBase + 4 * gop->Mode->Info->PixelsPerScanLine * y + 4 * x)) = pixel;
}
</syntaxhighlight>
For drawing characters, you can use the same method described in [[VGA Fonts]].
Line 95 ⟶ 105:
* GOP at [https://en.wikipedia.org/wiki/Graphics_Output_Protocol Wikipedia]
* UEFI Graphic Features at [https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface#Graphics_features Wikipedia]
* [https://
* [https://www.intel.com/content/dam/doc/guide/uefi-driver-graphics-controller-guide.pdf Intel documentation on GOP]
|