This skill should be used when analyzing the Breenix kernel boot sequence, verifying initialization order, timing boot stages, identifying boot failures, optimizing boot time, or understanding the boot process from bootloader handoff to kernel ready state.
Analyze and optimize the kernel boot process from bootloader to kernel ready.
Understanding the boot sequence is critical for debugging initialization issues, optimizing boot time, and ensuring proper subsystem ordering. This skill provides tools for analyzing boot logs, verifying checkpoint progression, and identifying boot failures.
What happens:
Entry point: kernel/src/main.rs kernel_main()
Initial state:
// CPU in Long Mode (64-bit)
// Interrupts disabled
// Paging enabled (bootloader setup)
// Stack ready
// Physical memory mapped at offset
Typical log output:
[Bootloader messages]
Loading kernel...
Jumping to kernel entry point...
Subsystems initialized (in order):
1. Logger
[ INFO] Breenix OS starting...
2. GDT (Global Descriptor Table)
[ INFO] GDT initialized
3. IDT (Interrupt Descriptor Table)
[ INFO] IDT initialized
4. PIC (Programmable Interrupt Controller)
[ INFO] PIC initialized
5. Frame Allocator
[ INFO] Physical memory: 94 MiB usable
[DEBUG] Frame allocator initialized
6. Heap Allocator
[ INFO] Heap: 1024 KiB
7. Virtual Memory
[DEBUG] Page table initialized
8. Kernel Stacks
[DEBUG] Kernel stack allocator initialized
9. Timer (PIT)
[ INFO] Timer initialized at 100 Hz
10. RTC (Real-Time Clock)
[ INFO] RTC initialized: 2025-10-23 12:34:56 UTC
11. Serial Input
[ INFO] Serial input interrupts enabled
12. Keyboard
[ INFO] Keyboard initialized
13. Interrupts Enabled
[ INFO] Enabling interrupts...
14. System Calls
[ INFO] System call infrastructure initialized
15. Threading
[ INFO] Threading subsystem initialized
16. Process Management
[ INFO] Process management initialized
17. POST (Power-On Self Test)
[ INFO] Running POST tests...
=== Memory Test ===
✅ MEMORY TEST COMPLETE
...
🎯 KERNEL_POST_TESTS_COMPLETE 🎯
18. Userspace Tests (if configured)
RING3_SMOKE: creating hello_time userspace process
[ INFO] Process created: PID 1
USERSPACE OUTPUT: Hello from userspace!
Final state:
[ INFO] Kernel initialization complete
[ INFO] System ready
Using log-analysis skill:
# Get all initialization messages in order
grep "initialized\|INITIALIZED\|Initializing" logs/breenix_20251023_*.log
# Or more comprehensive
grep -E "INFO|WARN|ERROR" logs/latest.log | less
Expected sequence:
Identify last successful checkpoint:
# Find last "initialized" message
grep "initialized" logs/breenix_*.log | tail -10
# Or find last successful operation
grep "SUCCESS\|✅\|complete" logs/breenix_*.log | tail -10
If boot hangs:
Working vs broken boot:
# Extract initialization sequence
grep "initialized\|Initializing" working.log > working_boot.txt
grep "initialized\|Initializing" broken.log > broken_boot.txt
# Compare
diff -u working_boot.txt broken_boot.txt
Look for:
Add timing checkpoints:
let start = kernel::time::get_monotonic_ms();
// Initialize subsystem
gdt::init();
let elapsed = kernel::time::get_monotonic_ms() - start;
log::info!("GDT initialization took {}ms", elapsed);
Analyze timing:
Check initialization order:
// Memory must be initialized before heap
assert!(frame_allocator.is_initialized());
heap::init(); // Safe now
// GDT must be before IDT
gdt::init();
idt::init(); // Can reference GDT segments
// Interrupts must be off during sensitive operations
assert!(!are_enabled());
Symptoms:
Diagnosis:
# Find last successful operation
grep "initialized\|complete" logs/latest.log | tail -1
# Check if interrupts were enabled prematurely
grep "Enabling interrupts" logs/latest.log
# Look for infinite loops
grep "WARN\|ERROR" logs/latest.log
Common causes:
Interrupts enabled too early
Deadlock during initialization
Infinite loop in subsystem init
Fix patterns:
// Add checkpoint logging
log::info!("About to initialize subsystem X");
subsystem_x::init();
log::info!("Subsystem X initialized successfully");
// If hangs between checkpoints, focus on subsystem_x::init()
Symptoms:
PANIC: [message]
Stack trace: ...
Diagnosis:
# Get panic message
grep "PANIC" logs/latest.log
# Get context
grep -B20 "PANIC" logs/latest.log
Common causes:
Assertion failure
assert!(condition); // Failed during boot
Check if assertion is correct or if precondition not met
Unwrap on None/Err
let value = option.unwrap(); // Panic if None
Use proper error handling during boot
Out of memory
allocation error: Layout { ... }
Increase heap size or defer allocation
Symptoms:
Example:
// BAD - heap used before initialization
use alloc::vec::Vec;
let v = Vec::new(); // Panic! Heap not initialized yet
heap::init();
// GOOD
heap::init();
use alloc::vec::Vec;
let v = Vec::new(); // OK
Diagnosis:
Symptoms:
Diagnosis:
# Find which commit broke it
git bisect start
git bisect bad HEAD
git bisect good last_working_commit
# Test each commit
kernel-debug-loop/scripts/quick_debug.py \
--signal "KERNEL READY" \
--timeout 15
Fix:
Measure with kernel-debug-loop:
# Time to specific checkpoint
kernel-debug-loop/scripts/quick_debug.py \
--signal "Kernel initialization complete" \
--timeout 30
Typical times (approximate):
1. Defer non-critical initialization
// Don't initialize during boot if not needed
// keyboard::init(); // Defer until first use
// Or lazy initialization
pub fn get_keyboard() -> &'static Keyboard {
static INIT: Once = Once::new();
INIT.call_once(|| {
keyboard::init();
});
&KEYBOARD
}
2. Parallelize independent operations
// Currently serial:
timer::init();
rtc::init();
keyboard::init();
// Could be parallel (if truly independent):
// Note: Difficult in kernel without threading during boot
3. Reduce logging verbosity
// Debug builds: verbose
#[cfg(debug_assertions)]
log::debug!("Detailed info");
// Release builds: minimal
#[cfg(not(debug_assertions))]
log::info!("Essential info only");
4. Optimize expensive operations
// Identify slow operations with timing
let start = time::get_monotonic_ms();
expensive_operation();
let elapsed = time::get_monotonic_ms() - start;
if elapsed > 10 {
log::warn!("Slow operation: {}ms", elapsed);
}
# Fast iteration on boot fixes
kernel-debug-loop/scripts/quick_debug.py \
--signal "BOOT_CHECKPOINT" \
--timeout 10
# Extract boot sequence
echo '"initialized"' > /tmp/log-query.txt
./scripts/find-in-logs
# Find boot failures
echo '"PANIC|FAULT|ERROR"' > /tmp/log-query.txt
./scripts/find-in-logs
Document boot issues:
# Problem
Kernel hangs after "Enabling interrupts"
# Root Cause
Timer interrupt handler called before scheduler ready
# Solution
Initialize scheduler before enabling interrupts
# Evidence
Before: Hang
After: Boot completes successfully
Essential checkpoints every boot should reach:
[✓] GDT initialized
[✓] IDT initialized
[✓] PIC initialized
[✓] Physical memory detected
[✓] Heap initialized
[✓] Timer initialized
[✓] Interrupts enabled
[✓] Threading initialized
[✓] Kernel ready
If boot stops before reaching a checkpoint, debug that subsystem.
kernel/src/main.rs - Entry point, boot orchestration
kernel/src/gdt.rs - GDT initialization
kernel/src/interrupts/mod.rs - IDT initialization
kernel/src/memory/frame_allocator.rs - Physical memory
kernel/src/time/timer.rs - Timer initialization
kernel/src/time/rtc.rs - RTC initialization
"GDT initialized"
"IDT initialized"
"Physical memory:"
"Heap:"
"Timer initialized"
"Enabling interrupts"
"Threading subsystem initialized"
"Kernel initialization complete"
Boot analysis requires:
A well-understood boot sequence makes debugging initialization issues straightforward.
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer