51#define CPU_MAX (UINT8_MAX + 1)
56#define CPU_ID_BOOTSTRAP 0
61#define CPU_ID_INVALID UINT16_MAX
74#define CPU_STACK_CANARY 0x1234567890ABCDEFULL
100#define CPU_MAX_EVENT_HANDLERS 32
328 return _cpus[nextId];
339#define CPU_FOR_EACH(cpu) \
340 for (cpuid_t _cpuId = 0; _cpuId < _cpuAmount; _cpuId++) \
341 for (cpu_t* cpu = _cpus[_cpuId]; cpu != NULL; cpu = NULL)
#define assert(expression)
void interrupt_disable(void)
Disable interrupts and increment the disableDepth.
void interrupt_enable(void)
Decrement the CLI depth and enable interrupts if depth reaches zero and interrupts were previously en...
static cpu_t * cpu_get_next(cpu_t *current)
Gets the next CPU in the CPU array.
uint64_t cpu_halt_others(void)
Halts all other CPUs.
void cpu_stacks_overflow_check(cpu_t *cpu)
Checks for CPU stack overflows.
uint64_t cpu_handler_register(cpu_func_t func)
Registers a CPU event handler for all CPUs.
cpu_event_type_t
CPU event types.
static cpu_t * cpu_get_unsafe(void)
Gets the current CPU structure without disabling interrupts.
static cpu_t * cpu_get(void)
Gets the current CPU structure.
void(* cpu_func_t)(cpu_t *cpu, const cpu_event_t *event)
CPU event function type.
void cpu_init(cpu_t *cpu)
Initializes the CPU represented by the cpu_t structure.
static void cpu_put(void)
Releases the current CPU structure.
#define CPU_MAX
Maximum number of CPUs supported.
cpu_t * _cpus[CPU_MAX]
Array of pointers to cpu_t structures for each CPU, indexed by CPU ID.
static cpuid_t cpu_get_id_unsafe(void)
Gets the current CPU ID.
static uint16_t cpu_amount(void)
Gets the number of identified CPUs.
void cpu_handlers_check(cpu_t *cpu)
Checks if any handlers have been registered since the last check, and invokes them if so.
static cpu_t * cpu_get_by_id(cpuid_t id)
Gets a CPU structure by its ID.
void cpu_init_early(cpu_t *cpu)
Only initialize the parts of the CPU structure needed for early boot.
void cpu_handler_unregister(cpu_func_t func)
Unregisters a previously registered CPU event handler.
uint16_t _cpuAmount
The number of CPUs currently identified.
uint16_t cpuid_t
Type used to identify a CPU.
#define CONFIG_INTERRUPT_STACK_PAGES
Interrupt stack configuration.
#define PAGE_SIZE
The size of a memory page in bytes.
#define NULL
Pointer error value.
#define RFLAGS_INTERRUPT_ENABLE
static uint64_t msr_read(uint32_t msr)
static uint64_t rflags_read()
BITMAP_DEFINE(initializedCpus, CPU_MAX)
interrupt_ctx_t interrupt
atomic_bool needHandlersCheck
uint8_t interruptStackBuffer[CONFIG_INTERRUPT_STACK_PAGES *PAGE_SIZE] ALIGNED(PAGE_SIZE)
stack_pointer_t exceptionStack
uint8_t nmiStackBuffer[CONFIG_INTERRUPT_STACK_PAGES *PAGE_SIZE] ALIGNED(PAGE_SIZE)
uint8_t doubleFaultStackBuffer[CONFIG_INTERRUPT_STACK_PAGES *PAGE_SIZE] ALIGNED(PAGE_SIZE)
uint8_t exceptionStackBuffer[CONFIG_INTERRUPT_STACK_PAGES *PAGE_SIZE] ALIGNED(PAGE_SIZE)
stack_pointer_t interruptStack
stack_pointer_t doubleFaultStack
Per-CPU Interrupt Context.
Per-CPU performance context.
CPU random number generator context.
Structure to define a stack in memory.
Per-CPU system time context.
Task State Segment structure.
Represents one instance of the waiting subsystem for a CPU.