Skip to main content

Module smp

Module smp 

Source
Expand description

SMP (Symmetric Multi-Processing) boot for x86_64.

Boots Application Processors (APs) using the legacy INIT+SIPI sequence. Inspired by Redox-OSโ€™s approach: a minimal trampoline does the 16โ†’64 bit mode switch, then jumps directly to smp_main in Rust.

Data layout after the trampoline code (written by BSP, read by AP): offset +0: PML4 physical address (CR3) offset +8: kernel stack top virtual address (RSP)

Synchronization: AP increments BOOTED_CORES after finishing per-CPU init. BSP spins until all expected APs are online.

Constantsยง

TRAMPOLINE_PHYS_ADDR
Physical address where the SMP trampoline is copied.

Staticsยง

AP_SCHED_GATE_OPEN ๐Ÿ”’
Gate used by BSP to release APs into scheduler/timer start.
BARRIER_TARGET ๐Ÿ”’
Target count for the rendezvous barrier (set by BSP before barrier).
BOOTED_CORES ๐Ÿ”’
Number of booted cores (starts at 1 for BSP).
SYNC_BARRIER ๐Ÿ”’
Counter for synchronization barriers.

Functionsยง

broadcast_panic_halt
Broadcast a halt command to all other CPUs.
copy_trampoline ๐Ÿ”’
Copy the trampoline to physical address 0x8000 and write the data area.
cpu_count
Return the number of online CPUs.
ensure_identity_mapping ๐Ÿ”’
Identity-map the trampoline physical pages so the AP can execute the trampoline code in real mode / protected mode before paging is enabled.
init
Boot Application Processors.
open_ap_scheduler_gate
Allow APs to start their local timer and enter the scheduler.
rendezvous_barrier ๐Ÿ”’
Wait at a synchronization barrier until all expected CPUs arrive.
send_init_sipi ๐Ÿ”’
Send INIT + SIPIร—2 to an AP per Intel SDM Volume 3, Section 10.6.7.1.
send_ipi ๐Ÿ”’
Send an IPI and wait for delivery.
smp_main
First Rust function executed on APs after the trampoline.
smp_trampoline ๐Ÿ”’ โš 
smp_trampoline_end ๐Ÿ”’ โš 
udelay ๐Ÿ”’
Busy-wait for the given number of microseconds (very rough).
wait_delivery ๐Ÿ”’
Wait for ICR delivery to complete.