02. Computer Hardware Review

Processors, Memory Hierarchy, Disks, I/O Devices, Buses, and Booting.

An operating system does not exist in an abstract mathematical vacuum; it is fundamentally shaped and constrained by the physical silicon it commands. At its core, the OS acts as both a resource manager and an extended virtual machine, turning raw hardware into a safe, programmable execution environment. However, software alone cannot enforce memory protection boundaries or wrest control back from an errant program—it requires direct hardware cooperation through privileged CPU execution modes, timer interrupts, Memory Management Units (MMUs), and DMA controllers. Understanding these physical hardware building blocks is the indispensable foundation for studying how operating systems virtualize the CPU and memory, coordinate concurrent threads, and persist data to non-volatile storage.

System Architecture Overview

The diagram below maps out how the core hardware subsystems covered in this module connect—from CPU execution engines and memory hierarchies down to system buses, storage controllers, and boot firmware.

1. PROCESSORS & PIPELINING CPU Core 0 & Core 1 Fetch • Decode • Execute • WB Privilege Levels (Ring 0 / Ring 3) Superscalar & Multicore Execution 3. VIRTUAL MEMORY & MMU CR3 Root & Page Table Walk PML4 → PDPT → PD → PT 2 MiB Superpages & Offset Bypass Physical DRAM Frame Mapping 4. DISKS & I/O CONTROLLERS Device Drivers & MMIO/PMIO Direct Memory Access (DMA) NVMe Storage & Peripherals High-Speed Bus Controllers 5. SYSTEM BUS TOPOLOGY & INTERCONNECTS High-Speed Memory Bus • PCIe Serial Lanes • SPI / LPC Firmware Bus BOOT SEQUENCE & FIRMWARE INITIALIZATION Power-On Reset Vector → UEFI POST → Bootloader Handoff → OS Kernel Entry

1. Processors (CPUs) & Execution Mechanics

The Central Processing Unit (CPU) is the computational brain of the computer, executing instructions fetched from main memory. The CPU follows the classical fetch-decode-execute cycle:

Interactive Walkthrough: Instruction Throughput Engine

Step through sequential vector operations across standard pipelined, superscalar, and multicore execution.

Architecture:
The Scenario: Computing a Multiply-Accumulate (MAC) Step

We are computing one single term of a vector dot product: sum = sum + (A × B).

Stage Explanation:
Loading pipeline state...
Clock Cycle
Cycle 1
Execution Phase
Pipeline Fill
Instructions Retired
0 / 4
Throughput (IPC)
0.00 IPC
Hazard Status
None (Clean Fill)
Stage 1: FETCH (IF) I1: LOAD R1, [A] PC = 0x00401000 Stage 2: DECODE (ID) Idle (Bubble) Read Registers Stage 3: EXECUTE (EX) Idle (Bubble) ALU / Address Gen Stage 4: WRITEBACK Idle (Bubble) Update Register File Data Forwarding Bypass PIPELINE TOPOLOGY: SINGLE-CORE Cycle 1: Fetching Instruction I1 into IF Stage. Core 0 active.
Detailed Mechanics: What Is Happening
Behind the Curtain: Why The System Does This
Pioneer Insight: John von Neumann & The Stored-Program Model

Before John von Neumann formalized the stored-program architecture in his 1945 EDVAC report, early computers were programmed manually by plugging patch cables and setting physical switches. Treating code as data inside a shared memory space enabled self-loading operating systems and dynamic linkers, but it also introduced the foundational vulnerability of buffer overflows—where malicious inputs overwrite instruction pointers in memory.

James Goodman & Bus Snooping (1983)

When multi-core processors emerged, private L1/L2 caches created a consistency crisis: if Core 0 updated a variable, how did Core 1 know its cached copy was stale? Goodman solved this by introducing bus snooping, where cache controllers monitor the shared memory bus to automatically invalidate outdated local copies.

2. Privilege Modes & Hardware Protection

To prevent rogue or faulty user software from crashing the operating system or corrupting other programs, CPU hardware enforces distinct privilege execution levels:

Deep Dive: Privilege Hierarchies Across Architectures (Rings, ELs, and Modes)

While the term "Rings" (Ring 0 through Ring 3) is famously associated with x86 architecture, the underlying concept of hierarchical hardware privilege is universal across modern processors:

Processor Architecture User / Application Tier Kernel / Supervisor Tier Virtualization / Firmware Tier
x86-64 (Intel / AMD) Ring 3 (User applications) Ring 0 (OS Kernel) Ring -1 / VMX Root (Hypervisors)
ARM64 (AArch64) EL0 (Apps & OS Daemons) EL1 (OS Kernel / Supervisor) EL2 / EL3 (Hypervisor / Secure Monitor)
RISC-V U-mode (User Mode) S-mode (Supervisor Mode) M-mode (Machine Mode / Firmware)

Regardless of nomenclature, the hardware state machine enforces identical safety guarantees: unprivileged instructions cannot manipulate page tables, modify control registers, or execute raw I/O without trapping through a controlled supervisor gateway.

Historical Footnote: What Happened to Rings 1 and 2?

While Intel's hardware design originally defined 4 rings—with Ring 1 intended for device drivers and Ring 2 for system services—mainstream operating systems like Linux and Windows chose to ignore them, using only Ring 0 (Kernel) and Ring 3 (User). Running drivers in Ring 1 or 2 provided little real-world security protection because a driver bug could still compromise the kernel, and managing four hardware rings added unnecessary architectural complexity.

Pioneer Insight: The Manchester Atlas & The Invention of the Hardware Trap
University of Manchester Atlas Computer, January 1963 Atlas (1962)
Wikimedia Record
Author: Iain MacCallum

The University of Manchester Atlas computer (1962), led by Tom Kilburn and David Edwards, pioneered the concept that entering supervisor mode should not be an ordinary subroutine call. Instead, they invented hardware traps that simultaneously elevated processor privilege and redirected execution to immutable vector locations. Without this hardware gateway, unprivileged code could easily forge supervisor privileges.

John McCarthy & The Non-Negotiable Timer Interrupt

Early time-sharing mainframes relied entirely on cooperative yields. If an errant infinite loop began running, the entire machine locked up. In 1963, John McCarthy championed the integration of a non-negotiable hardware clock interrupt (the PDP-1 channel 17 clock), ensuring the CPU would forcibly trap into the supervisor to reclaim control, making preemptive multitasking possible.

3. Virtual Memory & The Memory Management Unit (MMU)

Modern architectures decouple the addresses generated by programs from the physical addresses wired into silicon using Virtual Memory, managed directly by specialized hardware called the Memory Management Unit (MMU).

Address Translation Mechanics

The hardware MMU takes the Virtual Page Number and indexes into the active process's Page Table to discover the corresponding Physical Frame Number (PFN). The lowest 12 bits of the original address (the offset) pass through completely unmodified, because the byte offset within a virtual page is identical to the byte offset within a physical frame:

VIRTUAL ADDRESS (Generated by CPU Instruction) Virtual Page Number (VPN) Upper Address Bits [47:12] Page Offset (12 bits) Bits [11:0] • Identifies exact byte in 4 KiB page Page Table Lookup Passes through unchanged PHYSICAL ADDRESS (Issued to DRAM Memory Bus) Physical Frame Number (PFN) Base address of 4 KiB frame in physical DRAM Page Offset (12 bits) Bits [11:0] • Unmodified intra-frame byte offset

Understanding Superpages (Huge Pages)

Normally, x86-64 uses a 4-level page table hierarchy to translate standard 4 KiB pages, requiring individual memory lookups across PML4, PDPT, Page Directory, and Page Table. However, modern workloads with massive memory footprints (such as databases and hypervisors) can overwhelm the Translation Lookaside Buffer (TLB) if every 4 KiB chunk requires its own translation entry.

A superpage (or huge page) solves this by allowing the MMU to terminate the page walk early. By asserting a special Page Size (PS) bit in the Page Directory Entry (PDE) at Level 2, the hardware treats the entire 2 MiB region as a single atomic mapping, bypassing lower page tables completely and binding directly to a physical superpage frame.

Standard 4 KiB Paging
Full 4-level walk offers fine-grained memory management but results in high TLB pressure for large allocations.
2 MiB Superpages
Halves the page walk depth, allowing a single TLB entry to cover 512 times more memory and dramatically boosting performance.

Interactive Walkthrough: Synchronized Page Table Walk & Offset Pass-Through

Trace how the MMU steps through multi-level page table entries (PTEs) in DRAM in real time.

Granularity:
The Scenario: Tracing a 4 KiB Virtual-to-Physical Translation

We are tracing how the MMU translates virtual address 0x00403018 into physical DRAM address 0x07B40018 across synchronized page table entries:

Stage Explanation:
Loading translation state...
Virtual Address
0x00403018
Active Table Walk
CR3 Root
Page Offset
0x018 (Bypass)
Physical Frame (PFN)
Pending...
Final Physical Addr
Pending...
Root Register CR3 0x1A4000 PML4 Table Index 0: Unused Index 1: Unused Index 2: 0x2B100 Index 3: Unused Index 4: Unused ... (512 Entries) PDPT Table Index 0: Unused Index 1: Unused Index 2: Unused Index 3: 0x3C200 Index 4: Unused ... (512 Entries) Page Directory Index 0: Unused Index 1: Unused Index 2: Unused Index 3: 0x4D300 Index 4: Unused ... (512 Entries) Page Table (PT) VPN 0x00401: Unused VPN 0x00402: Unused VPN 0x00403: 0x07B40 VPN 0x00404: Unused VPN 0x00405: Unused ... (512 Entries) Page Offset (0x018) Passes Through Completely Unmodified to DRAM TRANSLATION ENGINE STATUS: READY
Detailed Mechanics: What Is Happening
Why The System Does This
Key Definitions & Hardware Terminology
Virtual Address
An address generated by a CPU instruction consisting of a Virtual Page Number (VPN) and a page offset, which must be translated by the MMU before accessing DRAM.
Root Register
The top-level CPU architectural pointer (such as CR3 on x86 or TTBR0 on ARM) anchoring the execution context by storing the physical base address of the active process's top-level translation table.
CR3 Register
The specific x86 root register storing the physical base address of the top-level page table (PML4).
CR4 Register
Extended control register enabling PAE, page size extensions, and virtualization features.
PML4 Table
Top-level 4 KiB table in x86-64 4-level paging (where PML stands for Page Map Level) containing entries pointing to PDPTs.
PDPT
Page Directory Pointer Table (Level 3); contains 512 entries pointing to Page Directories.
PFN (Physical Frame Number)
The upper address bits of a physical memory address identifying a specific 4 KiB page frame in DRAM; combined with the page offset during translation.
PTE (Page Table Entry)
Leaf entry containing the physical frame number (PFN) and protection flags.
Systems Engineering: Lampson's Laws & Ousterhout's Law
Butler Lampson, Royal Society Butler Lampson
Wikimedia Record
Author: Wikimedia Commons

Turing Award winner Butler Lampson emphasized a core rule of operating system design: separation of policy from mechanism. The hardware provides mechanisms (like MMU page walks or timer traps), while the OS establishes policies (like scheduling algorithms or eviction rules). Mixing them leads to brittle architectures.

John Ousterhout & The Memory Latency Wall

In his landmark 1990 paper, John Ousterhout observed that while CPU clock speeds were scaling exponentially, memory and storage bus latency lagged severely behind. This reality explains why hardware architectural breakthroughs like Translation Lookaside Buffers (TLBs), DMA controllers, and superpages are vital to preventing CPU starvation.

4. Disks, I/O Devices, & Controller Hardware

Input/output (I/O) hardware bridges the CPU and memory with the outside digital and physical world. Because physical devices (keyboards, network interfaces, NVMe drives, and displays) operate at speeds orders of magnitude slower than CPU registers and DRAM buses, computer architectures utilize a specialized hierarchy of hardware controllers and communication pathways.

The Component Hierarchy

THE I/O HARDWARE & SOFTWARE COMPONENT HIERARCHY From User-Space System Calls down to Silicon Controller Registers and Physical Media USER SPACE (RING 3) User Application / Standard C Library (POSIX I/O) Issues high-level calls: read(), write(), ioctl() via file descriptors System Call Trap (syscall / sysenter) KERNEL SPACE (RING 0 / SUPERVISOR) Generic I/O Subsystem (VFS & Block Layer) Uniform naming, file permissions, page cache, I/O request queueing, and elevator scheduling Device Driver (e.g., nvme.ko, e1000e.sys) Translates OS requests into controller commands; Services Interrupt Service Routines (ISRs) Programmed I/O (MMIO / PMIO) Hardware Interrupt Line (IRQ) DEVICE CONTROLLER / ADAPTER (SILICON IC) Controller Internal Registers & Data Buffers Command Reg Status Reg Data In/Out On-chip FIFO Direct Memory Access (DMA) Bypasses CPU to stream data directly to/from Physical DRAM Bus Proprietary Physical Bus Signaling (PCIe PHY, NVMe, SATA, USB) PHYSICAL HARDWARE DEVICE (ELECTROMECHANICAL / PHY) NVMe NAND Flash Cells Magnetic HDD Platters Ethernet PHY & RJ45 Port Display OLED/LCD Matrix

How I/O Communication Works

The CPU communicates with device controllers using two primary hardware mechanisms:

  1. Port-Mapped I/O (PMIO): The CPU uses dedicated, isolated hardware instructions (such as in and out on x86) interacting with a separate address space specifically reserved for I/O ports.
  2. Memory-Mapped I/O (MMIO): The controller's control and data registers are mapped directly into the system's physical address space. When the CPU writes to a specific MMIO physical address, the memory bus routes the write directly to the hardware controller's internal registers instead of DRAM.

Direct Memory Access (DMA)

To prevent the CPU from wasting valuable cycles moving large blocks of data byte-by-byte between an I/O device and DRAM, systems employ a Direct Memory Access (DMA) controller:

5. Buses & The Boot Process

Modern computers rely on a high-speed hierarchy of communication pathways known as buses to transport data, addresses, and control signals between the CPU, memory, and peripheral controllers. Following power-on, a carefully choreographed boot sequence transitions the bare silicon into a fully operational operating system.

System Bus Architecture & The PCIe Hierarchy

System bus topology has evolved from shared parallel buses (like the old PCI bus) to high-speed point-to-point serial packet interconnects:

The Boot Process: From Power-On to Operating System Handoff

When a computer is powered on, the CPU has no operating system loaded, RAM is uninitialized, and registers contain undefined values. The system initializes through distinct sequential stages:

  1. Power-On Reset & The Reset Vector: The motherboard chipset asserts a reset signal. Upon deassertion, the CPU forces its Program Counter (PC) to a hardwired architectural address known as the Reset Vector (e.g., 0xFFFFFFF0 in legacy x86 or mapped ROM addresses in modern UEFI). At this exact location sits the CPU's first instruction: a jump to the motherboard flash ROM.
  2. Firmware Initialization (UEFI / BIOS): The CPU executes the Extensible Firmware Interface (UEFI) stored in non-volatile flash memory. The firmware performs the Power-On Self-Test (POST), initializes memory controllers, trains DRAM timing parameters, and discovers attached hardware devices.
  3. Device Discovery & Boot Selection: The UEFI firmware scans storage volumes for a valid EFI System Partition (ESP) containing signed bootloader binaries (e.g., EFI/BOOT/BOOTX64.EFI) according to stored NVRAM boot variables.
  4. The Bootloader Handoff: The primary bootloader (such as GRUB or the Windows Boot Manager) loads the operating system kernel image and initial RAM disk (initrd/initramfs) into physical RAM.
  5. Entering Protected / Long Mode & Kernel Entry: The bootloader transitions the CPU from 16-bit real mode into 64-bit Long Mode, enables paging and the MMU by loading the root register (CR3), and jumps directly into the kernel's entry point (`kernel_main`). The OS initializes driver subsystems, spawns the first user-space process (init or systemd), and presents the user login environment.