Kernel Initialization
Overview
The FreeWorld OS kernel initialization system provides a complete, ordered initialization sequence that ensures all subsystems are started in the correct dependency order. This includes driver initialization, service startup, filesystem mounting, process manager setup, and IPC system initialization.
UEFI-Aware Initialization Phases
The kernel initialization follows a carefully ordered sequence for UEFI boot:
- Kernel Entry (UEFI) -
kernel_entry_uefi.asmreceives boot parameters, extracts UEFI data (framebuffer, memory map, ACPI RSDP) - Framebuffer Console - Initialize GOP framebuffer console (replaces serial debugging)
- IDT Setup - Initialize Interrupt Descriptor Table for exception handling
- Physical Memory Manager - Initialize UEFI memory map-based frame allocator (replaces E820)
- ACPI Support - Initialize ACPI using RSDP from UEFI System Table (no memory searching)
- Interrupt Controllers - Initialize I/O APIC and Local APIC (replaces legacy PIC)
- Timers - Initialize HPET using ACPI address (replaces legacy PIT)
- Modern Drivers - Initialize USB xHCI, NVMe, AHCI via PCI enumeration
- Virtual Memory - Initialize paging, virtual memory, swap
- Process Scheduling - Initialize unified scheduler
- Kernel Debugging - Initialize KDB and debugging tools
- Kernel Logging - Initialize klog and syslog
- Kernel Modules - Initialize module system
- Power Management - Initialize power management
- Process Manager - Initialize process management
- IPC System - Initialize inter-process communication
- Filesystem Mounting - Mount virtual and root filesystems
- Service Startup - Start system services
- Init Process - Start initial user-space process
Driver Initialization Order
The driver initialization system ensures drivers are initialized in the correct dependency order across 9 phases:
Phase 0: Critical Drivers (UEFI-Aware)
- HPET Timer - High Precision Event Timer (replaces legacy PIT)
- I/O APIC - Modern interrupt controller (replaces legacy PIC)
- Local APIC - Per-CPU interrupt controller
Phase 1: Storage Drivers (Modern)
- NVMe Controllers - PCI enumeration, modern SSD support
- AHCI/SATA Controllers - PCI enumeration, SATA drive support
- SCSI controllers
- CD/DVD drives (ATAPI)
- ⚠️ Legacy ATA PIO - Deprecated, replaced by NVMe/AHCI
Phase 2: Filesystem Drivers
- FAT32, ext2/3/4, NTFS, exFAT, Btrfs, XFS, ZFS
- Virtual filesystems: /proc, /sys, /dev, /tmp, devtmpfs
Phase 3: Network Drivers
- Ethernet drivers (RTL8139, E1000, VirtIO Net)
- WiFi drivers (structure ready)
- Bluetooth drivers (structure ready)
Phase 4: Graphics Drivers (UEFI-Aware)
- GOP Framebuffer - Graphics Output Protocol (replaces VESA/VBE)
- Framebuffer Console - Text output to GOP framebuffer (replaces serial/VGA)
- GPU drivers (Intel, AMD, NVIDIA)
- Display output (DisplayPort, HDMI, DVI)
- Multi-monitor support
- ⚠️ VESA/VBE - Deprecated, replaced by GOP
Phase 5: Audio Drivers
- AC97 driver
- HD Audio (Intel HDA) driver
- USB audio (already initialized in USB phase)
- Audio mixer
Phase 6: Input Drivers (Modern)
- USB xHCI - USB 3.0+ host controllers (primary)
- USB HID Devices - Keyboard, mouse via USB (replaces PS/2)
- Touchpad, touchscreen (structure ready)
- Game controllers (structure ready)
- ⚠️ PS/2 Keyboard/Mouse - Deprecated, replaced by USB xHCI
Phase 7: USB Drivers (UEFI-Aware)
- USB xHCI Controllers - PCI enumeration, modern USB 3.0+ support
- USB HID devices
- USB storage
- USB audio
- ⚠️ Legacy USB Controllers (UHCI, OHCI, EHCI) - Deprecated in favor of xHCI
Phase 8: Other Drivers
- Video acceleration drivers
- Miscellaneous drivers
API Functions
; Complete driver initialization
driver_init_order_complete() -> status
; Individual phase initialization
driver_init_phase_critical() -> status
driver_init_phase_storage() -> status
driver_init_phase_filesystem() -> status
driver_init_phase_network() -> status
driver_init_phase_graphics() -> status
driver_init_phase_audio() -> status
driver_init_phase_input() -> status
driver_init_phase_usb() -> status
driver_init_phase_other() -> status
Service Startup Sequence
The service startup system manages system services in the correct dependency order across 3 phases:
Phase 0: Critical Services
- Service Manager (must be first)
- Syslog service (needed for logging)
- Udev/Devd service (device management)
- D-Bus service (IPC)
Phase 1: System Services
- Logd service (logging daemon)
- Networkd service (network configuration)
- Securityd service (security daemon)
- Cron service (scheduled tasks)
- Resource Manager service
- IPC Manager service
- Registry service (Windows compatibility)
- File System Watcher service
- Error Manager service
Phase 2: Application Services
- GUI Server service
- Display Manager service
- Shell service (desktop shell)
Phase 3: User Services
User services are started after user login by the session manager.
API Functions
; Complete service startup
service_startup_sequence_complete() -> status
; Individual phase startup
service_startup_phase_critical() -> status
service_startup_phase_system() -> status
service_startup_phase_application() -> status
service_startup_phase_user() -> status
Filesystem Mounting Sequence
The filesystem mounting system handles mounting in the correct order:
Phase 0: Virtual Filesystems
Virtual filesystems are mounted first as they don't depend on storage:
/proc- Process and system information/sys- System information and devices/dev- Device nodes/tmp- Temporary filesystemdevtmpfs- Automatic device node creation
Phase 1: Root Filesystem
The root filesystem is mounted with support for:
- Boot parameter specification (
root=/dev/sda1) - UUID-based mounting (
root=UUID=...) - Auto-detection (tries common devices)
- Filesystem type detection (FAT32, ext2/3/4, NTFS, etc.)
- Mount options parsing
- Read-only fallback on errors
Phase 2: Other Filesystems
Other filesystems are mounted from configuration (e.g., /etc/fstab).
API Functions
; Complete filesystem mounting
filesystem_mount_sequence_complete() -> status
; Mount root filesystem
mount_root_filesystem_complete() -> status
; Mount virtual filesystems
mount_virtual_filesystems() -> status
; Get root device info
get_root_device() -> device_path
get_root_fstype() -> filesystem_type
Process Manager Initialization
The process manager initialization sets up all process management subsystems:
Components Initialized
- Process table - Process data structure management
- Thread table - Thread data structure management
- PID allocator - Process ID allocation
- TID allocator - Thread ID allocation
- Process groups - Process group management
- Sessions - Session management
- Signal handling - Signal delivery and handling
- Process credentials - UID, GID, capabilities
- Process limits - Resource limits (RLIMIT_*)
- Process accounting - Process statistics
- Process namespaces - Namespace isolation
- Process monitoring - Process health monitoring
Kernel Process
Creates the kernel process (PID 0) which serves as the root of the process tree.
API Functions
; Initialize process manager
process_manager_init_complete() -> status
; Get init process PID
process_manager_get_init_pid() -> pid
; Check if initialized
process_manager_is_initialized() -> initialized
IPC System Initialization
The IPC system initialization sets up all inter-process communication mechanisms:
Components Initialized
- Shared memory system - Shared memory segments
- Message queues - POSIX message queues
- Semaphores - POSIX semaphores
- Pipes - Anonymous pipes
- FIFOs - Named pipes
- Sockets - Network sockets (if not already done)
- Signals - Signal-based IPC (if not already done)
- D-Bus - D-Bus IPC (if available)
- IPC namespace - IPC namespace isolation
- IPC permissions - Permission management
- IPC monitoring - IPC usage monitoring
API Functions
; Initialize IPC system
ipc_system_init_complete() -> status
; Check if initialized
ipc_system_is_initialized() -> initialized
Error Handling
The initialization system includes comprehensive error handling:
- Critical Failures - Process manager, IPC system, root filesystem mount failures cause system halt
- Non-Critical Failures - Driver, service, and graphics failures are logged but don't halt the system
- Fallback Mechanisms - System continues with available components
- Error Logging - All errors are logged via klog
Build System
Initialization components are built using the Makefile in kernel/init/:
cd kernel/init
make
This produces object files that are linked into the kernel:
kernel_init.o- Main initialization sequencedriver_init_order.o- Driver initialization orderservice_startup_sequence.o- Service startup sequencefilesystem_mount_sequence.o- Filesystem mountingprocess_manager_init.o- Process manager initializationipc_system_init.o- IPC system initialization
Integration
The initialization system integrates with:
- Boot System - Receives boot parameters and hardware info
- ACPI - Uses ACPI device tree for hardware enumeration
- Memory Management - Uses frame allocator for memory allocation
- Process Management - Initializes process management before starting init
- Filesystem - Mounts filesystems before starting services
- Services - Starts services in dependency order
- Logging - Uses klog for initialization logging