Page 1 of 1

Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 9:27 am
by Electrical
Hello! How to set GOP mode after exiting Boot Services?

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 9:41 am
by kzinti
You can't. You have to do it before exiting boot services.

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 9:49 am
by Electrical
So the only way to set video mode is to save RAM contents into a file, then restart the os change mode is bootloader and load the RAM contents?:( I thought there is an easier method

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 9:52 am
by PeterX
Electrical wrote:So the only way to set video mode is to save RAM contents into a file, then restart the os change mode is bootloader and load the RAM contents?:( I thought there is an easier method
There is! You start the kernel as an UEFI application. The kernel then sets the video mode and exits boot-services.
Alternative: Use Grub and let it set the video mode.

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 9:54 am
by kzinti
Electrical wrote:So the only way to set video mode is to save RAM contents into a file, then restart the os change mode is bootloader and load the RAM contents?:( I thought there is an easier method
That's correct. If you want to change the video mode from the kernel, you will have to reboot and do it before exiting boot services. This is unless you have video drivers for your card that know how to change the video mode.
PeterX wrote:There is! You start the kernel as an UEFI application. The kernel then sets the video mode and exits boot-services.
Alternative: Use Grub and let it set the video mode.
How is that solving anything for the OP? He asked how to change the video mode after exiting boot services.

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 9:58 am
by PeterX
kzinti wrote:
Electrical wrote:So the only way to set video mode is to save RAM contents into a file, then restart the os change mode is bootloader and load the RAM contents?:( I thought there is an easier method
That's correct. If you want to change the video mode from the kernel, you will have to reboot and do it before exiting boot services. This is unless you have video drivers for your card that know how to change the video mode.
PeterX wrote:There is! You start the kernel as an UEFI application. The kernel then sets the video mode and exits boot-services.
Alternative: Use Grub and let it set the video mode.
How is that solving anything for the OP? He asked how to change the video mode after exiting boot services.
He asked for a simple way and I answered. His first question is already answered.

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 10:06 am
by Electrical
What if i didn't exit boot services? Would i be able to use uefi protocols and create syscalls? :D

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 10:07 am
by kzinti
PeterX wrote:He asked for a simple way and I answered. His first question is already answered.
The OP was asking how to change the video mode after exiting boot services. You answered by saying that he should change the video mode before exiting boot services.

One of us is confused here.
Electrical wrote:What if i didn't exit boot services? Would i be able to use uefi protocols and create syscalls? :D
Yes you could do that :). The problem is that you then have no control over your hardware management, including memory. So you won't get far :).

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 10:17 am
by Electrical
Thank you for all your answers :)

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 11:06 am
by bzt
Electrical wrote:So the only way to set video mode is to save RAM contents into a file, then restart the os change mode is bootloader and load the RAM contents?:( I thought there is an easier method
Implement native video card drivers.
Electrical wrote:What if i didn't exit boot services? Would i be able to use uefi protocols and create syscalls?
Well, yes and no. In theory it could be done, but in practice it comes at a too large price. Your kernel won't own the memory, it would have to rely on UEFI memory allocation (which is proven to be fragmenting badly), and it wouldn't be able to set up virtual memory (as UEFI boot services mandate identity mapping), essentially constricting the whole OS into a single, badly managed address space. And there's the question how your kernel could set up descriptor tables (some UEFI services use interrupts, and you can't expect anything from a firmware's IDT, same issue with GDT, you don't know what you got but you cannot use your own as that would break UEFI). So could be done, but questionable if worth it.

Cheers,
bzt

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 3:34 pm
by zaval
Electrical wrote: What if i didn't exit boot services? Would i be able to use uefi protocols and create syscalls? :D
it's a wrong and bad approach. Boot Services were created only for the FW itself and for UEFI applications, mainly - OS Loaders. It's their purpose. All the services and protocols are for this only purpose. Answering your subject question, you have two choices:
1) if you have a documentation for the machine display controllers, your OS needs to have a driver for them - let's call it "video port driver". then you can do whatever that hardware is capable of.
2) if the above is luxury, you take the framebuffer handed off to your OS by the loader, taken from GOP and use it as is, that is - without the possibility to change the resolution and use other HW capabilities of the underlying device. this approach, below:
So the only way to set video mode is to save RAM contents into a file, then restart the os change mode is bootloader and load the RAM contents?:( I thought there is an easier method
as already pointed out, is useless or saying differently - such an overkill. instead, your UEFI OS Loader negotiates with the UEFI (through GOP) the desired (by your OS) resolution (from that limited set, available, don't expect the FW would be driving 8K :D) and sets it up during its run (which is at the Boot Services stage). This is all you need and have in the 2nd variant. UEFI thinks the 1st is what happens (and it's reasonable, since the firmware interface spec cannot take into account this sweet combination of OS dev enthusiasts limited by the display controller vendors' unwillingness to open their manuals).

Nowadays, I see, 1024x768 is pretty common to expect to be set on real hardware. Thanks to the Windows bootmgr.efi, that stated, it wants such. :) even uboot's UEFI on ARM, sets this resolution. at least it was it, with those couple of machines, I was lucky to get working GOP on (Pine64+ (old versions of uboot though) and Rock Pi 4B).

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 6:53 pm
by Octocontrabass
kzinti wrote:You can't. You have to do it before exiting boot services.
If you can find the option ROM containing the GOP driver, you can execute its code inside an emulated UEFI environment (which you have to write) and use it to control the display adapter that way.

UGA was designed to work like this, except with fewer dependencies so you don't need a whole emulated UEFI environment to use it.

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Tue Mar 09, 2021 6:59 pm
by kzinti
Octocontrabass wrote:If you can find the option ROM containing the GOP driver, you can execute its code inside an emulated UEFI environment (which you have to write) and use it to control the display adapter that way.

UGA was designed to work like this, except with fewer dependencies so you don't need a whole emulated UEFI environment to use it.
Although I am sure you are technically right, how realistic is it that the OP is going to explore this idea and succeed after he posted that question?

Also I am not sure that would qualify as "using the gop after exiting boot services".

Re: Setting GOP mode after exiting Boot Services [UEFI]

Posted: Sat May 18, 2024 8:40 pm
by wishedtobe
Octocontrabass wrote:
kzinti wrote:You can't. You have to do it before exiting boot services.
If you can find the option ROM containing the GOP driver, you can execute its code inside an emulated UEFI environment (which you have to write) and use it to control the display adapter that way.

UGA was designed to work like this, except with fewer dependencies so you don't need a whole emulated UEFI environment to use it.
Hello! I did as you said, but the ROM I read did not start with 0xaa55 as expected. Instead, it starts with a magic number and then all the rest are 0x55.And I read the real rom from the bar mapped space. Is this due to the graphics card itself or the PCI?