Skip to main content
When MVH Kernel encounters an unrecoverable error, it enters a controlled panic state that displays a stable panic code, the decoded exception name, hardware error-code flag analysis (page-fault and selector-error formats), the full set of general-purpose registers, the x86_64 control registers (CR0, CR2, CR3, CR4), and a bounded frame-pointer stack trace. All output is written to both the VGA text console and the serial port so that you can capture it headlessly. Once a panic is triggered the system halts and does not return.
Both kernel_panic and kernel_panic_exception are declared noreturn. Calling either function halts the system immediately and irrevocably — execution never returns to the call site.

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:
Panic codes are stable across kernel releases so you can use them in automated crash analysis pipelines. The code is printed in the panic banner alongside the human-readable exception name.

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

Trigger a kernel panic with a plain text message. Use this function when your own code detects an unrecoverable condition — for example, a failed assertion, a corrupted data structure, or an unexpected null pointer at a point where recovery is impossible. The panic handler prints the message, the current register state, the control registers, and a stack trace, then halts all further execution.
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 never returns. Any code after the call site is unreachable.

kernel_panic_exception

Trigger a kernel panic from an exception frame. This function is called automatically by the kernel’s 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 use kernel_panic as a hard assertion guard inside a kernel subsystem initialisation routine.