Stable Panic Codes
The kernel assigns a fixed numeric code to each common exception type. You can list all defined panic codes from the kernel shell:Types
exception_frame_t
A complete snapshot of the processor state at the moment an exception fires. The kernel’s low-level exception stubs push these fields onto the stack in the order listed, then pass a pointer to this structure to kernel_panic_exception.
uint64_t
The eight extended 64-bit general-purpose registers (
r15 through r8) saved by the exception stub before transferring control to the panic handler.uint64_t
The base pointer register. The panic handler walks this chain to produce the frame-pointer stack trace displayed in the panic output.
uint64_t
First integer argument register (System V AMD64 ABI).
uint64_t
Second integer argument register.
uint64_t
Third integer argument register / data register.
uint64_t
Fourth integer argument register / counter register.
uint64_t
Base register (callee-saved).
uint64_t
Accumulator register; holds the return value of the most recently completed function call.
uint64_t
The x86_64 exception vector number (0–255). Well-known values include
0 (divide error), 6 (invalid opcode), 8 (double fault), 13 (general protection fault), and 14 (page fault).uint64_t
The hardware-supplied error code. The panic handler decodes this field for vector 13 (GPF, selector-error format) and vector 14 (page fault, CR2 + P/W/U/I flags). Set to
0 for exceptions that do not push an error code.uint64_t
The instruction pointer value at the time of the exception — the address of the faulting or next instruction, depending on the exception class.
uint64_t
The code segment selector active when the exception occurred.
uint64_t
The full 64-bit RFLAGS value captured by the CPU on exception entry.
Functions
kernel_panic
const char *
required
A null-terminated human-readable description of the failure. This string is displayed verbatim in the panic banner on both VGA and serial output. Keep it concise — one short sentence is ideal.
kernel_panic_exception
exception_dispatch routine for every unhandled CPU exception — you do not need to call it yourself under normal circumstances.
The panic handler reads the vector number and error code from the frame to select the correct stable panic code, decode the error flags, and print the full register dump.
const exception_frame_t *
required
Pointer to a fully populated
exception_frame_t built by the low-level exception stub. The structure must remain valid for the duration of the call (in practice it lives on the kernel stack and is never freed, since the function never returns).kernel_panic_exception is called automatically by exception_dispatch for all CPU exceptions. You only need to call it directly if you are writing a custom exception stub that bypasses the standard dispatch path.Example
The following example shows how to usekernel_panic as a hard assertion guard inside a kernel subsystem initialisation routine.