Monday 31 December 2007

Why do we need BIOS anyway?

Recently I've been playing with my OS installations quite a bit. Setup Linux on this disk, XP on that one, another copy of XP there and maybe Vista there.
Well, Vista eventually had to go, but I kept the Linux and XP installations. What remains is the memories of all the problems I had installing all these operating systems. And guess what - all the problems stem from the fact that none of these systems really read the BIOS settings telling them what I wanted to do.
OK, I really have to be fair to Ubuntu: at least it attempted to install exactly where I told it to. Unfortunately, things didn't go quite as smooth as expected. I had to manually place GRUB to the appropriate disk. Otherwise at least it didn't mess with the other three disks I have.
The story was completely different for XP and Vista. I set the appropriate drive as boot in BIOS, but the crap installer put boot loader on any particular drive it found fit for that at a particular time. Notifying me about the chosen disk is of course out of the question.
Then I try to disable (in BIOS) all disks but the one I want to install XP to. One would hope that at least this would work. Wrong!!! XP's IDE drivers simply ignore any such settings in the BIOS and continue showing all the disks that are attached. The only solution for this problem is to physically disconnect the disks.

Modern OS's don't even use the drivers provided in hardware BIOS except in some ultra-special fall-back modes. Those of us old enough will still remember all those int xx functions with which one could access the hardware in an easy, but rather slow way. Pretty much every hardware still comes with BIOS providing those interrupt functions although nowadays these functions are rather poor in number and functionality. The reason for this I think is simple: everybody simply expects a driver for your chosen OS will fix this providing for full functionality.

So, what's the use of BIOS then anyway?

With current solutions, all one needs from BIOS is that tiny little bit of functionality to allow boot from CD, HDD or some such device. Everything can be sorted out later with appropriate drivers for the OS being booted.
Of course, things aren't quite as simple. The most obvious example of hardware that isn't managed by OS directly is RAM. Overclockers out there will know what I'm talking about. Currently there are no drivers for any OS that would manage how RAM works. Same goes for system buses (PCI, PCI-Ex, AGP, HTT and the like) and a lot of this goes for the processor as well. There are many aspects of today's computer that still get managed by the BIOS directly. But that doesn't make it BIOS (Basic Input/Output System) now, does it?

But still, why have any of this in BIOS when we could just as well have a few appropriate extra drivers for the OS and be done with it? It's not like those 512KB of ROM motherboards have could ever show, not with today's multi GB operating systems. Some fail safe functionality needed for boot could just as well be placed in 64KB of ROM, everything else is just unnecessary duplication of code.
What I hate most about this code duplication is how some settings are respected while others are not. For example - to make power management work, it has to be set just right in BIOS as well as in the OS. Integrated NICs and their drivers obey the on/off switch, pretty much the same goes for other peripherals, but other settings for those same peripherals are simply moot since the driver makes sure that the peripheral in question works. Disks on the other hand are supported in BIOS just for the purpose of booting, nothing else. A few milliseconds after the boot the driver is loaded and everything set in BIOS is forgotten...

What's the most ridiculous of all is that we have all the necessary drivers in BIOS, but your OS of choice won't be able to use the device until you provide it with appropriate drivers. Which is why I'm writing this post.

You see, I'm not really against drivers in the BIOS. On the contrary: I believe BIOS should provide the drivers for all hardware in the computer. Without exception!

These drivers should:
1) Provide a fast, overhead free interface directly to hardware
2) Manage all IRQ, DMA and similar stuff through universal interfaces
3) Provide just the functionality of the hardware, nothing more, nothing less. Application specific bug fixes like the graphics drivers are full of must remain an OS (or better yet - application) specific feature.
4) Integrate with the BIOS on code segment basis, eliminating excessive function calls and such
5) Long-term standardization of hardware communications protocols
6) Provide an easy method for upgrading the driver at a later time
7) Many other things, but I'm too lazy to think of them right now

What I'm proposing here is a bit of paradigm shift: currently OS manages the hardware of interest entirely - by using drivers. I believe this is not optimal for the following reasons:
1) Drivers have to be written separately for each OS and possibly for each major version of the OS creating lots of excessive work (and bugs) for driver developers
2) Plethora of operating systems out there makes it practically impossible to write drivers for each of them increasing consumer problems with hardware purchases
3) Creates usage problems because each hardware manufacturer does it's drivers it's own way. Drivers and supporting applications look different from manufacturer to manufacturer steepening the learning curve for the users

I've always found it super annoying to have to find the correct drivers for my on-board Ethernet NIC or sound card or anything else for that matter. If you ever installed an OS on your own, especially an OS that is a couple of years old, you have noticed that half your hardware is not recognized at installation leaving you with plenty of work installing the latest drivers. That is, if you can figure out what all those "Unknown device" entries in the hardware manager are. One of the most annoying drivers to install are the NIC drivers: if you forgot do download them before installing the OS, you have no way of accessing the internet, which means you have to install them from the CD that came with your computer (if you still have it) or find a friend that can download the drivers for you from the internet. Great, if you're like me (installing OS at night), you won't be as stupid to go wake your friend up at 3am, will you?

So, my proposition is to make BIOS really a BIOS again, but this time a bit more modern. DOS had no problem just linking all the BIOS interrupt functions into it's own int 0x21. That was fast enough since the hardware was so slow at the time. Modern operating systems just made it easier to write the drivers for than the BIOS, but it all started with Windows 3.x anyway. DOS didn't have a need for graphics accelerator, you see. That's one of the reasons why we have this ridiculous situation today. At least, it's ridiculous in my opinion.
What we need to do today is simply design a good method that would allow for fast and reliable access to all provided hardware functions while at the same time allowing for easy integration into an OS supporting the new model.

With this, we provide the following benefits:
1) Provide a standard hardware interface for all operating systems
2) Driver developers only have to worry about 8,16,32 and 64 bitness of their drivers and even that could be taken care of by including a small p-code to machine code compiler built into the motherboard BIOS. This could even eliminate platform differences (same driver working with a MIPS, ARM, X86 or any other processor).
3) Virtualization becomes a snap. BIOS would become the platform for virtual server.
4) No more trouble finding the drivers for your OS of choice
5) Maybe, just maybe, basic functionality of common hardware could in time be covered by a single, generic driver built into the motherboard BIOS

I hear EFI (Extensible Firmware Interface) already handles a lot of what's proposed here. But if I understand it's specification correctly, it is again a compromise, offering just basic functionality. Not to mention it isn't being used despite it's obvious advantages over the now 30 year old PC BIOS...
I wonder who was too powerful this time...