Overview

The FreeWorld OS boot parameter system provides comprehensive command-line parsing, boot flag handling, and parameter extraction. This enables full control over kernel boot behavior and configuration.

✅ Fully Implemented

Key Features: UTF-16 to ASCII conversion, command-line tokenization, boot flag parsing, parameter extraction, memory size parsing

Components

1. Boot Parameter Initialization

Location: kernel/boot/boot_params.asm

Complete boot parameter parsing and management:

  • Structure Validation: Magic number verification
  • Command-Line Extraction: From boot parameters structure
  • UTF-16 Conversion: Automatic UTF-16 to ASCII conversion
  • Argument Tokenization: Space and tab-separated arguments
  • Flag Parsing: Boot flag detection and setting
  • Parameter Extraction: Key-value parameter parsing
  • Parameter Storage: All parameters stored for access

2. Boot Flags

Supported boot flags:

  • quiet - Quiet boot (minimal output)
  • debug - Debug mode (verbose debugging)
  • verbose - Verbose output
  • single / s - Single user mode
  • nosmp - Disable SMP (single CPU)
  • nomodeset - Disable mode setting
  • acpi=off / noacpi - Disable ACPI
  • nohpet - Disable HPET
  • nopci - Disable PCI

3. Boot Parameters

Supported parameters:

  • root=<device> - Root filesystem device (e.g., /dev/sda2)
  • initrd=<path> - Initrd path
  • vga=<mode> - VGA mode (e.g., vga=791)
  • console=<device> - Console device (e.g., console=ttyS0)
  • loglevel=<n> - Log level (0-7, default 7)
  • maxcpus=<n> - Maximum CPUs to use (0 = all)
  • mem=<size> - Memory limit with unit (e.g., mem=512M, mem=2G)

Boot Parameter Flow

UEFI Bootloader
    ↓
Read BootParameters EFI variable
    ↓
Pass to kernel via boot_params_t
    ↓
Kernel Entry (kernel_entry_uefi)
    ↓
Extract command_line from boot_params
    ↓
Boot Parameter Initialization
    ↓
1. Validate boot parameters
    - Check magic number ("FWOS")
    - Verify structure
    ↓
2. Parse Command Line
    - Convert UTF-16 to ASCII
    - Tokenize arguments (space/tab)
    - Store arguments (up to 64)
    ↓
3. Parse Arguments
    - Check for flags
    - Extract parameters (key=value)
    - Set boot flags
    ↓
4. Store Parameters
    - Root device
    - Initrd path
    - VGA mode
    - Console
    - Log level
    - Max CPUs
    - Memory limit
    ↓
Boot Parameters Ready

API Functions

Initialization

; Initialize boot parameters
boot_params_init:
    ; Input: RDI = boot parameters pointer
    ; Returns: RAX = 0 on success, non-zero on error

Flag Access

; Get boot flags
boot_params_get_flags:
    ; Returns: EAX = boot flags

; Check boot flag
boot_params_check_flag:
    ; Input: EAX = flag to check
    ; Returns: AL = 1 if set, 0 if not

Parameter Access

; Get root device
boot_params_get_root:
    ; Returns: RAX = pointer to root device string

; Get initrd path
boot_params_get_initrd:
    ; Returns: RAX = pointer to initrd path string

; Get VGA mode
boot_params_get_vga:
    ; Returns: RAX = pointer to VGA mode string

; Get console
boot_params_get_console:
    ; Returns: RAX = pointer to console string

; Get log level
boot_params_get_loglevel:
    ; Returns: AL = log level (0-7)

; Get max CPUs
boot_params_get_maxcpus:
    ; Returns: EAX = max CPUs (0 = all)

; Get memory limit
boot_params_get_mem_limit:
    ; Returns: RAX = memory limit in bytes (0 = no limit)

Argument Access

; Get argument count
boot_params_get_arg_count:
    ; Returns: EAX = argument count

; Get argument
boot_params_get_arg:
    ; Input: EAX = argument index
    ; Returns: RAX = pointer to argument string or 0

Supported Boot Options

Boot Flags

Flag Description Boot Flag Constant
quiet Quiet boot (minimal output) BOOT_FLAG_QUIET
debug Debug mode BOOT_FLAG_DEBUG
verbose Verbose output BOOT_FLAG_VERBOSE
single / s Single user mode BOOT_FLAG_SINGLE_USER
nosmp Disable SMP BOOT_FLAG_NOSMP
nomodeset Disable mode setting BOOT_FLAG_NOMODESET
acpi=off / noacpi Disable ACPI BOOT_FLAG_ACPI_OFF
nohpet Disable HPET BOOT_FLAG_NOHPET
nopci Disable PCI BOOT_FLAG_NOPCI

Boot Parameters

Parameter Format Example Description
root= <device> root=/dev/sda2 Root filesystem device
initrd= <path> initrd=/boot/initrd.img Initrd path
vga= <mode> vga=791 VGA mode
console= <device> console=ttyS0 Console device
loglevel= <0-7> loglevel=4 Log level
maxcpus= <n> maxcpus=4 Maximum CPUs
mem= <size>[K|M|G|T] mem=512M Memory limit

Usage Examples

Setting Boot Parameters

From EFI shell or boot manager:

efi-setvar BootParameters \
    -guid {8BE4DF61-93CA-11D2-AA0D-00E09802402A} \
    -s "root=/dev/sda2 quiet loglevel=4 maxcpus=4 mem=2G"

Accessing Boot Parameters in Kernel

; Initialize boot parameters
extern boot_params_init
extern uefi_boot_params
mov rdi, [uefi_boot_params]
call boot_params_init

; Check if quiet mode
extern boot_params_check_flag
mov eax, 0x0010  ; BOOT_FLAG_QUIET
call boot_params_check_flag
test al, al
jnz .quiet_mode

; Get root device
extern boot_params_get_root
call boot_params_get_root
; RAX = pointer to root device string

; Get log level
extern boot_params_get_loglevel
call boot_params_get_loglevel
; AL = log level

; Get memory limit
extern boot_params_get_mem_limit
call boot_params_get_mem_limit
; RAX = memory limit in bytes (0 = no limit)

Integration Points

With UEFI Boot

  • Boot parameters passed from UEFI bootloader
  • Command line from EFI variables
  • Boot parameter structure validation

With Kernel Initialization

  • Boot parameters initialized early (Phase 2.5)
  • Flags affect kernel behavior
  • Parameters used for configuration

With ACPI

  • ACPI can be disabled via acpi=off or noacpi
  • Boot parameter checked before ACPI init

With Driver System

  • Root device used for filesystem mounting
  • Console parameter used for console setup
  • VGA mode used for display initialization

File Structure

kernel/boot/
├── boot_params.asm    # Boot parameter parsing (~800 lines)
└── Makefile          # Build system

Future Enhancements

  • Additional Parameters: resume=, panic=, apic=, noapic
  • Parameter Validation: Range checking, device path validation, mode validation
  • Boot Profiles: Predefined boot profiles, profile selection, custom profile support
  • Runtime Modification: Boot parameter modification at runtime, dynamic flag setting

Related Documentation