Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

V.E.L.O.C.I.T.Y.-OS: Writing Bare-Metal Drivers – PCI, NVMe & FAT32 (Part 9)

Description and use

The author built PCI, NVMe, and FAT32 drivers in Rust for a bare‑metal OS, enabling disk I/O and program execution from NVMe storage.

Problem

In a bare‑metal kernel running in Ring 0, the author had no drivers to access hardware, preventing any disk I/O or file loading.

Outcome

The author successfully added low‑level drivers that allow a bare‑metal Rust kernel to discover PCI devices, communicate with an NVMe SSD, and parse a FAT32 filesystem, enabling file listing and program execution directly from disk.

Workflow

  • 1. Write PCI scanner using legacy I/O ports 0xCF8/0xCFC to enumerate buses, slots, functions and capture BAR0 addresses.
  • 2. Use PCI scanner to locate NVMe controller (class 0x01, subclass 0x08) and map its MMIO base from BAR0.
  • 3. Allocate Admin Submission and Completion queues, configure doorbell stride, map I/O queues, and implement ring doorbells for read/write commands.
  • 4. Implement NVMe read_blocks function that submits commands, handles PRP mapping, and polls completion queue with clflush and spin loops.
  • 5. Write a no_std FAT32 parser that reads raw bytes from NVMe blocks, decodes 8.3 filenames, and loads files cluster‑by‑cluster.
  • 6. Resolve deadlocks in serial logger by bypassing recursive locks and adjust JIT assembler calling conventions for UEFI target.
  • 7. Test by booting QEMU with a 64 MB NVMe image, listing files and executing a program from disk.
  • 8. Integrate FAT32 driver with JIT VM to enable demand‑paging of code from NVMe as cold context.

Evidence

I wrote a PCI scanner. The scanner recursively queries buses 0..255, slots 0..31, and functions 0..7 using CPU legacy I/O ports 0xCF8 (Address) and 0xCFC (Data).

Source

Using the PCI scanner, the kernel locates the mass storage controller (Class 0x01, Subclass 0x08). From BAR0, I retrieve the base pointer to the memory‑mapped I/O (MMIO) registers.

Source

I wrote a custom, #![no_std] FAT32 driver. Because alignment‑safe access is critical on bare‑metal hardware, the parser uses direct offset‑based byte reads.

Source

  • Record date: 2026-09-05T14:18:26.976Z