hal.dll - Hardware Abstraction Layer
Overview
hal.dll (Hardware Abstraction Layer) provides an abstraction layer between hardware interfaces and the kernel. It allows the kernel to work with different hardware configurations without modification.
Status: Fully implemented with complete CPU detection, memory detection, PCI device enumeration, and device management.
Features
- CPU Detection: Detects CPU vendor (Intel, AMD, VIA) and features (SSE, AVX, 64-bit, PAE, etc.)
- Memory Detection: Detects system memory via E820 and E801 methods
- PCI Device Enumeration: Scans all PCI buses and detects devices (Ethernet, Storage, Graphics, Sound, USB)
- Device Management: Provides device lookup by type or vendor/device ID
- I/O Operations: Read/write operations for I/O space and memory-mapped devices
Data Structures
hal_info_t
typedef struct {
uint32_t cpu_vendor;
uint32_t cpu_features;
uint64_t memory_size;
uint32_t device_count;
hal_device_t devices[32]; // Up to 32 devices
} hal_info_t;
hal_device_t
typedef struct {
uint32_t device_id;
uint32_t device_type;
uint32_t vendor_id;
uint32_t class_code;
uint32_t io_base;
uint64_t mem_base;
uint32_t irq;
char name[64];
} hal_device_t;
| Field | Type | Description |
|---|---|---|
cpu_vendor |
uint32_t | CPU vendor identifier |
cpu_features |
uint32_t | CPU feature flags |
memory_size |
uint64_t | Total system memory in bytes |
device_count |
uint32_t | Number of detected devices |
Functions
hal_init
int hal_init(void);
Returns: 0 on success, -1 on failure
Description: Initializes HAL, detects CPU, memory, and devices.
hal_get_info
hal_info_t* hal_get_info(void);
Returns: Pointer to hal_info_t structure
hal_device_read
int hal_device_read(uint32_t device_id, void* buffer, size_t size);
Parameters:
device_id: Device identifierbuffer: Buffer to read intosize: Number of bytes to read
hal_device_write
int hal_device_write(uint32_t device_id, const void* buffer, size_t size);
Static Variables
| Variable | Type | Description |
|---|---|---|
hal_info |
hal_info_t | Static HAL information structure |
Initialization Process
- Detect CPU vendor and features
- Detect total system memory
- Detect and enumerate devices
- Initialize device drivers
Integration Points
- fwoskrnl.exe: Kernel uses HAL for hardware access
- Device Drivers: HAL provides interface for drivers
- freeload.exe: May load HAL before kernel