Early Hardware Detection
Overview
The FreeWorld OS early hardware detection system uses UEFI-provided information for modern hardware discovery. In UEFI boot, most hardware information comes from UEFI (memory map, ACPI, GOP framebuffer), eliminating the need for legacy detection methods.
✅ Fully Implemented (UEFI-Aware)
UEFI Migration Complete (2025): Hardware detection now primarily uses UEFI-provided information. Legacy detection methods (E820, memory searching) are deprecated.
Key Features: UEFI memory map, ACPI RSDP from UEFI System Table, GOP framebuffer, PCI enumeration, APIC from ACPI MADT, HPET from ACPI
Detection Components
1. CPU Detection
- Vendor String: Intel, AMD, or other vendor
- Brand String: Full processor name
- Feature Flags: CPUID leaf 1 (MMX, SSE, AVX, etc.)
- Extended Features: CPUID leaf 7 (additional features)
- Cache Information: L1, L2, L3 cache sizes
- CPU Count: Number of logical processors
- Per-Core Info: Structure for per-core information
2. Memory Detection (UEFI-Aware)
- UEFI Memory Map: Primary method - EFI memory map from bootloader (replaces E820)
- Memory Types: Available, reserved, ACPI reclaimable, MMIO, etc.
- Memory Totals: Total, available, and reserved memory
- Memory Map: Array of EFI memory descriptors
- ⚠️ E820 Support: Deprecated - Legacy BIOS method, no longer used in UEFI boot
Implementation:
kernel/memory/frame_allocator_uefi.asm uses UEFI memory map for physical memory management.
3. ACPI Detection (UEFI-Aware)
- RSDP from UEFI: Primary method - RSDP from UEFI System Table Configuration Table
- No Memory Searching: RSDP is provided by UEFI (no EBDA/BIOS ROM search needed)
- Version Detection: ACPI 1.0 or 2.0
- ⚠️ RSDP Search: Deprecated - Legacy memory search method, no longer used
- Checksum Validation: RSDP checksum verification
- Table Location: RSDP address stored
4. PCI Enumeration
- Full Scan: All buses (0-255), devices (0-31), functions (0-7)
- Vendor/Device ID: Device identification
- Class Codes: Device classification
- Subclass: Device subclass
- Programming Interface: Device-specific interface
- Header Type: PCI header type
- Base Address Registers: BAR0, BAR1 for I/O and memory
- Device Count: Total PCI devices found
5. APIC Detection
- Local APIC: CPUID feature flags check
- APIC Base: MSR IA32_APIC_BASE read
- APIC Enable: Enable bit check
- IOAPIC: Detection via ACPI MADT (structure ready)
6. Storage Detection
- ATA: Primary (0x1F0) and secondary (0x170) ports
- SATA: Via PCI enumeration (class 0x01, subclass 0x06)
- NVMe: Via PCI enumeration (class 0x01, subclass 0x08)
- Device Types: Type classification
- Port Tracking: I/O port or PCI bus/device
7. Display Detection
- VGA: Standard x86 VGA (always present)
- VESA/VBE: BIOS extensions (INT 0x10, AX=0x4F00)
- GPU: Via PCI enumeration (class 0x03)
- Vendor/Device ID: GPU identification
- Framebuffer: Framebuffer address detection
8. Network Detection
- Ethernet: Via PCI (class 0x02, subclass 0x00)
- WiFi: Via PCI (class 0x02, subclass 0x80)
- Vendor/Device ID: Network adapter identification
- PCI Location: Bus/device/function tracking
9. Audio Detection
- AC97: Via PCI (class 0x04, subclass 0x01, prog_if 0x00)
- HDA: Via PCI (class 0x04, subclass 0x01, prog_if 0x01)
- USB Audio: Via USB enumeration (structure ready)
- Codec ID: Audio codec identification
10. Input Detection
- PS/2 Keyboard: Always present on x86
- PS/2 Mouse: Detection via PS/2 controller
- USB Input: Via USB enumeration (structure ready)
- Interface Type: PS/2, USB, I2C classification
11. USB Detection
- USB Controllers: Via PCI enumeration
- Class Code: 0x0C (Serial Bus Controller)
- Subclass: 0x03 (USB)
- Controller Count: Number of USB controllers
12. NUMA Detection
- SRAT Parsing: Structure ready for SRAT parsing
- Node Count: NUMA node detection
- ACPI-Based: Uses ACPI SRAT table
Data Structures
Early Hardware Info Structure
struc EARLY_HARDWARE_INFO
.cpu_count: resb 1
.cpu_vendor: resb 13
.cpu_brand: resb 48
.cpu_features: resq 1
.cpu_extended_features: resq 1
.cpu_cache_info: resq 1
.memory_total: resq 1
.memory_available: resq 1
.memory_reserved: resq 1
.acpi_present: resb 1
.acpi_version: resb 1
.acpi_rsdp: resq 1
.pci_present: resb 1
.pci_device_count: resd 1
.apic_present: resb 1
.apic_base: resq 1
.ioapic_present: resb 1
.ioapic_base: resq 1
.numa_nodes: resb 1
.storage_count: resb 1
.display_count: resb 1
.network_count: resb 1
.audio_count: resb 1
.usb_count: resb 1
.input_count: resb 1
endstruc
PCI Device Structure
struc PCI_DEVICE
.bus: resb 1
.device: resb 1
.function: resb 1
.vendor_id: resw 1
.device_id: resw 1
.class_code: resd 1
.subclass: resb 1
.prog_if: resb 1
.revision: resb 1
.header_type: resb 1
.bar0: resd 1
.bar1: resd 1
.irq: resb 1
endstruc
API Functions
Get Early Hardware Info
get_early_hardware_info:
; Returns: RAX = pointer to early_hardware_info
Get Memory Map
get_memory_map:
; Returns: RAX = pointer to memory_map_entries
; RCX = entry count
Get PCI Devices
get_pci_devices:
; Returns: RAX = pointer to pci_devices
; RCX = device count
Get Storage Devices
get_storage_devices:
; Returns: RAX = pointer to storage_devices
; CL = device count
Get Display Devices
get_display_devices:
; Returns: RAX = pointer to display_devices
; CL = device count
Get Network Devices
get_network_devices:
; Returns: RAX = pointer to network_devices
; CL = device count
Get Audio Devices
get_audio_devices:
; Returns: RAX = pointer to audio_devices
; CL = device count
Get Input Devices
get_input_devices:
; Returns: RAX = pointer to input_devices
; CL = device count
Set UEFI Memory Map
set_uefi_memory_map:
; Input: RDI = memory map pointer
; RSI = memory map size
; RDX = descriptor size
Integration Points
With UEFI Boot
- Receives memory map from UEFI bootloader
- Receives ACPI RSDP from UEFI boot parameters
- Uses EFI memory map for memory detection
With Kernel Initialization
- Called before kernel decompression (Phase 0)
- Provides hardware info for driver loading
- Memory map used for memory management setup
With Driver System
- PCI devices enumerated for driver matching
- Device structures available for driver initialization
- Hardware capabilities known before driver load
Usage Example
; In kernel initialization
extern early_hardware_detect
call early_hardware_detect
; Get hardware information
extern get_early_hardware_info
call get_early_hardware_info
; RAX now points to early_hardware_info structure
; Access CPU count
mov al, [rax + EARLY_HARDWARE_INFO.cpu_count]
; Access memory total
mov rbx, [rax + EARLY_HARDWARE_INFO.memory_total]
; Access PCI device count
mov ecx, [rax + EARLY_HARDWARE_INFO.pci_device_count]
; Get PCI devices
extern get_pci_devices
call get_pci_devices
; RAX = pointer to pci_devices
; RCX = device count
Detection Flow
Early Hardware Detection (before drivers)
↓
1. CPU Detection
- Vendor, brand, features
- Cache information
- CPU count
↓
2. Memory Detection
- E820 (BIOS) or EFI (UEFI)
- Memory map parsing
- Total/available/reserved calculation
↓
3. ACPI Detection
- RSDP search or from UEFI
- Version detection
- Table location
↓
4. PCI Enumeration
- Full bus/device/function scan
- Device classification
- Device structure storage
↓
5. APIC Detection
- Local APIC (MSR)
- IOAPIC (ACPI MADT)
↓
6. Device-Specific Detection
- Storage (ATA, SATA, NVMe)
- Display (VGA, VESA, GPU)
- Network (Ethernet, WiFi)
- Audio (AC97, HDA)
- Input (PS/2, USB)
- USB controllers
↓
7. NUMA Detection
- SRAT parsing
- Node count
↓
Hardware Info Structure Populated
Related Documentation
- UEFI Boot - Memory map and ACPI RSDP passing
- Kernel - Kernel initialization phases
- Device Drivers - Driver matching using hardware info
- Memory Management - Memory map usage