Page 1 of 2

Cannot set video mode on real hardware

Posted: Fri May 21, 2021 7:39 am
by Danyy
I just recently finished tasking in my OS and decided to make a whole rewrite to fix some mistakes. Along the way, I also decided to make it bootable on real hardware. The code got stuck on setting video mode. First I thought the problem was with my set video mode function but it wasn't that. The problem is that my computer doesn't seem to support 1920x1080x32 resolution. The video list ends on 0x11Bh which is 1280x1024x24. My monitor and graphics card both support 1920x1080 and it also works on QEMU. The code also fails on Virtual Box.

Also, note that my computer doesn't have legacy BIOS, it has UEFI and I am running the OS with CSM. I thought the problem may be with that.

I can give you any information that you may need, I didn't post code since it seems to be irrelevant.

TL;DR:

I cannot set video mode because the video mode list on real hardware doesn't include my desired resolution 1920x1080x32 although my hardware should support it. I don't have legacy BIOS, I am running OS with UEFI and CSM.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 8:45 am
by pvc
VBE often doesn't support modern resolutions. Try GOP (if your video card supports it).

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 8:52 am
by Danyy
pvc wrote:VBE often doesn't support modern resolutions. Try GOP (if your video card supports it).
Yes but QEMU seems to support it very well

Edit: Is there any way I can make my VBE2 support video mdoes I want.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 8:57 am
by Octocontrabass
QEMU is nicer than hardware in several ways.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 9:07 am
by Danyy
Octocontrabass wrote:QEMU is nicer than hardware in several ways.
Is there any way I could make real hardware detect the video modes I want

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 9:22 am
by Octocontrabass
Yes: write a driver for the video card.

There's no way to make the firmware give you additional modes.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 9:25 am
by Danyy
Octocontrabass wrote:Yes: write a driver for the video card.

There's no way to make the firmware give you additional modes.
so it is impossible lol since I cannot write a driver for every video card

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 11:07 am
by nullplan
Danyy wrote:so it is impossible lol since I cannot write a driver for every video card
No, but you can start with a driver for your video card, and then add every card you come across as required. Given that your OS is unlikely to be used outside of you personally, this is probably the way to go. Add a VESA/GOP fallback for people who want to try it out, and make documentation available on how to add video drivers, and that is probably going to be as it gets. Everything more would require vendor support, which you are unlikely to get until you even reach the lofty heights Linux has climbed to (<10% market share). Which is probably still beyond even your wildest dreams.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 12:14 pm
by pvc
IMO, targeting Intel integrated graphics would be a good point to start for several reasons.
  • a lot of machines (from virtually any segment) have it
  • documentation is decent(-ish)
  • differences between models are only minimal (for 2D graphics)
  • potential test machines are extremely cheap (sometimes even free)

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 3:58 pm
by Danyy
pvc wrote:IMO, targeting Intel integrated graphics would be a good point to start for several reasons.
  • a lot of machines (from virtually any segment) have it
  • documentation is decent(-ish)
  • differences between models are only minimal (for 2D graphics)
  • potential test machines are extremely cheap (sometimes even free)
nullplan wrote:
Danyy wrote:so it is impossible lol since I cannot write a driver for every video card
No, but you can start with a driver for your video card, and then add every card you come across as required. Given that your OS is unlikely to be used outside of you personally, this is probably the way to go. Add a VESA/GOP fallback for people who want to try it out, and make documentation available on how to add video drivers, and that is probably going to be as it gets. Everything more would require vendor support, which you are unlikely to get until you even reach the lofty heights Linux has climbed to (<10% market share). Which is probably still beyond even your wildest dreams.
Ok but isn’t it just making things harder for me. Wouldn’t using UEFI and GOP be easier than writing drivers for my video card. I believe it would be provided that GOP can support higher video modes. Is it *guaranteed* for the GOP to supply higher modes? If not so, how can I even start writing drivers for a video card?

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 4:33 pm
by zaval
GOP reports in every case what modes it does support. Being in the loader, you can query that and set to what you like most. You can also query EDID information, using UEFI, but that makes little sense, because again - what GOP supports, it reports itself. If you find through EDID some higher resolutions, that GOP doesn't claim to support - you wouldn't be able to set them without directly manipulating the display controller, what is only possible if you know what to manipulate. Warning: GOP, as any UEFI protocol, works only before ExitBootServices(), so setting the mode through it is only possible in the loader.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 9:06 pm
by Octocontrabass
Danyy wrote:Is it *guaranteed* for the GOP to supply higher modes?
No.
Danyy wrote:If not so, how can I even start writing drivers for a video card?
Start by figuring out which video card it is so you can find documentation.

Re: Cannot set video mode on real hardware

Posted: Fri May 21, 2021 9:56 pm
by bzt
Danyy wrote:Is there any way I could make real hardware detect the video modes I want
Well, yes and no. There is a way to detect video modes without writing a driver, however it will report what the card actually supports, and not necessarily what you want. The best you can do is get the list of supported video modes, then look for the resolution which is the closest to the one you want (but there's no guarantee there will be an exact match).
Danyy wrote:Also, note that my computer doesn't have legacy BIOS, it has UEFI and I am running the OS with CSM.
In that case you definitely will have GOP (in UEFI mode) and both GOP and VBE will report exactly the same video resolutions (because in legacy CSM the VBE function is just a wrapper around GOP).

As for VBE, I don't have a tutorial, but here's a link a working Assembly code in my boot loader. It queries the list of supported modes from VESA VBE, and then sets the mode which is closest to the resolution given in reqwidth and reqheight variables.

For GOP, here's a tutorial. It reports the following modes in my qemu:
Image
On a real machine it will report 20 - 30 modes at least.

Cheers,
bzt

Re: Cannot set video mode on real hardware

Posted: Sat May 22, 2021 1:10 am
by Danyy
bzt wrote:
Danyy wrote:Is there any way I could make real hardware detect the video modes I want
Well, yes and no. There is a way to detect video modes without writing a driver, however it will report what the card actually supports, and not necessarily what you want. The best you can do is get the list of supported video modes, then look for the resolution which is the closest to the one you want (but there's no guarantee there will be an exact match).
Danyy wrote:Also, note that my computer doesn't have legacy BIOS, it has UEFI and I am running the OS with CSM.
In that case you definitely will have GOP (in UEFI mode) and both GOP and VBE will report exactly the same video resolutions (because in legacy CSM the VBE function is just a wrapper around GOP).

As for VBE, I don't have a tutorial, but here's a link a working Assembly code in my boot loader. It queries the list of supported modes from VESA VBE, and then sets the mode which is closest to the resolution given in reqwidth and reqheight variables.

For GOP, here's a tutorial. It reports the following modes in my qemu:
Image
On a real machine it will report 20 - 30 modes at least.

Cheers,
bzt
zaval wrote:GOP reports in every case what modes it does support. Being in the loader, you can query that and set to what you like most. You can also query EDID information, using UEFI, but that makes little sense, because again - what GOP supports, it reports itself. If you find through EDID some higher resolutions, that GOP doesn't claim to support - you wouldn't be able to set them without directly manipulating the display controller, what is only possible if you know what to manipulate. Warning: GOP, as any UEFI protocol, works only before ExitBootServices(), so setting the mode through it is only possible in the loader.
I think I couldn’t clarify. Using VBE I am getting the list of supported video modes and checking the mode that supports 1920x1080x32 and set it, meaning I am not hardcoding any mode. My graphics card being 2080ti and monitor being a 2k monitor, they should support video modes such as 1920x1080x32 but VBE doesn’t report them.

I am asking how I should reach the video modes I want that are already supported my graphics card and that should be reported by VBE but aren't, without writing a driver for my video hard (hopefully)?

Re: Cannot set video mode on real hardware

Posted: Sat May 22, 2021 1:52 am
by Octocontrabass
Danyy wrote:I am asking how I should reach the video modes I want that are already supported my graphics card and that should be reported by VBE but aren't, without writing a driver for my video hard (hopefully)?
The only way to do it is to write a driver.