How's the BIOS so clever?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

How's the BIOS so clever?

Post by onlyonemac »

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
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
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How's the BIOS so clever?

Post by iansjack »

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.
Last edited by iansjack on Thu Jul 31, 2014 2:09 pm, edited 1 time in total.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: How's the BIOS so clever?

Post by SpyderTL »

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
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
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: How's the BIOS so clever?

Post by onlyonemac »

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.
That is exactly what I was thinking.
iansjack wrote:Any ancillary components will have their own BIOS to hook into the motherboards BIOS.
I didn't think of that; I seem to remember I read that somewhere a long time ago...
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.
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...)
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
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: How's the BIOS so clever?

Post by Rusky »

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...)
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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: How's the BIOS so clever?

Post by Brendan »

Hi,
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.
BIOS doesn't support that much hardware. For example, it doesn't support:
  • 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)
In addition; for the hardware it does support, often it's using crusty/slow legacy modes (e.g. basic PIO for hard disks, rather than the full NCQ with bus-mastering/DMA, 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)
Basically; it only has to be "bare minimum" code that's able to start an OS (and is only used for less than 5 seconds); and none of it is actually good (for any definition of "good" - features, performance, fault handling, etc).

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.
tehmav
Posts: 4
Joined: Tue Aug 05, 2014 2:02 pm

Re: How's the BIOS so clever?

Post by tehmav »

You could take a look at coreboot.
Very interesting project, definitifly worth a look (especially at the source ;))
Post Reply