Hi!
I haven't posted for a while but the other day I was thinking about a stark difference between the BIOS and us operating system developers. You see, we always struggle to support every different kind of hardware that could possibly exist, yet whenever there's a BIOS function to do something it will probably be able to do it with whatever hardware you supply. And now what I can't work out is how come BIOSes are so able to work with any kind of hardware.
I know BIOSes are developed commercially, but I still don't think any company will have resources to produce a BIOS that will work with absolutely any hardware. And I know Linux can work with most hardware, but then Linux has an enormous team of programmers (by several orders of magnitude larger than most teams of BIOS developers). Now what I'm wondering is if the compatibility offered by BIOSes is because only a limited range of hardware will work with a given PC's internal hardware, so there's no need to spend time developing support for hardware that will never work with the PC's internal hardware (as opposed to osdevvers who don't know what hardware their users could have). However, most BIOSes these days are designed to work on a wide range of motherboards - surely the manufacturers don't package up a custom-modified BIOS image for every make and model of motherboard?
This just puzzles me because it seems like there's an obvious solution to versatile hardware compatibility, but at the moment it's only known to BIOS developers.
Any ideas?
Thanks,
onlyonemac
How's the BIOS so clever?
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
How's the BIOS so clever?
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: How's the BIOS so clever?
A particular BIOS is designed to run with a particular motherboard whereas an OS is designed to run on many different hardware configurations. So the BIOS writer has an easier task (inasmuch as that level of development can ever be called easy) than the OS writer. Any ancillary components will have their own BIOS to hook into the motherboards BIOS.
A BIOS performs a particular task with a well-defined set of hardware, so I wouldn't say it is that clever. Try flashing a motherboard with a BIOS designed for another motherboard and see what happens. You might not consider it so versatile then.
A BIOS performs a particular task with a well-defined set of hardware, so I wouldn't say it is that clever. Try flashing a motherboard with a BIOS designed for another motherboard and see what happens. You might not consider it so versatile then.
Last edited by iansjack on Thu Jul 31, 2014 2:09 pm, edited 1 time in total.
Re: How's the BIOS so clever?
Most of the stuff that the BIOS does just happens to not need specific device information. During startup, it is mainly responsible for taking information from one known source (say the PCI bus), and copying it to a known memory location in a known format (say, the APCI tables).
As for the more complex stuff, there are several standard APIs that can be used to communicate between the BIOS and devices, like VESA, PXE, PCI, USB, etc. These must be supported by the hardware, so that the BIOS and the hardware can agree ahead of time how they will communicate. Using nothing but these standard APIs, the BIOS can do a lot of initialization by itself, and for more complicated things, like SCSI controllers, the BIOS uses PCI to "notify" the hardware that it needs to initialize itself, which gives the hardware the ability to "install" it's own "event handlers" to "extend" the default BIOS functionality.
Still, it is amazing that it all works as well as it does. There are several open-source BIOS projects that you can check out to see what happens beneath the covers if you are really interested.
http://www.seabios.org
As for the more complex stuff, there are several standard APIs that can be used to communicate between the BIOS and devices, like VESA, PXE, PCI, USB, etc. These must be supported by the hardware, so that the BIOS and the hardware can agree ahead of time how they will communicate. Using nothing but these standard APIs, the BIOS can do a lot of initialization by itself, and for more complicated things, like SCSI controllers, the BIOS uses PCI to "notify" the hardware that it needs to initialize itself, which gives the hardware the ability to "install" it's own "event handlers" to "extend" the default BIOS functionality.
Still, it is amazing that it all works as well as it does. There are several open-source BIOS projects that you can check out to see what happens beneath the covers if you are really interested.
http://www.seabios.org
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: How's the BIOS so clever?
That is exactly what I was thinking.iansjack wrote:A particular BIOS is designed to run with a particular motherboard whereas an OS is designed to run on many different hardware configurations.
I didn't think of that; I seem to remember I read that somewhere a long time ago...iansjack wrote:Any ancillary components will have their own BIOS to hook into the motherboards BIOS.
The solution is to package up a different version of our operating system for every motherboard . Seriously is there not a way for us to tap into the BIOSes of the "ancillary components" so that we don't have to try and reverse-engineer every single piece of hardware? (Perhaps Linux could do that too then...)onlyonemac wrote:This just puzzles me because it seems like there's an obvious solution to versatile hardware compatibility, but at the moment it's only known to BIOS developers.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: How's the BIOS so clever?
DOS tried that already. Coming from the other direction, if you write a coreboot payload you can use the same drivers in the early boot and when fully booted.onlyonemac wrote:The solution is to package up a different version of our operating system for every motherboard . Seriously is there not a way for us to tap into the BIOSes of the "ancillary components" so that we don't have to try and reverse-engineer every single piece of hardware? (Perhaps Linux could do that too then...)
Re: How's the BIOS so clever?
Hi,
Also; the code is simpler than the corresponding code you'd expect in an decent OS, because:
Finally, BIOS developers don't write everything from scratch for every motherboard. Instead, they'd have "generic BIOS code" and customise a few things to suit the chipset/motherboard. The majority of the code would be code that has evolved over the last 30+ years. Some things (e.g. RTC and PIC code) may have been untouched for several decades, some things (e.g. USB support) might have been added 15+ years ago. The amount of "new and untested" code for a motherboard is likely to be very little.
Cheers,
Brendan
BIOS doesn't support that much hardware. For example, it doesn't support:onlyonemac wrote:I haven't posted for a while but the other day I was thinking about a stark difference between the BIOS and us operating system developers. You see, we always struggle to support every different kind of hardware that could possibly exist, yet whenever there's a BIOS function to do something it will probably be able to do it with whatever hardware you supply. And now what I can't work out is how come BIOSes are so able to work with any kind of hardware.
- Sound input or output (other than PC speaker)
- Video (it's provided by the video card's ROM)
- Networking (it's provided by the network card's ROM)
- IO APICs (not used at all)
- HPET (not used at all)
- IOMMUs (not used at all)
- Game controller/s (joysticks, etc)
Also; the code is simpler than the corresponding code you'd expect in an decent OS, because:
- there's no protection/isolation (other than being in "hard to modify ROM")
- no support for multiple CPUs (excluding setting MTRRs and populating ACPI tables)
- no support for multi-tasking
- very little memory management
- very simple user interface
- no file system/s
- no disk cache/s
- no need for good performance for anything
- poor fault tolerance (e.g. not even basic exception handlers that work - if anything goes wrong then crash/reboot)
Finally, BIOS developers don't write everything from scratch for every motherboard. Instead, they'd have "generic BIOS code" and customise a few things to suit the chipset/motherboard. The majority of the code would be code that has evolved over the last 30+ years. Some things (e.g. RTC and PIC code) may have been untouched for several decades, some things (e.g. USB support) might have been added 15+ years ago. The amount of "new and untested" code for a motherboard is likely to be very little.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.