Setting GOP mode after exiting Boot Services [UEFI]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Electrical
Posts: 8
Joined: Wed May 27, 2020 8:27 am

Setting GOP mode after exiting Boot Services [UEFI]

Post by Electrical »

Hello! How to set GOP mode after exiting Boot Services?
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

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

Post by kzinti »

You can't. You have to do it before exiting boot services.
Electrical
Posts: 8
Joined: Wed May 27, 2020 8:27 am

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

Post 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
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

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

Post 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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

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

Post 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.
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

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

Post 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.
Electrical
Posts: 8
Joined: Wed May 27, 2020 8:27 am

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

Post by Electrical »

What if i didn't exit boot services? Would i be able to use uefi protocols and create syscalls? :D
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

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

Post 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 :).
Electrical
Posts: 8
Joined: Wed May 27, 2020 8:27 am

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

Post by Electrical »

Thank you for all your answers :)
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

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

Post 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
User avatar
zaval
Member
Member
Posts: 647
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

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

Post 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).
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
Octocontrabass
Member
Member
Posts: 5418
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

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

Post 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".
wishedtobe
Posts: 7
Joined: Sat May 04, 2024 7:48 am
Libera.chat IRC: wishedtobe

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

Post 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?
Post Reply