28 panic(
NULL,
"Failed to allocate memory for trampoline backup");
34 panic(
NULL,
"Failed to allocate memory for trampoline stack");
79 while (elapsed < timeout)
103 panic(
NULL,
"Failed to initialize CPU %u", cpuId);
#define assert(expression)
@ GDT_CS_RING0
Value to load into the CS register for kernel code.
@ GDT_SS_RING0
Value to load into the SS register for kernel data.
#define TRAMPOLINE_PML4_OFFSET
Offset within the trampoline page where the PML4 address is stored.
void trampoline_send_startup_ipi(cpu_t *cpu, cpuid_t id, lapic_id_t lapicId)
Sends the startup IPI to a CPU to start it up.
#define TRAMPOLINE_STACK_OFFSET
Offset within the trampoline page where the stack pointer for the trampoline is stored.
#define TRAMPOLINE_SIZE
The size of the trampoline code.
void trampoline_start(void)
The start of the trampoline code, defined in trampoline.s.
#define TRAMPOLINE_BASE_ADDR
The physical address where the trampoline code will be copied to and executed from.
void trampoline_deinit(void)
Deinitializes the trampoline by restoring the original contents of the trampoline memory location.
#define TRAMPOLINE_ENTRY_OFFSET
Offset within the trampoline page where the entry point to jump to is stored.
#define TRAMPOLINE_ADDR(offset)
Macro to get a pointer to an address within the trampoline page.
#define TRAMPOLINE_CPU_OFFSET
Offset within the trampoline page where the CPU structure pointer is stored.
uint64_t trampoline_wait_ready(clock_t timeout)
Waits for the currently starting CPU to signal that it is ready.
#define TRAMPOLINE_CPU_ID_OFFSET
Offset within the trampoline page where the CPU id is stored.
#define TRAMPOLINE_DATA_OFFSET
The offset within the trampoline page where we can store data.
void trampoline_init(void)
Initializes the trampoline by copying the trampoline code to its designated memory location.
void trampoline_c_entry(cpu_t *cpu, cpuid_t cpuId)
After the trampoline is done with basic initialization, it calls this C entry point to continue CPU i...
uint64_t cpu_init(cpu_t *cpu, cpuid_t id)
Initializes a CPU structure as part of the boot process.
uint16_t cpuid_t
Type used to identify a CPU.
void lapic_send_init(lapic_id_t id)
Send an INIT IPI to a local apic.
void lapic_send_sipi(lapic_id_t id, void *entryPoint)
Send a Startup IPI to a local apic.
uint8_t lapic_id_t
Local APIC ID type.
void hpet_wait(clock_t nanoseconds)
Wait for a specified number of nanoseconds using the HPET.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_DEBUG(format,...)
#define PML_ENSURE_LOWER_HALF(addr)
Ensures that the given address is in the lower half of the address space.
void pmm_free(void *address)
Frees a single physical page.
void * pmm_alloc(void)
Allocates a single physical page.
space_t * vmm_get_kernel_space(void)
Retrieves the kernel's address space.
_NORETURN void thread_jump(thread_t *thread)
Jump to a thread by calling thread_load() and then loading its interrupt frame.
thread_t * sched_thread_unsafe(void)
Retrieves the currently running thread without disabling interrupts.
bool sched_is_idle(cpu_t *cpu)
Checks if the CPU is idle.
NORETURN void sched_idle_loop(void)
The idle loop for a CPU.
#define PAGE_SIZE
Memory page size.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ clock_t
A nanosecond time.
#define RFLAGS_ALWAYS_SET
#define atomic_store(object, desired)
#define atomic_load(object)
#define atomic_init(obj, value)
__UINTPTR_TYPE__ uintptr_t
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC void * memset(void *s, int c, size_t n)
uintptr_t top
The top of the stack, this address is not inclusive.
Thread of execution structure.
stack_pointer_t kernelStack
The kernel stack of the thread.
static atomic_bool cpuReadyFlag
static void * backupBuffer
static void trampoline_after_jump(void)
static void * trampolineStack
#define WRITE_64(address, value)