The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
smp_boot.c File Reference

start the other cores (application processors) of an x86 machine. More...

Macros

#define LOW_PAGE_LIMIT   0x100u
#define CR4_PCIDE   (1u << 17)
#define MSR_EFER   0xC0000080u
#define EFER_LMA   (1u << 10)
#define INIT_WAIT_US   10000u
#define STARTUP_WAIT_US   200u
#define ANSWER_WAIT_US   100000u
#define POLL_US   100u

Functions

void smp_ap_entry (cpu_t *cpu)
 the first C code of a core other than the boot core.
void arch_smp_reserve (void)
 keep a page of low memory for the start code of the other cores.
bool arch_smp_prepare (cpu_t *boot)
 get ready to start the other cores: copy the start code to its page and make the page tables it uses.
bool arch_cpu_start (cpu_t *cpu)
 start one core and wait up to 100 ms for it to say it is online.
void arch_smp_finish (bool all_started)
 release what only the start of the cores used.
void arch_cpu_send_ipi (const cpu_t *cpu, arch_ipi_t ipi)

Variables

const uint8_t ap_trampoline_start []
const uint8_t ap_trampoline_end []
const uint8_t ap_trampoline_data []

Detailed Description

start the other cores (application processors) of an x86 machine.

a core that gets INIT and then a startup IPI (SIPI) starts in real mode at a page below 1 MiB that the SIPI gives. the trampoline (asm/ap_trampoline.asm, asm64/ap_trampoline.asm) is copied to that page. it changes to protected mode (and to long mode on x86_64) with a temporary page table, and jumps to smp_ap_entry() on the stack of the core. the temporary page table is a copy of the kernel half of the kernel's tables, with the trampoline page also at its own address. the sequence is from the Intel SDM, volume 3, 8.4, as in Linux's smpboot.c.

the boot core starts one core at a time and waits for it, so one data block in the trampoline page is enough.

Macro Definition Documentation

◆ LOW_PAGE_LIMIT

#define LOW_PAGE_LIMIT   0x100u

◆ CR4_PCIDE

#define CR4_PCIDE   (1u << 17)

◆ MSR_EFER

#define MSR_EFER   0xC0000080u

◆ EFER_LMA

#define EFER_LMA   (1u << 10)

◆ INIT_WAIT_US

#define INIT_WAIT_US   10000u

◆ STARTUP_WAIT_US

#define STARTUP_WAIT_US   200u

◆ ANSWER_WAIT_US

#define ANSWER_WAIT_US   100000u

◆ POLL_US

#define POLL_US   100u

Function Documentation

◆ smp_ap_entry()

void smp_ap_entry ( cpu_t * cpu)

the first C code of a core other than the boot core.

the trampoline jumps here with the temporary page table, interrupts off, and the stack of the core. never returns.

Parameters
cputhe cpu_t of the core.

◆ arch_smp_reserve()

void arch_smp_reserve ( void )

keep a page of low memory for the start code of the other cores.

call it right after pmm_init, before other allocations can take that memory.

◆ arch_smp_prepare()

bool arch_smp_prepare ( struct cpu * boot)

get ready to start the other cores: copy the start code to its page and make the page tables it uses.

it also sets the hardware id of the boot core in its cpu_t.

Parameters
bootthe cpu_t of the boot core.
Returns
false if the other cores cannot start (no local APIC, no low page or no memory).

◆ arch_cpu_start()

bool arch_cpu_start ( struct cpu * cpu)

start one core and wait up to 100 ms for it to say it is online.

Parameters
cpuits cpu_t, with index, apic_id and idle_stack set.
Returns
true if the core runs.

◆ arch_smp_finish()

void arch_smp_finish ( bool all_started)

release what only the start of the cores used.

Parameters
all_startedfalse if a core did not answer: then the start code and its page tables stay, because that core can still start late.

◆ arch_cpu_send_ipi()

void arch_cpu_send_ipi ( const cpu_t * cpu,
arch_ipi_t ipi )

Variable Documentation

◆ ap_trampoline_start

const uint8_t ap_trampoline_start[]
extern

◆ ap_trampoline_end

const uint8_t ap_trampoline_end[]
extern

◆ ap_trampoline_data

const uint8_t ap_trampoline_data[]
extern