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

the local APIC and the I/O APIC. More...

#include "common/stdint.h"

Go to the source code of this file.

Macros

#define LOCAL_TIMER_VECTOR   0xEC
 the vector of the local APIC timer on the cores other than the boot core (as in Linux)
#define TLB_FLUSH_VECTOR   0xFC
 the vector of the IPI that asks a core to flush its TLB (Linux's CALL_FUNCTION_VECTOR)
#define RESCHEDULE_VECTOR   0xFD
 the vector of the IPI that wakes a core to run a process or act on a signal (as in Linux)

Functions

bool apic_init (uint32_t timer_hz)
 change from the 8259 PICs to the APICs.
bool apic_active (void)
 true after a successful apic_init.
void apic_eoi (void)
 end of interrupt to the local APIC.
void apic_set_irq_masked (uint32_t irq, bool masked)
 mask or unmask the I/O APIC entry of an ISA IRQ (0 to 15).
uint8_t apic_id (void)
 the id of the local APIC of the boot core, for the destination of MSI messages and the I/O APIC entries.
void apic_set_irq_level (uint32_t irq)
 make the I/O APIC entry of an ISA IRQ level-triggered (a PCI interrupt line routed to it).
bool apic_set_irq_dest (uint32_t irq, uint8_t lapic_id)
 send the I/O APIC entry of an ISA IRQ to a local APIC (physical destination mode).
bool apic_init_ap (void)
 set up the local APIC of a core other than the boot core: turn it on, mask LINT0, LINT1 and the error interrupt, and start its timer on LOCAL_TIMER_VECTOR at the rate the boot core measured (if the boot core uses its timer).
bool apic_send_init (uint8_t target)
 send INIT to a core: it stops and waits for a startup IPI.
bool apic_send_startup (uint8_t target, uint32_t page_address)
 send a startup IPI (SIPI) to a core that waits after INIT.
void apic_send_ipi (uint8_t target, uint8_t vector)
 send an interrupt to another core (an IPI) on a vector, with fixed delivery.
void apic_send_nmi (uint8_t target)
 send a non-maskable interrupt (NMI, vector 2) to another core.

Detailed Description

the local APIC and the I/O APIC.

the kernel starts with the 8259 PICs. apic_init changes to the APICs if the ACPI MADT describes them: the 8259s are masked, the I/O APIC sends the ISA IRQs to the same vectors as before (PIC_REMAP_OFFSET + irq), and the local APIC timer gives the scheduler tick on the vector of IRQ 0. without a MADT the kernel stays on the 8259s.

Macro Definition Documentation

◆ LOCAL_TIMER_VECTOR

#define LOCAL_TIMER_VECTOR   0xEC

the vector of the local APIC timer on the cores other than the boot core (as in Linux)

◆ TLB_FLUSH_VECTOR

#define TLB_FLUSH_VECTOR   0xFC

the vector of the IPI that asks a core to flush its TLB (Linux's CALL_FUNCTION_VECTOR)

◆ RESCHEDULE_VECTOR

#define RESCHEDULE_VECTOR   0xFD

the vector of the IPI that wakes a core to run a process or act on a signal (as in Linux)

Function Documentation

◆ apic_init()

bool apic_init ( uint32_t timer_hz)

change from the 8259 PICs to the APICs.

call with interrupts off, after acpi_init (it needs the MADT) and mmio_init.

Parameters
timer_hzthe tick rate for the local APIC timer.
Returns
true if the APICs are in use.

◆ apic_active()

bool apic_active ( void )

true after a successful apic_init.

◆ apic_eoi()

void apic_eoi ( void )

end of interrupt to the local APIC.

◆ apic_set_irq_masked()

void apic_set_irq_masked ( uint32_t irq,
bool masked )

mask or unmask the I/O APIC entry of an ISA IRQ (0 to 15).

◆ apic_id()

uint8_t apic_id ( void )

the id of the local APIC of the boot core, for the destination of MSI messages and the I/O APIC entries.

◆ apic_set_irq_level()

void apic_set_irq_level ( uint32_t irq)

make the I/O APIC entry of an ISA IRQ level-triggered (a PCI interrupt line routed to it).

the polarity stays as the MADT gives it.

◆ apic_set_irq_dest()

bool apic_set_irq_dest ( uint32_t irq,
uint8_t lapic_id )

send the I/O APIC entry of an ISA IRQ to a local APIC (physical destination mode).

Parameters
irqthe ISA IRQ (0 to 15).
lapic_idthe id of the local APIC of the core.
Returns
false if the IRQ has no I/O APIC entry.

◆ apic_init_ap()

bool apic_init_ap ( void )

set up the local APIC of a core other than the boot core: turn it on, mask LINT0, LINT1 and the error interrupt, and start its timer on LOCAL_TIMER_VECTOR at the rate the boot core measured (if the boot core uses its timer).

call it on that core, after apic_init on the boot core.

Returns
true if the timer of the core runs.

◆ apic_send_init()

bool apic_send_init ( uint8_t target)

send INIT to a core: it stops and waits for a startup IPI.

Parameters
targetthe local APIC id of the core.
Returns
false if the local APIC could not send the IPI.

◆ apic_send_startup()

bool apic_send_startup ( uint8_t target,
uint32_t page_address )

send a startup IPI (SIPI) to a core that waits after INIT.

the core starts in real mode at page_address (CS = page_address / 16, IP = 0).

Parameters
targetthe local APIC id of the core.
page_addressa page-aligned physical address below 1 MiB.
Returns
false if the local APIC could not send the IPI.

◆ apic_send_ipi()

void apic_send_ipi ( uint8_t target,
uint8_t vector )

send an interrupt to another core (an IPI) on a vector, with fixed delivery.

interrupts are off on this core while the IPI goes out.

Parameters
targetthe local APIC id of the core.
vectorthe vector the core receives.

◆ apic_send_nmi()

void apic_send_nmi ( uint8_t target)

send a non-maskable interrupt (NMI, vector 2) to another core.

it comes also when interrupts are off on that core.

Parameters
targetthe local APIC id of the core.