Driver System

Hardware detection and device drivers

Driver Architecture

guideXOS drivers are compiled directly into the kernel image. All drivers initialize during boot and communicate directly with hardware through port I/O and memory-mapped I/O (MMIO).

Key Characteristics

  • Statically Linked - All drivers compiled into kernel binary
  • Direct Hardware Access - No HAL or abstraction layers
  • Interrupt-Driven - Hardware events via IDT handlers
  • DMA Capable - Direct Memory Access for network and storage
  • Bare-Metal - Written in unsafe C# with pointer access
💡 Note:

Drivers cannot be loaded at runtime. To add hardware support, you must recompile the kernel with the new driver code and rebuild the ISO.


PCI Device Discovery

The PCI subsystem enumerates all devices on the PCI bus during initialization:

PCI Scan Process

PCI.Initialize()
    ↓
Scan Bus 0-255
    ↓ For each device:
    ├─ Read Vendor ID / Device ID
    ├─ Read Class Code / Subclass
    ├─ Read BAR (Base Address Registers)
    ├─ Enable Bus Mastering
    └─ Call device-specific Init()
        ├─ IDE Controller → IDE.Initialize()
        ├─ Network Card → Intel825xx.Initialize()
        ├─ USB Controller → (future support)
        └─ ...

PCI Configuration Space

Drivers use port I/O (0xCF8 / 0xCFC) to read/write PCI configuration registers:

// Read PCI config register
uint ReadConfig(byte bus, byte device, byte function, byte offset)
{
    uint address = 0x80000000 | (bus << 16) | (device << 11) 
                   | (function << 8) | (offset & 0xFC);
    Native.Out32(0xCF8, address);
    return Native.In32(0xCFC);
}

Detected Devices

Use the pci command in Console to view all detected PCI devices:

gx> pci
Bus:Dev.Fn  Vendor:Device  Class      Name
00:00.0     8086:1237      0600       Intel 440FX Chipset
00:01.0     8086:7000      0601       Intel PIIX3 ISA Bridge
00:01.1     8086:7010      0101       Intel PIIX3 IDE Controller
00:02.0     10EC:8139      0200       Realtek RTL8139 Fast Ethernet
00:03.0     1234:1111      0300       QEMU VGA

Storage Drivers

IDE/SATA Controller

guideXOS includes a legacy IDE driver for disk and CD-ROM access:

  • PIO Mode - Programmed I/O transfer
  • Primary/Secondary Channels - Master/Slave devices
  • ATAPI Support - CD/DVD drives
  • LBA Addressing - Supports large disks

Supported Operations

IDE.ReadSector(drive, lba, buffer)    // Read 512-byte sector
IDE.WriteSector(drive, lba, buffer)   // Write 512-byte sector
IDE.Identify(drive)                    // Get drive info
IDE.EjectCD(drive)                     // Eject CD tray

Port Layout

Port Register Function
0x1F0 Data Read/Write data
0x1F1 Error/Features Error status
0x1F2 Sector Count Number of sectors
0x1F3-5 LBA Low/Mid/High Logical address
0x1F6 Drive Select Master/Slave
0x1F7 Status/Command Device status

Network Drivers

guideXOS supports two families of network cards:

Intel 825xx Series

  • Supported Cards: Intel PRO/1000 (82540EM, 82545EM, 82574L)
  • DMA Engine: Descriptor ring buffers for TX/RX
  • Interrupt Handling: Auto-clears on status read
  • Link Detection: Automatic negotiation
// Intel 825xx TX/RX flow
Intel825xx.Send(packet[])
    ↓
Copy to TX descriptor ring
    ↓
Notify hardware (tail pointer)
    ↓
Hardware sends via DMA
    ↓
IRQ on completion

Realtek RTL8139/RTL8111

  • Supported Cards: RTL8139 (older), RTL8111 (newer)
  • Circular Buffers: 8KB RX buffer, 2KB TX buffer
  • Low Resource Usage: Simple, reliable driver
  • Wide Compatibility: Found in many VMs
// RTL8111 Packet Receive
Hardware writes to RX buffer
    ↓
Generate interrupt
    ↓
RTL8111.OnInterrupt()
    ↓
Copy packet from buffer
    ↓
Pass to IPv4 stack

MAC Address

Each driver reads the hardware MAC address from EEPROM or ROM registers. View your MAC with ipconfig.


Input Devices

PS/2 Keyboard

Standard PS/2 keyboard driver with scancode translation:

  • Port: 0x60 (data), 0x64 (command)
  • IRQ: IRQ1 (interrupt vector 0x21)
  • Scancode Set: Set 1 (XT scancodes)
  • Modifiers: Shift, Ctrl, Alt tracking
Keyboard.OnInterrupt()
    ↓
Read scancode from port 0x60
    ↓
Translate to ASCII/keycode
    ↓
Add to keyboard buffer
    ↓
GUI reads via Keyboard.GetKey()

PS/2 Mouse

PS/2 mouse with 3-byte packet protocol:

  • Port: 0x60/0x64 (shared with keyboard)
  • IRQ: IRQ12 (interrupt vector 0x2C)
  • Protocol: 3-byte packets (buttons, X delta, Y delta)
  • Wheel Support: Extended 4-byte packets

Graphics Drivers

VESA Framebuffer

guideXOS uses VESA BIOS Extensions for graphics:

  • Resolution: 1024x768x32 (RGBA8888)
  • Framebuffer: Memory-mapped linear buffer
  • Double Buffering: Back buffer → front buffer copy
  • Software Rendering: All drawing in C#
// Pixel drawing
void SetPixel(int x, int y, uint color)
{
    uint* fb = (uint*)framebufferAddress;
    fb[y * width + x] = color;
}

VGA Text Mode

VGA text mode (80x25) used during early boot:

  • Buffer: 0xB8000 (memory-mapped)
  • Format: 2 bytes per character (ASCII + attribute)
  • Colors: 16 foreground, 8 background
💡 Tip:

To add support for new hardware, study existing drivers in the source code. Most drivers follow the same pattern: PCI init → MMIO mapping → interrupt setup → DMA.


Related Topics