What are the functions of the BIOS while the operating system is running?

77

24

I always wondered whether the BIOS (apart from conducting POST, starting the bootloader and passing control to the OS after one presses the power button) has any purpose or function while the operating system is running?

Does the operating system communicate with the BIOS while running and if so, how?

JohnnyFromBF

Posted 2012-08-16T09:10:04.453

Reputation: 4 298

Related: Why must a computer have a BIOS? – Breakthrough – 2012-08-21T20:00:26.923

Answers

72

With modern OSs, practically none. Linus Torvalds reportedly said its task is to "just load the OS and get the hell out of there".

Older operating systems like MS-DOS relied on the BIOS for many tasks (e.g. disk access), by calling interrupts.

With modern OSs, the bootloader quickly switches into 32- or 64-bit mode and executes the OS kernel. The kernel can register its own interrupt handlers, which can be called by user-space applications. The kernel's routines can be more portable (since they don't depend on the specific hardware), more flexible (OS vendors can change them on demand rather than having to use whatever came with the hardware), more sophisticated (they can execute arbitrarily complex code rather than what was programmed into the BIOS), and more secure (since the OS can control access to shared resources and prevent programs from clobbering each other, implementing its own arbitrary permissions schemes).

To interact with specific hardware, OSs can load and use its own device drivers. So there's no need for the OS or applications to call most BIOS routines at all. In fact, for security reasons, BIOS interrupts are even disabled. Since the BIOS lives in 16-bit real mode it's harder to call for modern OSs.

While use of the BIOS is very limited while the OS runs, its functions are still peripherally used. For example, when a computer sleeps, the OS is not running and it ultimately falls to the firmware to set the hardware to the correct state to pause and resume the OS. These uses are generally limited to ACPI calls rather than calls to the full BIOS interface. ACPI is a BIOS extension that "brings power management under the control of the operating system (OSPM), as opposed to the previous BIOS-central system, which relied on platform-specific firmware to determine power management and configuration policy".

Note that officially "BIOS" refers to a particular firmware interface, but the term is commonly used to refer to computer firmware in general. Some recent computers (especially Apple ones) have replaced BIOS (sensu strictu) with UEFI, which of course then is what is called to implement these functions.

For more information about how the role of the BIOS has diminished over time, see Wikipedia.

Mechanical snail

Posted 2012-08-16T09:10:04.453

Reputation: 6 625

15There is some minimal interaction via the system clock (time of day). – MSalters – 2012-08-16T09:25:27.440

2@MSalters - Some OSes like Linux normally only access the RTC once at boot. – sawdust – 2012-08-16T11:00:43.077

3

What about System Management Mode: http://smackerelofopinion.blogspot.co.uk/2009/10/system-management-mode-is-evil.html ?

– Adrian Cox – 2012-08-16T11:31:01.100

1@sawdust: That depends; ntpd may set it every 11 minutes. – MSalters – 2012-08-16T12:22:55.627

7Are you really sure about this? What about the fan controls, the already mentioned system management mode, the whole ACPI, which for example controls processor speed? – Alexander – 2012-08-16T14:04:35.503

32I could give it a try and solder off the BIOS chip while the machine is running. – JohnnyFromBF – 2012-08-16T14:09:59.467

5@Ian why make it hard for yourself. Find an older board with a socketed bios and just yank the chip. Alternately IIRC some recent overclocker boards still have a hardware switch to let you swap between two BIOSes. Botch a flash of the B image, boot to A, switch to B when running. – Dan is Fiddling by Firelight – 2012-08-16T15:35:53.527

1

yeah, I'm not sure this is totally correct. I found that in Linux proper ACPI support is critical in the BIOS, regardless of what your Kernel does. "An ACPI-based BIOS that is not compliant with the ACPI standard might not support workable communication between the operating system (or Setup) and your hardware" http://technet.microsoft.com/en-us/library/cc779659.aspx

– Jeff Atwood – 2012-08-16T18:06:26.993

17@Ian I have done that. I lost power while flashing a BIOS, it did not boot up after that. We had 20 machines with exact same hardware and they were aging.. So I booted one, removed BOIS chip, plugged in the screwed up one, and flashed. Both BOIS chips worked perfectly fine after that. Granted, it was DOS, running for flash software. Still impressive I think. (Boards were Gigabyte branded, Pentium 4 compatible as far as I remember) – Ekin Koc – 2012-08-16T19:39:08.487

@JeffAtwood: Yeah, I probably overstated some of this. Added some qualifications and expanded. – Mechanical snail – 2012-08-16T22:20:58.697

4@EkinKoc: while a cool feat, it doesn't prove that the BIOS is not used after boot. Because most modern chipsets copy the BIOS from the very slow ROM to faster RAM and only use the in-ram copy after that. So the OS could still be using some BIOS calls even if the BIOS chip was removed after bootup. – Joachim Sauer – 2012-08-17T08:59:06.237

3@JoachimSauer Yep true, you can get a copy of your BIOS while running Linux by dumping the first Mebibyte of /dev/mem like this sudo dd if=/dev/mem of=BIOS bs=1048576 – JohnnyFromBF – 2012-08-17T10:48:28.867

What about issuing AT commands, bubbling up proper interrupts for device insertions, enabling overclocking directly from the OS, etc? The firmware is generally underappreciated. – Milind R – 2014-01-17T06:59:44.823

32

The BIOS provides a number of services to the Operating Systems, most of which are related to power management:

  • modifying the CPU and bus clocks
  • enabling/disabling mainboard devices
  • expansion port power control
  • suspend-to-disk and suspend-to-RAM
  • resume event settings

Suspend-to-disk is implemented in the OS most of the time as the OS can restore its state faster (only the kernel state is reloaded, and program state swapped in when required, which is significantly faster than reloading the entire RAM), but the feature remains in the specification.

Suspend-to-RAM can not be implemented by the OS, as it relies on the BIOS skipping the RAM initialization and test, so the OS needs an API to tell the BIOS that it intends to be resumed with the current RAM contents. In order to provide this service, the BIOS asks the OS to leave a certain RAM area intact.

The interface for the OS for all BIOS services is a piece of virtual machine code that needs to be run on an emulator, and which generates the necessary I/O operations into the hardware. For suspend, this is generally implemented so that executing one of the hardware writes then triggers an interrupt, which transfers control to the BIOS.

Simon Richter

Posted 2012-08-16T09:10:04.453

Reputation: 2 384

17

There are three primary areas where an OS uses the BIOS in modern systems, such as those using the UEFI standard. The first is a series of services known as the UEFI runtime services. These services allow the OS to grab information that only the BIOS knows, such as the time that the BIOS was using, the boot order, the current user security profile, the information about the motherboard, DIMMs, etc.

The second is System Management Mode, which is a hidden section of memory (SMRAM) that is accessed by a high-priority interrupt (SMM). Many BIOS use this to implement high-security OEM features or to implement hardware work arounds.

The third is ACPI. ACPI provides configuration, power management and hardware data and code used by the OS to augment what the OS drivers can find out using an industry standard or device driver. For example, is there a special signal to control the hard drive power, or is there a special way to talk to the battery that isn't covered by a standard.

Tim

Tim Lewis

Posted 2012-08-16T09:10:04.453

Reputation: 171

9

Modern OSs use the BIOS mainly for loading only, but there are still some uses for it which include, most notably:

  • Reacting to the power button (Shut down the PC after 4 seconds
    included).
  • Changing screen brightness settings on laptops
  • Battery events on laptops
  • Suspension

bluehallu

Posted 2012-08-16T09:10:04.453

Reputation: 203

I thought Brightness was done by altering the color values right before drawing. – Cole Johnson – 2012-08-16T19:34:58.237

3@ColeJohnson: No: On Thinkpads at least it actually changes the backlight brightness. – Mechanical snail – 2012-08-16T22:00:26.747

1The brightness is a hardware controlled pulse width modulated signal, switching the bright white LED on and off at high frequency. This light is one major battery consumer – None – 2012-08-17T00:55:33.853

1

On top of what has been noted above, Intel is starting to swing the other way and build more in by providing out of band access to the hardware via Active Management Technology built into the bios and motherboard which can be controlled independently of the OS. With these boards you can actually do a fair bit. Whether you consider it inbuilt or a second OS is another thing but as it has hardware on board and components in the bios, i'm sticking with inbuilt.

intels marketing guff

Matt

Posted 2012-08-16T09:10:04.453

Reputation: 153