Hi,
thehardcoreOS wrote:I've also read that since we are using GRUB2 we can ask GRUB to set video mode for us?
It can (but more on that later).
thehardcoreOS wrote:Another important note it that we can directly write to BIOS using inportb and outportb functions. Can we set video mode by using them from our C code or we need some extra assembly functions?
Using protected mode makes this a bit difficult right?
That's a native video driver (which is possible), but means that you need a different driver for most different video cards and ends up being a lot of work.
thehardcoreOS wrote:Also there is something called V8086 monitor that is really hard to write but it can use BIOS functions that are not usable with protected mode on?
You can use V8086 (or software emulation); but that's extra work that is useless for modern (UEFI) computers so it's typically not worth bothering with.
There are 2 parts to this problem - finding a video mode that actually works (that the OS itself, and the video card, and the monitor all support); and setting that video mode.
For finding a video mode I'd:
- get a list of all video modes that the video card supports (from UEFI, from VBE, or from native driver)
- remove anything the OS doesn't support
- remove anything the monitor doesn't support (based on EDID information)
- give each video mode a score (representing things like if it's the monitor's native resolution, if it'll gobble too much RAM, if it will look ugly, how much it matches user's preferences if any, etc)
- select the video mode with the best score
For setting a video mode, there are 2 options:
- Use a native video driver (and write one for each video card). This probably isn't very practical; but allows you to support multiple monitors, multiple video cards, etc, and allows you to change video modes after boot without much hassle.
- Use the firmware (VBE for BIOS, GOP or UGA for UEFI, etc). This is far more practical; but BIOS/VBE doesn't support multiple monitors or video cards properly and is painful for switching video modes after boot; and UEFI may or may not support multiple monitors or video cards properly (depends on whether there's appropriate UEFI drivers, etc) and can't be used at all for switching video modes after boot.
You mostly want to support both options. Essentially; use a native video driver if one exists, and use firmware as a "fallback" (for when you have no native video driver). In this case, for the "no driver fallback" it's not really worth bothering with the hassle of trying to support video mode switching after boot (partly because it's something that the user doesn't care about most of the time anyway).
Now... GRUB can set the video mode for you during boot (if the right "GRUB modules" are installed, etc); but it won't do it properly (e.g. doesn't really know what your software supports, doesn't check if the monitor supports the video mode, etc). Because of this, to get the best results the end user needs to configure GRUB (more end user hassle, more chance of user mis-configuring). It also can't work properly on something like a "live CD" (where it's impossible to configure GRUB to work for all the different computers the CD might be booted on). Finally, GRUB (multi-boot) has no support for multi-monitor or multiple video cards (even when you're booting on a UEFI system that has full support for this).
Basically; GRUB is the easiest form of "use firmware (indirectly) to setup video mode during boot", but it's also the worst option (for end user hassle), the worst option (for reliability), and the worst option (for features - e.g. multiple monitors, etc).
Cheers,
Brendan