Cocojunk

🚀 Dive deep with CocoJunk – your destination for detailed, well-researched articles across science, technology, culture, and more. Explore knowledge that matters, explained in plain English.

Navigation: Home

BIOS

Published: Sat May 03 2025 19:14:06 GMT+0000 (Coordinated Universal Time) Last Updated: 5/3/2025, 7:14:06 PM

Read the original article here.


The Basic Input/Output System (BIOS): Laying the Foundation for Your Computer

In the journey of understanding and potentially building a computer from scratch, the Basic Input/Output System (BIOS) stands as a fundamental component. It's the very first piece of software that runs when you power on a PC, bridging the gap between the raw hardware and the operating system. Think of it as the computer's primal instruction set, stored directly on the motherboard, that teaches the system how to wake up, check its parts, and find the program that will ultimately take control – the operating system.

What is BIOS?

BIOS (Basic Input/Output System) is a type of firmware permanently stored on a chip on the computer's motherboard. Its primary roles are to initialize and test system hardware components during the booting process and to provide basic runtime services for the operating system and application programs, particularly in older systems or during the early boot phase of modern systems.

BIOS is often referred to by various names, including System BIOS, ROM BIOS (reflecting its original storage medium), BIOS ROM, or PC BIOS. The term "firmware" is key here; it's software that is tightly integrated with specific hardware and stored in non-volatile memory, meaning it persists even when the power is off.

The name "BIOS" itself has historical roots, originating from the CP/M operating system in 1975, where Gary Kildall used the term to describe the machine-specific part of the OS responsible for interacting directly with the hardware. When IBM created the original PC, they adopted a similar concept for their own firmware.

For someone looking to build a computer from scratch, understanding BIOS is crucial because:

  1. It defines the initial state: It's the code that runs before anything else you might write (like a bootloader or simple OS).
  2. It provides basic access: In early systems (and still in a limited way today), it offers standardized ways to interact with hardware without needing complex drivers immediately.
  3. It sets the stage for boot: It determines how and from where the next stage of the boot process is loaded.

Historical Context: From CP/M to the IBM PC and Beyond

The concept of a hardware abstraction layer, or a system to manage basic I/O, predates the IBM PC. Gary Kildall's CP/M operating system, a popular choice for microcomputers in the 1970s, included a component called the BIOS. This part of CP/M contained the low-level, hardware-specific code needed to run on different machines. The rest of CP/M, the Basic Disk Operating System (BDOS), was more hardware-independent. This allowed CP/M to be ported relatively easily by simply rewriting the BIOS for each new hardware platform.

CP/M (Control Program for Microcomputers): An early operating system created by Gary Kildall of Digital Research in 1975. It was widely adopted for 8-bit microcomputers based on the Intel 8080/8085 and Zilog Z80 processors. Its design influenced later operating systems like MS-DOS.

When IBM developed their Personal Computer (the IBM PC 5150), they needed their own firmware to handle the system's startup and basic hardware interactions. This firmware, stored in ROM, became the foundation for the PC BIOS. The original IBM PC BIOS was proprietary.

The success of the IBM PC led to a demand for compatible machines. Companies like Compaq and Phoenix Technologies invested heavily in "reverse engineering" the IBM PC BIOS. They analyzed the behavior and interfaces of the IBM BIOS without copying its code directly (to avoid copyright infringement). This effort resulted in legally compatible BIOS implementations that allowed other manufacturers to build machines that could run the same software as the IBM PC, including MS-DOS. This reverse-engineered interface became a de facto standard for PC hardware and software interaction for decades.

Reverse Engineering: The process of analyzing a finished product to understand its design, structure, and function. In the context of the PC BIOS, this involved studying the behavior of the IBM BIOS to create a compatible implementation without access to the original source code.

The evolution continued:

  • Early IBM PCs (XT-class): BIOS was stored on Mask ROM chips, which were manufactured with the code permanently etched into them. Updates required physically replacing the chip.
  • IBM PC AT and Compatibles: Introduced the use of battery-backed CMOS RAM to store configuration settings (like time, date, and hard drive parameters), which were previously set via DIP switches or jumpers. Configuration required a special utility program, often run from a floppy disk.
  • Mid-1990s onwards: Flash memory became standard for storing the BIOS. This allowed the BIOS firmware to be updated electronically ("flashing") without physically replacing the chip, enabling bug fixes, support for newer hardware, and added features. This also unfortunately opened the door to BIOS rootkits and the risk of "bricking" the motherboard if an update failed.
  • IBM PS/2 Era: IBM experimented with dividing the BIOS into CBIOS (Compatibility BIOS) for backward compatibility with DOS in real mode and ABIOS (Advanced BIOS) designed for protected-mode multitasking operating systems like OS/2. This split didn't become a widespread standard in the broader PC market.

This historical perspective is vital for understanding the technical constraints and design choices made in early PC architecture, which are directly relevant to "building from scratch" within that paradigm.

Core Functionality of the BIOS

The BIOS performs several critical tasks from the moment the computer is powered on until the operating system takes over.

1. Power-On Self-Test (POST)

Power-On Self-Test (POST): A diagnostic testing sequence that a computer's BIOS runs when first powered on. It checks the basic functionality of critical hardware components required for the system to boot, such as the CPU, RAM, keyboard controller, and video adapter.

The POST is the very first sequence of operations executed by the CPU after receiving the initial instruction from the reset vector (explained below). If the system is powered on ("cold boot"), a full POST is typically performed. If the user initiated a restart via software (like Ctrl+Alt+Delete, a "warm boot"), the BIOS might use a flag in CMOS memory to skip some of the more time-consuming tests.

During POST, the BIOS:

  • Initializes the CPU: Sets up basic registers and CPU state.
  • Checks the System Integrity: Performs checksums on the BIOS firmware itself.
  • Initializes and Tests RAM: Counts and tests system memory. Early POST often involved writing and reading patterns to specific memory locations.
  • Initializes Chipset: Configures the motherboard's chipset, which controls communication between the CPU, memory, and peripherals.
  • Detects and Initializes Basic Devices: Identifies and initializes essential components like the keyboard controller, real-time clock, and essential buses (like PCI in later systems).
  • Initializes the Video Adapter: Sets up the video card (either integrated or discrete) so that information can be displayed on the screen. This is when you typically see the manufacturer's logo or BIOS messages.
  • Identifies and Configures Storage Devices: Detects hard drives, SSDs, optical drives, etc., via interfaces like IDE/ATA, SATA, or NVMe.
  • Checks for Fatal Errors: If a critical error occurs during POST (e.g., memory failure, CPU issue), the BIOS signals this. On very early PCs, this might be a series of beeps (as the video might not be initialized). Later systems display error codes or messages on the screen.

If the POST completes successfully, the BIOS proceeds to the next stage.

2. Handling Option ROMs (BIOS Extensions)

After the core system POST, the BIOS typically scans for and executes firmware modules located on expansion cards plugged into the motherboard (like older video cards, SCSI controllers, network cards required for booting, etc.). These are known as Option ROMs or BIOS Extension ROMs.

Option ROM / BIOS Extension ROM: A block of firmware located on an expansion card that extends the functionality of the motherboard BIOS. It allows the card to be initialized and provide services before the operating system loads, especially if the card is needed for the boot process itself.

The motherboard BIOS scans a specific area of the computer's memory address space (historically, the Upper Memory Area between 0xC0000h and 0xF0000h) in chunks (typically 2 KB boundaries). It looks for a specific two-byte "signature" (0x55 followed by 0xAA) at the beginning of the chunk. If the signature is found, the BIOS checks the next byte to determine the size of the Option ROM block and performs a checksum verification. If valid, the BIOS transfers control (jumps) to an entry point specified within the Option ROM data structure.

The code in the Option ROM then executes. It is responsible for initializing the hardware on its specific card. For example, a SCSI controller's Option ROM would initialize the controller and connected drives, and potentially add new BIOS interrupt services (like extensions to Interrupt 13h for disk access) or register its capability as a boot device using the BIOS Boot Specification (BBS) API. After the Option ROM's initialization routine completes, it's expected to return control back to the motherboard BIOS. The BIOS then continues scanning for the next Option ROM until the designated memory area is exhausted.

Option ROMs were essential in the early PC era for supporting hardware that wasn't directly built into the motherboard or supported by the main BIOS. They provide a mechanism for modular hardware to integrate with the system's boot process. Some older motherboards even had empty sockets to manually plug in Option ROM chips for added functionality.

3. Boot Process (Loading the Operating System)

The final critical task of the BIOS is to find and load the initial boot loader software, which in turn starts the operating system.

Boot Loader: A small program whose primary function is to load a larger program, such as an operating system kernel, into memory and begin its execution.

After POST and Option ROM scanning, the BIOS initiates the boot sequence, typically by calling Interrupt 19h. This interrupt signals the start of the boot process. The BIOS then consults its configuration settings (stored in CMOS or flash memory) to determine the "boot order" – the sequence of devices it should check for bootable media (e.g., floppy disk, hard disk, CD/DVD, USB drive, network).

For each device in the boot order, the BIOS attempts to read the very first sector (Sector 0). This sector is typically 512 bytes long and is known as the boot sector. On a hard drive, this is the Master Boot Record (MBR). On a floppy disk or a CD/DVD emulating one (using the El Torito standard), it's the Volume Boot Record (VBR).

Boot Sector: The first sector (512 bytes) of a bootable storage device (like a floppy disk, hard drive partition, or optical disc). It contains initial bootstrap code and often information about the file system.

Many BIOS implementations also check for a specific signature at the end of the boot sector (the last two bytes must be 0x55 followed by 0xAA) to confirm that the sector is intended to be a boot sector. If a valid boot sector is found, the BIOS loads its 512 bytes into memory at a fixed address (specifically, physical address 0x07C00).

Once loaded, the BIOS transfers execution control directly to this boot sector code. At this point, the BIOS has done its job, and the boot loader code loaded from the device takes over. The BIOS itself does not interpret the contents of the boot sector or file systems; that's the boot loader's responsibility.

For a "from scratch" builder, this is the point where your own code, if written as a boot sector, would begin executing. Understanding the environment the BIOS sets up before jumping to 0x07C00 is critical.

The Boot Environment

When the BIOS jumps to the boot sector at 0x07C00, the CPU is in Real Mode.

Real Mode: The operating mode of 8086 and later x86 processors where the processor behaves like an 8086, with a 20-bit segmented memory address space (allowing access up to 1 MB of memory) and no memory protection.

The state of the system in Real Mode at this point is relatively simple:

  • CPU Mode: Real Mode.
  • Instruction Pointer (CS:IP): Points to 0x07C00. The exact values for CS and IP vary between BIOS implementations (e.g., 0x0000:0x7C00 or 0x07C0:0x0000), but the resulting physical address is always 0x07C00.
  • Stack Pointer (SS:SP): Points to a valid stack location set up by the BIOS, but its size and location are not standardized. A robust boot sector typically sets up its own stack.
  • Other Registers: General-purpose and segment registers (like AX, BX, CX, DX, ES, DS, etc.) generally have undefined values, except for the DL register, which usually contains the drive number of the boot device (as used by BIOS interrupt 13h disk services).
  • Interrupt Vector Table: Located at memory address 0x00000 to 0x003FF, this table is populated by the BIOS with entry points for BIOS services (like Interrupt 13h for disk, Interrupt 10h for video, Interrupt 16h for keyboard) and hardware interrupts.
  • BIOS Data Area (BDA): A small area in conventional memory (typically 0x00400 to 0x004FF) used by the BIOS to store various system parameters and states (like the keyboard buffer, serial/parallel port addresses, disk drive parameters).
  • Available Memory: Memory from 0x00500 upwards is available for the boot program.

This established environment allows the boot sector code to immediately use the basic BIOS services via interrupts and load further stages of the operating system.

User Interaction and Configuration

While the primary function of the BIOS happens automatically during boot, it also provides a way for users to configure hardware settings.

BIOS Setup Utility

Early PCs used DIP switches or jumpers on the motherboard to set options like memory size or video adapter type. Later, the IBM AT stored settings in battery-backed CMOS RAM but required a separate utility program (often on a floppy disk) to change them.

Starting in the mid-1990s, it became common for the BIOS firmware itself to include a BIOS configuration utility (or BIOS setup utility, or CMOS setup). This is a basic interactive program stored within the BIOS ROM that users can access by pressing a specific key (commonly Delete, F2, F1, or F10) very early in the boot process, usually prompted on the screen during POST.

CMOS (Complementary Metal-Oxide-Semiconductor) RAM: A small amount of non-volatile memory on the motherboard that stores BIOS configuration settings (like boot order, system time, hardware parameters). It is typically powered by a small battery (the CMOS battery) to retain its contents when the main system power is off. While often referred to as "CMOS RAM," modern systems store configuration in the same flash memory as the BIOS itself, but the settings section is still commonly called "CMOS Setup."

The BIOS setup utility allows users to:

  • Configure or disable integrated hardware components (e.g., serial ports, USB controllers).
  • Set the system date and time.
  • Specify the boot order of devices.
  • Set passwords to protect access to the setup utility or the boot process itself.
  • Adjust performance settings (like memory timings, CPU frequency - see Overclocking).
  • Monitor system health (temperatures, fan speeds, voltages).

These settings are stored in the CMOS RAM or the dedicated configuration section of the flash memory, and the BIOS reads them every time the system boots to apply the user-specified hardware configuration.

Hardware Monitoring

Modern BIOS implementations often include features to monitor the system's hardware health. This is typically done by interfacing with a dedicated hardware monitor chip on the motherboard. The BIOS setup utility can display readings for CPU and chassis temperatures, power supply voltages, and fan speeds. It may also allow basic control over fan speeds. After the OS boots, specialized software or operating system drivers take over this monitoring, often communicating with the same hardware monitor chip.

Reprogramming (Flashing the BIOS)

As mentioned, modern BIOS is stored in rewritable flash memory. This allows the BIOS firmware to be updated, a process commonly referred to as "flashing the BIOS".

Flashing the BIOS: The process of replacing the existing BIOS firmware image on the motherboard's flash memory chip with a new version. This is usually done using a utility program provided by the motherboard manufacturer.

BIOS updates are released by motherboard manufacturers to fix bugs, improve compatibility with newer hardware (like CPUs, RAM, or expansion cards), add new features, or address security vulnerabilities. The process usually involves downloading a BIOS image file and running a flashing utility, often integrated into the BIOS setup utility itself or run from a bootable USB drive.

Flashing can be risky; an interruption (like a power loss) or using an incorrect BIOS image can corrupt the firmware, rendering the motherboard "bricked" or unusable. Newer motherboards often include features to mitigate this risk, such as:

  • Boot Blocks: A small, protected area of the flash memory that contains minimal code capable of initiating a recovery process even if the main BIOS is corrupted.
  • DualBIOS / Backup BIOS: Some motherboards have a secondary, backup BIOS chip that can automatically restore the main BIOS if it becomes corrupted.

BIOS as an Operating System Service

In the era of MS-DOS and other early single-tasking operating systems, the BIOS provided a crucial layer of abstraction between software and hardware.

BIOS Interrupt Calls: Software routines provided by the BIOS that can be invoked by application programs or the operating system by triggering a specific hardware interrupt (like INT 10h, INT 13h, INT 16h). These provide standardized ways to perform basic I/O operations.

The original IBM PC BIOS offered a library of functions accessible via software interrupts. For example:

  • INT 10h: Video services (displaying text/graphics, changing video modes).
  • INT 13h: Disk services (reading/writing sectors to floppy or hard disks).
  • INT 16h: Keyboard services (reading key presses).
  • INT 17h: Printer services.

This allowed programs running under DOS to interact with hardware in a relatively standardized way, regardless of the specific hardware implementation (e.g., whether a system used a monochrome or color graphics card). This was particularly useful for early applications and the command-line environment of DOS.

However, using BIOS services via interrupts in Real Mode was slow and inefficient, especially for tasks like graphics-intensive operations. Programmers soon discovered that bypassing the BIOS and programming the hardware registers directly offered significant performance advantages. Furthermore, the 1 MB memory limitation and lack of protection in Real Mode made BIOS services unsuitable for the needs of modern multitasking operating systems like Windows NT, Linux, or macOS.

Modern operating systems use BIOS services primarily during the initial boot phase. Once the OS kernel is loaded and switches the CPU into Protected Mode (or Long Mode), it typically takes over direct control of the hardware using its own device drivers. These drivers interact directly with hardware registers and do not use the legacy BIOS interrupt calls for routine operations.

Nevertheless, some interfaces standardized by the BIOS still exist in modern systems and are used by modern OSes, but often accessed in ways compatible with protected mode, such as:

  • ACPI (Advanced Configuration and Power Interface): Used by the OS for power management and hardware configuration.
  • SMBIOS (System Management BIOS): Provides information about the system's hardware components.
  • e820: A memory map interface used by the OS to determine available memory regions.
  • VESA BIOS Extensions (VBE): Provided more advanced video modes beyond the basic VGA modes.

Legacy BIOS systems (or UEFI systems running in Compatibility Support Module, CSM, mode) can still boot and run older operating systems like MS-DOS that rely heavily on BIOS interrupt calls.

Hardware Aspects

Where and how the BIOS is stored and how it interfaces with other hardware are important technical details.

Storage Medium

  • Mask ROM: The earliest, non-alterable storage. Code was "masked" during the chip manufacturing process. Updating meant replacing the chip. (IBM PC, XT)
  • EPROM (Erasable Programmable Read-Only Memory): Could be erased using ultraviolet light and reprogrammed using a special programmer. Required removing the chip from the motherboard.
  • EEPROM (Electrically Erasable Programmable Read-Only Memory): Could be erased and reprogrammed electrically. Could potentially be reprogrammed while still on the motherboard, but often slower than flash.
  • Flash Memory (NOR Flash): The standard for modern BIOS. Electrically erasable and programmable, allowing in-circuit flashing via software utilities. Faster for reading than typical EEPROM. Became common around 1995.

The size of the BIOS firmware has grown dramatically over time, from the original IBM PC's 8 KB to multi-megabyte images today, reflecting the increasing complexity of hardware it needs to initialize and manage.

Interfacing

Initially, BIOS chips interfaced directly with the CPU via the system bus. As PC architecture evolved:

  • ISA Bus: Early flash BIOS chips were connected via the Industry Standard Architecture (ISA) bus.
  • LPC Bus: Around 1998, the Low Pin Count (LPC) bus became standard for connecting the BIOS flash chip and other slow I/O devices, often via a "firmware hub" (FWH).
  • SPI Bus: More modern systems use the Serial Peripheral Interface (SPI) bus for faster access to the BIOS flash memory.

Related Firmware and Components

Beyond the main BIOS, other specialized firmware and components are involved in the low-level system operations:

  • Keyboard Controller: On IBM AT and later systems, a separate microcontroller managed the keyboard interface and the A20 gate (for accessing memory above 1 MB in Real Mode). This controller had its own firmware, sometimes also referred to as a "keyboard BIOS," which could occasionally require updates.
  • Memory Reference Code (MRC): Often a part of the BIOS, the MRC is crucial for initializing the memory system (DRAM). It reads information from the memory modules (via SPD - Serial Presence Detect) and configures complex timings and settings required for stable memory operation, a process highly dependent on the specific CPU and memory types.
  • Integrated Management Engine (IME) / Platform Security Processor (PSP): Modern Intel and AMD platforms include complex co-processors with their own significant firmware (IME for Intel, PSP for AMD). These components handle out-of-band management, security features, and other low-level tasks, running largely independently of the main CPU and traditional BIOS/UEFI. Their firmware is often stored alongside or integrated with the main BIOS flash.

Security Concerns

The critical, low-level nature of BIOS makes it a target for malicious attacks. If BIOS firmware is compromised, an attacker could potentially gain deep control over the system, even before the operating system loads, and potentially install persistent rootkits that are difficult to detect and remove.

Historically, vulnerabilities like the CIH virus (Chernobyl) in the late 1990s demonstrated that malicious code could erase the BIOS flash memory on systems with vulnerable chipsets (like the Intel i430TX) running operating systems that allowed direct hardware access (like Windows 9x). Such an attack could render the computer unbootable, requiring hardware replacement or specialized reprogramming.

Modern systems are less vulnerable to this specific type of attack due to:

  • Protected Boot Blocks/DualBIOS: As mentioned earlier, hardware safeguards make it harder to completely brick the BIOS via software.
  • Operating System Security: Modern OS kernels (Windows NT-based versions, Linux, macOS, BSD) enforce privilege separation and prevent user-mode programs from directly accessing hardware ports and memory regions required to reprogram the BIOS. An attacker would typically need higher privileges (like Administrator/root) or a kernel exploit to attempt a BIOS attack.
  • Hardware-Based Protections: Intel Boot Guard (IBG) and similar technologies on newer platforms verify the digital signature of the firmware before executing it, attempting to prevent modified or malicious firmware from running.

Despite these protections, BIOS/UEFI security remains an important area of research, as compromise at this level is highly potent.

Alternatives and Successors: The Rise of UEFI

The legacy PC BIOS, based on Real Mode operation and interrupt services, had fundamental technical limitations imposed by its origins in the 1980s 16-bit architecture. These limitations included:

  • Limited addressable memory during boot (1 MB).
  • Inflexible driver model tied to Real Mode.
  • Difficulty supporting new hardware interfaces (especially larger disks, networking).
  • Slow performance for complex tasks.
  • Lack of standardized modularity and extensibility.

To address these issues, the industry developed the Unified Extensible Firmware Interface (UEFI) as a successor.

UEFI (Unified Extensible Firmware Interface): A software interface between a computer's operating system and platform firmware. It replaces the legacy BIOS, providing a more modern environment for system startup, including native support for 64-bit operation, networking, and modular drivers.

UEFI provides a more feature-rich, modular, and flexible environment compared to legacy BIOS. It can run in 32-bit or 64-bit mode and has direct access to all system memory. It defines standardized interfaces for hardware access (UEFI drivers) and includes capabilities like network booting, secure boot (verifying the integrity of the OS loader), and support for large storage devices (GPT partition tables).

Most modern PCs ship with UEFI firmware. To maintain compatibility with older operating systems or hardware that rely on legacy BIOS interfaces, UEFI firmware often includes a Compatibility Support Module (CSM).

Compatibility Support Module (CSM): A component of UEFI firmware that provides backward compatibility with legacy BIOS. When CSM is enabled, UEFI can emulate the traditional BIOS environment, allowing older operating systems (like MS-DOS or older versions of Windows/Linux) or Option ROMs written for BIOS to function.

However, the industry is transitioning away from legacy BIOS entirely. Intel announced plans to remove legacy BIOS support from its platforms by 2020, and newer operating systems like Windows 11 require UEFI (except for some IoT editions). For someone building a modern system "from scratch," working with UEFI rather than legacy BIOS is the contemporary path.

Beyond UEFI, other alternative open-source firmware projects exist, notably Coreboot and Libreboot, which aim to replace proprietary BIOS/UEFI firmware with minimal, open-source alternatives, offering greater transparency and flexibility, particularly in server and embedded environments, and increasingly appearing on some consumer hardware.

Understanding BIOS is not just about appreciating the history; it's about understanding the fundamental steps a computer takes to go from inert hardware to a running system. While UEFI is the present and future, the concepts introduced by BIOS – POST, hardware initialization, boot device selection, and the initial jump to a bootloader – remain central to the startup process. For anyone delving into the low-level mechanics of computers, particularly the architecture of early PCs, the BIOS is the essential starting point.

See Also