28 asm volatile(
"cli" :::
"memory");
47 asm volatile(
"sti" :::
"memory");
94 panic(frame,
"page fault on present page at address 0x%llx", faultAddr);
100 panic(frame,
"kernel stack overflow at address 0x%llx", faultAddr);
106 panic(frame,
"failed to grow kernel stack for page fault at address 0x%llx", faultAddr);
117 panic(frame,
"failed to grow user stack for page fault at address 0x%llx", faultAddr);
125 panic(frame,
"invalid page fault at address 0x%llx", faultAddr);
137 F(
"pagefault at 0x%llx when %s present page at 0x%llx", frame->
rip,
162 F(
"pagefault at 0x%llx when %s 0x%llx", frame->
rip,
173 panic(frame,
"divide by zero");
180 panic(frame,
"invalid opcode");
185 panic(frame,
"double fault");
198 panic(frame,
"unhandled exception vector 0x%x", frame->
vector);
#define assert(expression)
void interrupt_ctx_init(interrupt_ctx_t *ctx)
Initializes the interrupt context.
void interrupt_handler(interrupt_frame_t *frame)
Handles CPU interrupts.
#define INTERRUPT_FRAME_IN_USER_SPACE(frame)
Checks if a interrupt frame is from user space.
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...
@ VECTOR_EXTERNAL_END
Exclusive end of external interrupts.
@ VECTOR_EXTERNAL_START
Inclusive start of external interrupts (handled by the IRQ system).
@ VECTOR_IPI
See IPI for more information.
@ VECTOR_FAKE
Used to implement interrupt_fake().
@ VECTOR_TIMER
See Timer subsystem for more information.
@ VECTOR_SPURIOUS
Made available for any component to use as a sink for spurious interrupts.
@ VECTOR_EXCEPTION_END
Exclusive end of exceptions.
void ipi_handle_pending(interrupt_frame_t *frame, cpu_t *self)
Handle pending IPIs on the current CPU.
void irq_dispatch(interrupt_frame_t *frame, cpu_t *self)
Dispatch an IRQ.
bool stack_pointer_overlaps_guard(stack_pointer_t *stack, uintptr_t addr, uint64_t length)
Check if an region overlaps the guard.
bool stack_pointer_is_in_stack(stack_pointer_t *stack, uintptr_t addr, uint64_t length)
Check if an region is within the stack.
void cpu_stacks_overflow_check(cpu_t *cpu)
Checks for CPU stack overflows.
static cpu_t * cpu_get_unsafe(void)
Gets the current CPU structure without disabling interrupts.
bool note_handle_pending(interrupt_frame_t *frame, cpu_t *self)
Handle pending notes for the current thread.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
void * vmm_alloc(space_t *space, void *virtAddr, uint64_t length, pml_flags_t pmlFlags, vmm_alloc_flags_t allocFlags)
Allocates and maps virtual memory in a given address space.
@ VMM_ALLOC_FAIL_IF_MAPPED
If set and any page is already mapped, fail and set errno to EEXIST.
void process_kill(process_t *process, const char *status)
Kills a process, pushing it to the reaper.
uint64_t thread_send_note(thread_t *thread, const char *string)
Send a note to a thread.
@ THREAD_DYING
The thread is currently dying, it will be freed by the scheduler once its invoked.
void wait_check_timeouts(interrupt_frame_t *frame, cpu_t *self)
Check for timeouts and unblock threads as needed.
thread_t * sched_thread_unsafe(void)
Retrieves the currently running thread without disabling interrupts.
void sched_do(interrupt_frame_t *frame, cpu_t *self)
Perform a scheduling operation.
void timer_ack_eoi(interrupt_frame_t *frame, cpu_t *self)
Acknowledge a timer interrupt and send EOI.
#define EEXIST
File exists.
#define errno
Error number variable.
#define F(format,...)
Format string macro.
#define ROUND_DOWN(number, multiple)
#define PAGE_SIZE
The size of a memory page in bytes.
#define NULL
Pointer error value.
#define ERR
Integer error value.
static void exception_handler(interrupt_frame_t *frame)
static void exception_user_page_fault_handler(interrupt_frame_t *frame)
static uint64_t exception_grow_stack(thread_t *thread, uintptr_t faultAddr, stack_pointer_t *stack, pml_flags_t flags)
static void exception_kernel_page_fault_handler(interrupt_frame_t *frame)
static void exception_handle_user(interrupt_frame_t *frame, const char *note)
errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
static const path_flag_t flags[]
#define RFLAGS_INTERRUPT_ENABLE
static uint64_t cr2_read()
static uint64_t rflags_read()
#define atomic_store(object, desired)
__UINTPTR_TYPE__ uintptr_t
interrupt_ctx_t interrupt
Per-CPU Interrupt Context.
A entry in a page table without a specified address or callback ID.
Structure to define a stack in memory.
Thread of execution structure.
process_t * process
The parent process that the thread executes within.
stack_pointer_t kernelStack
The kernel stack of the thread.
stack_pointer_t userStack
The user stack of the thread.