-
Notifications
You must be signed in to change notification settings - Fork 0
Hardware Drivers
PhantomOS includes drivers for graphics, USB, networking, storage, and power management, with a hardware abstraction layer for GPU backends.
The GPU Hardware Abstraction Layer provides a unified interface for multiple graphics backends. At boot, all backends register themselves, and the highest-priority available backend is selected.
| Backend | Priority | Source | Description |
|---|---|---|---|
| Intel BLT | 100 | intel_gpu.c |
Intel integrated GPU BLT engine |
| VirtIO GPU | 80 | virtio_gpu.c |
QEMU VirtIO GPU device |
| VMware SVGA | 60 | vmware_svga.c |
VMware SVGA II protocol |
| Bochs VGA | 40 | bochs_vga.c |
Bochs/QEMU VGA extensions |
| Software | 0 | (built-in) | CPU-based fallback |
gpu_hal_fill_rect(x, y, w, h, color); // Hardware-accelerated rectangle fill
gpu_hal_clear(color); // Full screen clear
gpu_hal_copy_region(dx, dy, sx, sy, w, h); // Screen-to-screen copy
gpu_hal_flip(); // Backbuffer to frontbuffer
gpu_hal_sync(); // Drain pending operationsIf the active backend doesn't support an operation, it falls back to software rendering. Statistics track GPU vs. software fallback counts.
- QEMU uses
SVGA_IO_MUL=1: value port at BAR0+1 (not +4) - QEMU doesn't implement
RECT_FILLorRECT_COPYFIFO commands - Uses CPU backbuffer +
SVGA_CMD_UPDATEfor compatibility
Full PCI bus enumeration via I/O ports 0xCF8/0xCFC:
void pci_init(void); // Enumerate all buses/devices/functions
uint32_t pci_read(uint8_t bus, uint8_t dev, uint8_t func, uint8_t offset);
void pci_write(uint8_t bus, uint8_t dev, uint8_t func, uint8_t offset, uint32_t val);Discovers VirtIO devices, USB controllers, GPU devices, and storage controllers.
USB 1.1 Universal Host Controller Interface:
- Discovered via PCI (class 0x0C, subclass 0x03, prog-if 0x00)
- I/O port base from PCI BAR4
- 1024-entry frame list for scheduled transfers
- Transfer Descriptors (TDs) and Queue Heads (QHs) for control/interrupt transfers
Supports boot-protocol keyboard and mouse:
- Device enumeration via USB SET_ADDRESS, GET_DESCRIPTOR
- SET_PROTOCOL to boot mode (simplified 8-byte reports)
- Interrupt IN polling via frame list scheduled TDs
- Keyboard: scancode translation, press/release detection via report diff
- Mouse: relative X/Y movement, button state
void usb_hid_init(void);
void usb_hid_poll(void); // Called from main loop
int usb_hid_device_count(void);VirtIO-net PCI device driver with ARP/ICMP stack:
- Static IP:
10.0.2.15/24 - Gateway:
10.0.2.2(QEMU user-mode networking) - MAC address read from VirtIO config space
- ARP: Responds to ARP requests, sends ARP for gateway resolution
- ICMP: Echo reply (responds to pings) and echo request (sends pings)
int virtio_net_init(void);
int virtio_net_ping(uint32_t dest_ip, uint16_t seq);
int virtio_net_ping_check(void);
void virtio_net_poll(void);
const struct net_stats *virtio_net_get_stats(void);Live desktop window showing: MAC address, IP, link status, TX/RX packet counts, ping results.
PIIX4 PM device support for QEMU i440fx platform:
- Detects PIIX4 PM via PCI (vendor 0x8086, device 0x7113)
- SCI interrupt on IRQ9 for power button events
- Graceful shutdown via S5 sleep state
- System reset via port 0xCF9
int acpi_init(void);
void acpi_request_shutdown(void); // Request graceful shutdown
void acpi_poweroff(void); // Execute S5 power-off
void acpi_reboot(void); // System resetDetects hypervisor via CPUID leaf 0x40000000:
-
KVM: Paravirtualized clock via MSR (
kernel/kvm_clock.c) - QEMU: Dirty-rect tile tracking for efficient screen updates
- VMware: SVGA II driver activation
- General: Timer-based frame limiting to avoid busy-loop rendering
VirtIO serial port for kernel log output when serial port unavailable. Used as debug output channel in VirtIO-enabled VMs.
- IRQ1 handler
- Scancode set 1 translation
- Modifier key tracking (shift, ctrl, alt)
- Key buffer for asynchronous reading
- IRQ12 handler (requires PIC cascade on IRQ2)
- 3-byte packet protocol (buttons, delta-X, delta-Y)
- Cursor position tracking with screen bounds clamping