How computers work

UEFI firmware and boot loader: the first seconds after the power button

When you press the power button, the operating system is sitting on the drive, but there is nobody to start it: the processor is empty, the RAM is not configured, and no devices have been found. This job is done by the UEFI firmware — a program stored in a flash memory chip on the motherboard. It brings the hardware up from scratch, finds the OS boot loader, checks its signature, leaves the system a detailed description of the board, and then leaves the stage.

Open in 3D →

From the button to the first instruction

The button on the case does not switch the computer on directly: it closes a contact watched by the board’s standby logic. The 5 V standby power from the power supply is always present as long as the plug is in the socket — that is why a computer can “wake up” from the button, from the network, or on a timer. Once it receives the command, the board asks the power supply to turn on, and the supply brings the 12, 5 and 3.3 V rails up to their nominal values in roughly 100–500 ms.

Until the voltages have settled, the processor is held in reset: starting up on “drifting” power would leave the transistors in a random state. When the power supply reports with the Power Good signal that everything is fine, and the VRM regulators have set the core voltage to about 1 V, the reset is released.

Even before the first clock tick of the x86 cores, a small service processor inside the chip wakes up: at AMD this is the Platform Security Processor, built on an ARM core; at Intel it is the Management Engine subsystem together with the Boot Guard mechanism. It reads the firmware from flash memory and checks its digital signature — if someone has swapped the firmware, the main processor will not start at all. At AMD this same service processor later also configures the memory.

The firmware itself lives in an SPI flash chip, usually 16–64 MB in size. It is connected to the chipset (on some platforms, directly to the processor) by a thin serial bus of four to six wires, and it is mapped to the very top of the address space. The first processor core (called the bootstrap processor, BSP) starts at a fixed address — the reset vector 0xFFFFFFF0, 16 bytes before the end of the first four gigabytes. There sits a jump instruction to the beginning of the firmware. The other cores are still asleep.

SEC and PEI: life without RAM

For the first milliseconds the processor lives in very strange conditions. It starts in 16-bit “real mode” — just like the 8086 processor in 1978: compatibility with the past is still maintained here. The very first firmware instructions switch it to 32-bit protected mode, and later, before drivers are loaded, to 64-bit mode.

The main problem is that there is no RAM. The DDR5 modules are sitting in their slots, but the memory controller does not yet know what they are or with what timings to talk to them. Yet an ordinary program needs a stack: where else would it put return addresses and local variables? The solution is to temporarily use the processor cache as memory (Cache-as-RAM). The firmware switches the cache into a special mode where lines are never evicted or written out, and gets several hundred kilobytes to a few megabytes of fast memory.

In the UEFI specification this stage is called SEC (Security) and PEI (Pre-EFI Initialization). PEI code is written very frugally and is often executed straight from flash memory, slowly — every read goes over the SPI bus. Its task is narrow: switch on the bare minimum of hardware and, above all, bring the RAM to life. If the board has debug LEDs or a two-digit POST code display, at this stage they show the processor and memory initialization codes.

Why is it so complicated? Because the processor is universal, while every board is different. How many memory modules there are, which frequencies, which voltages — none of this is known in advance, and only code running on the processor itself can find out.

See also: Cache: why the processor doesn’t wait for memory

Memory training: why the first boot takes so long

Every DDR5 module carries a small SPD chip — the module’s passport: capacity, number of ranks and banks, supported frequencies and timings (for example, 6000 MT/s at CL 30), and the XMP or EXPO overclocking profile. The firmware reads it over a service bus (for DDR5 this is I3C via the SPD hub chip on the module) and decides how to configure the memory controller.

But the passport is not enough. At 6000 MT/s a single bit lasts about 170 picoseconds, and the signals on different bus wires reach the chips at different times: the traces on the board have different lengths, and the chips on the module sit at different distances from the connector. So the firmware performs “memory training”: for every wire and every chip it tunes the delays, the reference voltage and the sampling moment, writes and reads test patterns, and looks for the middle of the “window” in which data is read without errors.

For two DDR5 modules this means tens of millions of trial operations. The first boot with new memory can take anywhere from 30 seconds to several minutes, especially with four modules or a large capacity — the screen stays black the whole time, and people often think the computer is broken. The training results are saved in flash memory, and on later boots the firmware only checks them quickly.

Once training is finished, the processor has full-fledged RAM — tens of gigabytes. The firmware unpacks the rest of its modules into it and moves on to the next phase. Along the way it builds a memory map: which address ranges are real RAM, which are occupied by devices, and which must be reserved for the firmware. The operating system will receive this map later.

See also: DDR5 memory: how a byte is stored

DXE: firmware drivers and walking the PCIe bus

The DXE phase (Driver Execution Environment) is already almost a small operating system: in 64-bit mode, hundreds of firmware driver modules are loaded, each with its own task. Some enable USB so the keyboard works, others the network card, others the drives. Drivers announce themselves through “protocols” — tables of functions that other modules can find and call.

The main job of DXE is enumerating the PCIe bus. Every PCIe device has a “bus : device : function” address and a 4 KB configuration space that records its vendor, type and requirements. The firmware polls all possible addresses one by one, finds bridges and goes behind them, building a device tree: processor → graphics card, processor → NVMe, processor → chipset → USB controller, network, SATA.

Every device needs a window in the address space — the BAR ranges through which the processor will read and write its registers. The device reports how much it needs (a graphics card needs hundreds of megabytes or gigabytes to access video memory), and the firmware hands out addresses so that the windows do not overlap. At the same time each link negotiates its speed: PCIe 5.0 gives 32 gigatransfers per second per lane, about 63 GB/s in one direction for an x16 slot.

The graphics card has its own small firmware (Option ROM) with a GOP driver — Graphics Output Protocol. The board’s firmware runs it, and the first image appears on the screen — the manufacturer’s logo. Until that moment the monitor was showing “No signal.” If a freshly assembled PC “won’t start,” it is most often stuck in one of these phases, and the POST code or the debug LEDs will tell you which one: CPU, memory, video or boot.

POST, settings, and what the battery keeps

POST (Power-On Self-Test) is the historical name for the self-check at power-on. In the BIOS era it was a separate stage with a memory count on the screen; in UEFI the checks are spread across the PEI and DXE phases: the processor, memory, graphics card, presence of a keyboard, temperature sensors and fans are all checked. A serious error, and the firmware stops, blinking an LED or sounding a beep code.

The setup screen that opens with Del or F2 is also a firmware application. The settings (boot order, memory frequencies, enabling virtualization, Secure Boot) are stored as UEFI variables in a separate area of the same SPI flash memory, called NVRAM. The operating system can also read and write these variables — for example, a Linux installer adds its own entry to the boot menu.

The CR2032 battery powers the real-time clock, which keeps ticking while the computer is unplugged. It used to power a small CMOS memory as well, where all the settings were stored — hence the phrase “clear CMOS.” On modern boards most settings live in flash memory, but clearing CMOS still restores them to factory defaults.

A common misconception is to call the firmware “BIOS” and believe that it lives “in the battery.” BIOS is an old firmware standard from 1981 (the IBM PC), with 16-bit code and interrupts. UEFI replaced it in the 2010s, and by the mid-2020s manufacturers had mostly removed the CSM compatibility mode that allowed booting old systems. The word “BIOS” has remained in board menus as a familiar name.

The boot manager: which file to run

The last phase before the OS is BDS (Boot Device Selection). The firmware reads the BootOrder variable — a list of numbers such as 0001, 0003, 0000 — and for each number reads a variable like Boot0001 with a description: which disk, which partition, which file to run. These are the entries of the boot menu that opens with F8, F11 or F12.

Today disks are partitioned in the GPT format: a partition table with unique identifiers at the start of the disk, and a copy of it at the end. The old MBR scheme stored the table in the first 512 bytes, allowed four primary partitions, and could not see beyond 2 TB. One of the GPT partitions is the EFI System Partition (ESP), an ordinary FAT32 partition of 100 MB – 1 GB. The firmware can read FAT32 by itself, without any OS.

The EFI partition holds boot loaders as files: for Windows it is \EFI\Microsoft\Boot\bootmgfw.efi, for Linux \EFI\ubuntu\shimx64.efi or systemd-boot. If there is no menu entry (for example, you have plugged in an installation USB stick), the firmware looks for a file at the standard path \EFI\BOOT\BOOTX64.EFI. A boot loader is a UEFI program in the PE format, the same format as an .exe in Windows.

This is the main difference from BIOS. The old firmware simply read the first sector of the disk (512 bytes) into memory at address 0x7C00 and jumped there, without knowing what it contained. UEFI understands partitions and files, can check signatures, and gives the boot loader a set of services: reading files, allocating memory, printing text and drawing graphics. The boot loader does not have to write its own disk driver.

Secure Boot and TPM: who checks the boot loader

Malware that starts before the OS (a bootkit) sees everything and can hide from antivirus software. Secure Boot closes this hole: the firmware runs only code whose digital signature verifies against keys stored in NVRAM. There are several levels of keys: the PK (Platform Key, from the board manufacturer) allows changing the KEK; the KEK keys allow changing the db database (allowed signatures and hashes) and dbx (revoked ones — for example, boot loaders with known vulnerabilities).

The db database of almost any PC contains Microsoft certificates: one for Windows, another for third-party boot loaders. Linux passes Secure Boot through a small boot loader called shim, signed by Microsoft: inside shim is the distribution’s key, which it uses to check GRUB, and GRUB in turn checks the kernel. So the common belief that “Secure Boot prevents you from installing Linux” is wrong: popular distributions boot with it out of the box, and you can add your own keys yourself.

Signature checking is a matter of “let in or keep out.” The TPM (Trusted Platform Module — a separate chip or a block inside the processor) has a different role: to measure. Each boot stage, before handing control to the next one, computes the next stage’s hash and “extends” a PCR register with it: new value = hash(old value + hash of the new code). An entry cannot be erased; you can only extend.

As a result, the PCR values are a fingerprint of the whole boot chain. Disk encryption is tied to them: BitLocker or LUKS store the key in the TPM “sealed” to specific PCR values. If someone has swapped the boot loader or changed the Secure Boot settings, the fingerprint will not match, the TPM will not release the key, and you will be asked for the recovery key. That is why Windows sometimes asks for the BitLocker key after a firmware update.

ACPI: a description of the board for the operating system

The operating system needs to learn how many cores the processor has, where the interrupt controllers are, which devices are not on PCIe (the power button, sensors, fans, a laptop battery), and how to put the computer to sleep. Probing everything again would be slow and dangerous, so the firmware leaves ACPI tables (Advanced Configuration and Power Interface) in memory.

The tables form a tree: from the RSDP pointer to the main XSDT table, and from it to dozens of specialized ones. MADT lists the cores and the APIC interrupt controllers, MCFG says at what address the PCIe configuration space lives, SRAT describes which memory is closer to which processor (important for two-socket servers), and FADT describes how to manage power. Separately there are SMBIOS tables: board model, serial numbers, installed memory modules — these are what programs like “System Information” display.

The trickiest table is DSDT. It contains not data but a program in AML bytecode: methods like “turn on the fan,” “read the battery charge,” “put the device into D3 state.” The OS kernel includes an AML interpreter that executes these methods. This way the board manufacturer can describe non-standard hardware, and the OS does not need a separate driver for every model.

ACPI also defines power states: S0 — working, S3 — sleep with the memory powered, S4 — hibernation to disk, S5 — soft off; C-states — how deeply idle cores “sleep”; P-states — steps of frequency and voltage. When the OS puts processor cores to sleep while idle, it does so by the rules the firmware left behind. Part of the firmware keeps running after boot: runtime services (reading variables, the clock, reboot) and SMM — a special processor mode invisible to the OS, in which the firmware handles emergency board events.

See also: The operating system: who shares out the processor, memory and devices

Handing over control: ExitBootServices

The OS boot loader runs as an ordinary UEFI application. Windows Boot Manager finds the right Windows installation and launches winload.efi, which reads into memory the ntoskrnl.exe kernel, the registry, and the drivers needed for startup. GRUB or systemd-boot read the Linux kernel (the vmlinuz file, 10–15 MB compressed) and the initramfs — an archive with a minimal set of programs and drivers for the first seconds.

Then the boot loader asks the firmware for the final memory map and calls the ExitBootServices function. From this moment the firmware no longer controls the computer: its drivers stop working, and the memory they occupied is given to the OS. Only the runtime services and the ACPI tables remain. The OS kernel receives control on the bootstrap processor core, in 64-bit mode, with a memory map and pointers to the tables.

From here on it is the OS doing the work: it builds its own page tables, sets up interrupt handlers, uses the MADT table to wake the remaining processor cores (each of them also starts in 16-bit mode and goes through the transition to 64-bit mode), loads drivers, and starts the first user-mode process — systemd in Linux or smss.exe in Windows.

How long does all this take? On a typical modern PC the firmware takes 3–10 seconds (not counting the first memory training), the boot loader a fraction of a second, and the OS kernel and services another 5–15 seconds until the desktop appears. “Fast Boot” in the settings saves time by skipping the probing of non-essential devices, while Windows “Fast Startup” does not actually shut the kernel down but saves it to disk, like hibernation. In the model, the “PC startup” scenario at the Workstation level goes through this very chain: “No signal” → UEFI screen → boot loader → desktop.

See also: The operating system: who shares out the processor, memory and devices

Open in 3D →

All articles

Overviews

Logic: from transistor to arithmetic

Processor

Computer

Servers and data centers

Networks and the internet

Software