For a simple OS, I agree.DavidCooper wrote:Is it really worth spending years working out how to change screen mode without using the BIOS in order to avoid having to switch back to real mode to let the BIOS do it for you? No doubt it is worth it if you're trying to build a serious OS to rival Windows, and maybe it's worth doing it in a hobby OS if your main interest is in writing screen mode changing code, but the ususal advice is to set up a VESA mode and just stay in it. That doesn't seem like the best option to me - it only takes a fraction of a second on a simple OS to switch everything back to original settings, use the BIOS to change mode and then redo the setup the way you need it, and this allows you to choose a display that suits a specific application (some apps benefiting from a greater range of colours and higher resolution at the cost of speed while for others speed is much more important).SmD wrote:Go *back* to real-address mode to speak to BIOS? Why would anyone want to do that? Surely, by the time they are ready to switch to protected mode, one is ready to be autonomous, no? I cannot imagine going back. I mean, I would have to restore the IVT and the memory directly above it that BIOS uses.
The problem is that as an OS developer tries to go beyond the "simple OS" stage it becomes increasingly more difficult to justify. Everything you touch (MSRs, local APIC, MTRRs, PIT, CMOS/RTC, HPET, USB, PCI device configuration for any/all devices, etc.) ends up being about 4 times as much work, because (for each piece of hardware) instead of just doing the initialisation once you have to be able to:
- save the original device's state somehow (impossible for a range of different pieces of hardware)
- do the initialisation (as you normally would)
- save the OSs current state (a complete nightmare in a lot of cases, where devices may be in the middle of DMA transfers, or have queues of pending commands, etc)
- restore the device's original state (that the BIOS expects)
- restore the device's "pre-empted" state (that the OS expects)
Then there's timing. It might take several seconds before "in progress" DMA transfers and bus mastering stuff completes, then you can start saving the state of everything; then start restoring the state of everything to BIOS defaults. Then there's the video mode switch itself (which is probably the single most expensive BIOS function), followed by restoring the state of everything again. It adds up to a massive problem for any hardware that is sensitive to latency - dropped packets for networking, lost keyboard and mouse data (and potentially screwed up keyboard/mouse state), annoying glitches in audio output (and worse if you're recording any sound), trashed writable CDs caused by buffer under-runs, dropped hot-plug or thermal sensor events, clock skew and/or missed timer IRQs, etc.
Then there's bugs. How are you going to test that all of the above works reliably on all different combinations of hardware under a range of different conditions? Quite simply you're not - it's going to be an untestable and unstable/glitchy mess, and the first time it fails is going to be the last time the unfortunate end-user will dare to use it.
Basically, it's one of those things that seems easy in the beginning, but becomes incredibly hard in the long run. I'd be tempted to suggest that people who suggest this method will never get past the "simple OS" stage, regardless of how hard they try.
Of course some people don't intend to go past the "simple OS" stage. For example, they might be writing a simple OS for educational purposes - e.g. because they want to learn how to design software with fatal flaws.

Cheers,
Brendan