CLOSE

The computer startup process is the sequence of events that happens from the moment you press the power button until the operating system is fully loaded and ready to use. This process involves several key stages, including the BIOS/UEFI, bootloader, and operating system initialization. Here's a step-by-step breakdown:

Computer Startup Process

[Power On or Reset] 
        |
        v
[CPU Starts at Reset Vector]  <-- Reset Vector located at 0xFFFF0
        |
        v
[BIOS Execution Begins]  <-- BIOS code mapped to 0xF0000 - 0xFFFFF
        |
        v
[BIOS performs POST]  <-- Power-On Self-Test, checks hardware
        |
        v
[Hardware Initialization]  <-- Initializes CPU, RAM, keyboard, video, disks, etc.
        |
        v
[Search for Boot Device]  <-- BIOS checks storage devices (e.g., HDD, SSD, USB)
        |
        v
[Load Bootstrap Loader]  <-- Loads bootloader from the boot device (e.g., from MBR)
        |
        v
[Bootloader Loaded into RAM]  <-- Bootloader now resides in conventional RAM
        |
        v
[Hand off Control to Bootloader]  <-- Bootloader begins executing in RAM
        |
        v
[Bootloader Loads the Operating System]  <-- OS kernel is loaded and executed
        |
        v
[Operating System Takes Over]

1️⃣ Power Supply and Initial Hardware Checks

When the computer is powered on, electrical signals are sent to the CPU, memory, and other hardware components. If everything went well then the CPU start executing the instructions stored at location of reset vector. This usually contains the jmp instruction which directs the CPU to the BIOS/UEFI.

🔰 Power-On:

  • Power Button Pressed: When you press the power button, an electrical circuit closes, allowing current to flow from the power supply unit (PSU) to the motherboard and other components.
  • Power Good Signal: The power supply performs a self-test and sends a "Power Good" signal to the motherboard if all voltages are within the correct ranges. This signal ensures that the power supply is stable and ready.

🔰 System Reset

Upon receiving the "Power Good" signal, the CPU is taken out of reset mode, in this mode the CPU goes to the location known as the reset vector and start executing instruction from there.

When a computer is powered on or reset, the CPU is an undefined state. It reads a specific, predefined memory location to start executing instructions. This location is the reset vector.

The reset vector is a predefined memory address where the CPU expects to find the first instruction to execute after a reset event. This event can be triggered by powering on the system, pressing the reset button, or by a software-initiated reset.

Reset Vector Address:

  • On x86 systems, the reset vector typically points to the address 0xFFFF:0000 in real mode (or 0xFFFFFFF0 in 32-bit protected mode and later systems).
  • The reset vector usually contains a jump instruction that redirects the CPU to part of the BIOS or UEFI (stored in non-volatile memory flash ROM on the motherboard). Thus we can say that this location directs the CPU to begin executing the BIOS initialization code.
  • The CPU reaches the location of 0xFFFF0 by setting the CS (Code Segment) register to 0xF000, and IP (Instruction Pointer) to 0xFFF0. Which is translated to 0xFFFF0.

Why a Fixed Address?

  • A fixed address for the reset vector ensures that, after a reset, the CPU always knows where to start executing instructions. This simplifies the hardware design and ensures a predictable startup behavior.
  • When the system is powered on or reset, the CPU does not retain any memory of its previous state, so it immediately goes to the reset vector (a fixed memory address).

Reset Vector:

  • The code at the reset vector is usually stored in non-volatile memory (such as ROM or Flash memory) so that it is available immediately upon power-up.
  • The CPU fetches the instruction at the reset vector address. This instruction is typically a jump instruction that redirects execution to the start of the BIOS or UEFI firmware.
    • Location: In real mode (the initial mode of operation for x86 CPUs), the reset vector is typically at 0xFFFF0 (16 bytes below the top of the 1MB memory space).
      • This is where the CPU expects the first instruction to be located after a reset.
      • This address contains a jump instruction to the BIOS startup code.
      • Example: On an x86 system, the CPU starts at address 0xFFFF0, and the BIOS has a jump instruction there that directs the CPU to the actual BIOS code at a lower memory address.
        • This instruction might be something like jmp 0xF000:0000, which tells the CPU to jump to 0xF0000 and begin executing the BIOS.
Memory Map in Real Mode (x86)
Address Range (Hex)Description
0x00000 - 0x9FFFFConventional RAM (640 KB)
0xA0000 - 0xBFFFFVideo Memory (VRAM)
0xC0000 - 0xEFFFFAdapter ROMs, Video BIOS
0xF0000 - 0xFFFFFSystem BIOS (64 KB) (ROM mapped into address space)
0xFFFF0 - 0xFFFFFReset Vector (16 bytes) (points to BIOS code)

In x86 real mode, the System BIOS is mapped into the upper portion of the 1 MB addressable memory space:

  • Memory range: 0xF0000 - 0xFFFFF
  • Size: 64 KB (though BIOS code may reside in a larger ROM chip, only this section is mapped into the first 1 MB of memory).

Jump to Firmware:

  • The reset vector points to the start of the firmware code (BIOS or UEFI), which is stored in non-volatile memory or the motherboard (typically ROM or flash memory).

2️⃣ BIOS/UEFI Initialization

As we studied above that the reset vector jumps to the BIOS/UEFI firmware which is stored in the ROM. The BIOS firmware is mapped to the address range 0xF0000 - 0xFFFFF. This code is stored in ROM, but it's memory-mapped to these addresses so the CPU can access and execute it.

This is done using the technique called BIOS Shadowing, in this performance of the Basic Input/Output System (BIOS) routines is imporoved by copying the BIOS firmware code from slower ROM (Read-Only Memory) into faster RAM (Random Access Memory). Once the BIOS code is loaded into the RAM, the system can access and execute it much more quickly, significantly improving system performance. This memory regions where the BIOS is shadowed is often write-protected and non-cacheable to prevent the operating system or applications from accidently modifying it. This memory is typically above 640 KB and within the Upper Memory Area (UMA) (from 0xC0000 to 0xFFFFF), which is part of the first 1MB of addressable memory. This is done because of below reasons: We can't execute from the Flash ROM forever as it is slower. Most of BIOS is compressed and we need to un-compress it when run from somewhere else in the memory.

The BIOS/UEFI performs the Power-On Self Test (POST) and Hardware initialization.

🔰 BIOS/UEFI Firmware Execution

  • Firmware Start: The CPU begins executing the BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface) firmware code stored in ROM or flash memory on the motherboard.
  • POST (Power-On Self Test):
    • The firmware runs a series of diagnostic tests to check the basic functionality of the hardware components, including the CPU, RAM, storage devices, and peripheral devices.
    • Any detected issues are reported via beep codes (series of beeps) or displayed error messages, providing a way to diagnose hardware problems early in the boot process.

🔰 Hardware Initialization:

  • System Bus Initialization:
    • The firmware initializes the system buses (such as PCI and PCIe), allowing the CPU to communicate with other hardware components.
  • Peripheral Initialization:
    • Peripheral devices like the keyboard, mouse, and video card are initialized to ensure they are ready for use.
  • Memory Initialization:
    • The firmware performs a memory check to verify that the RAM is functioning correctly and determines the amount of available memory.

3️⃣ Firmware Setup and Configuration

🔰 BIOS/UEFI Setup Utility

  • User Access to Setup Utility:
    • During POST, the user can enter the BIOS/UEFI setup utility by pressing a specific key (e.g., Del, F2, Esc). This utility allows users to configure system settings like the system clock, boot order, and hardware configurations.
  • Configuration Storage:
    • CMOS and NVRAM: Settings configured in the BIOS setup utility are stored in CMOS (Complementary Metal-Oxide-Semiconductor) memory, which is powered by a small battery, or in NVRAM (Non-Volatile Random Access Memory) in UEFI systems.

4️⃣ Boot Device Selection

After the BIOS/UEFI completes the POST, it looks for a bootable device (based on the boot order set in the firmware settings) such as a hard drive, SSD, USB drive, or optical drive, following the order defined in the boot priority settings.

🔰 Boot Sequence

  • Boot Order: The BIOS/UEFI firmware follows a predefined boot sequence to determine which device to boot from. This sequence can be configured in the setup utility.
  • Boot Device Detection: The firmware checks for bootable devices, such as hard drives, SSDs, USB drives, or network boot options. The BIOS reads the Master Boot Record (MBR) or the first sector of the bootable device to find the bootloader.

5️⃣ Loading the Bootloader

The firmware then attempts to load the bootloader from the selected boot device into conventional RAM (below 640 KB).

🔰 MBR and GPT

  • MBR (Master Boot Record): In BIOS systems, the firmware reads the first sector of the bootable device (MBR), which contains the bootloader code and load it at memory location 0x7c00 and transfers control to it.
    • In older systems, the first 512 bytes of the storage device (the boot sector) contains the MBR, which includes the bootloader and partition information.
  • GPT (GUID Partition Table): In UEFI systems, the firmware reads the EFI System Partition (ESP) to find and execute the bootloader file (e.g., BOOTX64.EFI).
    • For modern systems using UEFI, GPT is used, which supports larger drives and more partitions than MBR.

🔰 Bootloader Execution:

  • Executing the Bootloader: The firmware transfers control to the bootloader, which is a small program responsible for loading the operating system kernel into memory.
  • Loading the OS Kernel: The bootloader loads the operating system kernel and passes control to it. Common bootloaders include GRUB (GRand Unified Bootloader) for Linux systems and the Windows Boot Manager for Windows systems.

6️⃣ Operating System Initialization

🔰 Kernel Initialization:

  • Kernel Initialization: The operating system kernel initializes system components, including memory management, process scheduling, and hardware abstraction.
  • Driver Loading: The kernel loads essential drivers required to interface with hardware devices like disk drives, network cards, and input devices.

🔰 User Space Initialization:

  • User Space Initialization: The kernel starts user-space processes, including system daemons and services required for the operating system to function.
  • Login Prompt/Graphical Interface: Finally, the operating system presents a login prompt or graphical user interface, allowing the user to interact with the system.

Knowledge Center

BIOS Code Location:

The BIOS firmware resides in a ROM (Read-Only Memory) or flash memory chip, and the CPU accesses it directly from there. However, in the x86 architecture, this ROM is mapped into the address space at specific locations to allow the CPU to execute the BIOS code during system initialization.

The BIOS region is mapped into the upper 64 KB of the first megabyte of addressable memory (real mode). This is the area from 0xF0000 to 0xFFFFF in physical memory.

  • 0xF0000 to 0xFFFFF:
    This range (64 KB) is where the system BIOS ROM is mapped into the memory address space. Although it's not physically in RAM, the system can access it as if it were, allowing the CPU to execute the code stored in this region during the initial boot phase.
Shadowing BIOS into RAM

In some systems, particularly older systems, there was a technique known as BIOS shadowing:

  1. To improve performance, the contents of the BIOS ROM are copied into RAM during the system's initialization.
    • This makes access to the BIOS code faster because reading from RAM is significantly quicker than from ROM.
    • In this case, the BIOS is copied to a specific region of RAM, but from the CPU’s perspective, it still appears to reside in the 0xF0000 to 0xFFFFF address range.

Conventional Memory && Non-Conventional Memory:

Conventional Memory:

  • First 640 KB of memory (0x00000 - 0x9FFFF).
  • Directly accessible in real mode.
  • Used by older operating systems (like DOS) and early PCs for applications.

Definition: Conventional memory refers to the first 640 KB of memory in a computer system, specifically the address range from 0x00000 to 0x9FFFF.

  • Purpose: This portion of memory is used by DOS, early operating systems, and applications that run in real mode. It is the main memory area accessible by the CPU when in real mode.
  • Usage: This 640 KB is used for running programs, drivers, and the operating system. Before the advent of more advanced memory management techniques, this was the only area accessible for code and data storage, which led to significant limitations in early personal computers.
  • Reason for Limitation: The 640 KB limit is a remnant of early IBM PC architecture, where the remaining memory space in the first megabyte was reserved for system use, including video memory and device BIOS ROMs. Early software and operating systems were designed with this constraint in mind.

Non-Conventional Memory:

  • Includes memory above 640 KB.
  • Upper Memory Area (UMA) is between 640 KB and 1 MB, used for system components (video memory, BIOS, etc.).
  • Extended Memory is above 1 MB and is used by modern operating systems in protected mode.

Definition: Non-conventional memory refers to memory regions that fall outside the first 640 KB of addressable space. On x86 systems, this includes:

  1. Upper Memory Area (UMA): The range from 0xA0000 to 0xFFFFF (above 640 KB to 1 MB). This area is reserved for hardware devices and system BIOS. It’s broken into smaller regions:
    • Video memory (0xA0000 to 0xBFFFF) for graphics.
    • Option ROMs (0xC0000 to 0xDFFFF) for peripheral device firmware (e.g., video BIOS, network card ROM).
    • System BIOS (0xF0000 to 0xFFFFF), where the BIOS firmware is stored and executed during startup.
  2. Extended Memory: Memory above the 1 MB boundary. Extended memory was introduced with later 286+ CPUs in protected mode or 32-bit operating systems. This memory is used by modern OSes and applications but requires switching from real mode to protected mode or 32-bit addressing.
    • Use: Extended memory is where modern operating systems and applications run, allowing access to much larger amounts of memory (e.g., 4 GB and beyond with 32-bit or 64-bit systems).
  3. Expanded Memory (EMS): A technique used in the 1980s and early 1990s to work around the 640 KB limit. EMS allowed programs in real mode to access more memory by using a paging system to swap sections of memory into and out of a 64 KB page frame within the conventional memory space.