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

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

说明与用途

作者在 Rust 中为裸机操作系统编写了 PCI、NVMe 和 FAT32 驱动,支持从 NVMe 存储读取文件并执行程序。

问题

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.

结果

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.

工作流

  • 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.

证据

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).

来源

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.

来源

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.

来源

  • 记录日期: 2026-09-05T14:18:26.976Z