diff --git a/Kernel/Include/OS/Panic.h b/Kernel/Include/OS/Panic.h index c8d69d5..2eb3722 100644 --- a/Kernel/Include/OS/Panic.h +++ b/Kernel/Include/OS/Panic.h @@ -3,4 +3,5 @@ #include #include -__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame); \ No newline at end of file +__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame); +__attribute__((noreturn)) void OSPanic(const ASCII* message); \ No newline at end of file diff --git a/Kernel/Source/OS/Panic.c b/Kernel/Source/OS/Panic.c index 13883ac..8891ca8 100644 --- a/Kernel/Source/OS/Panic.c +++ b/Kernel/Source/OS/Panic.c @@ -20,10 +20,36 @@ static const ASCII* GetExceptionClassString(UInt32 class) { } } +__attribute__((noreturn)) static void Halt() { + while (1) { + CPUDisableInterrupts(); + CPUWaitForInterrupt(); + } +} + static void PrintSeparator() { OSLog("--------------------------------\n"); } +static void DrawPanicHeader() { + OSLog("\n\n"); + PrintSeparator(); + OSLog("\tKernel Panic! :(\n"); + PrintSeparator(); +} + +static void DrawPanicFooter() { + PrintSeparator(); + OSLog("\tSystem halted.\n"); + PrintSeparator(); +} + +__attribute__((noreturn)) void OSPanic(const ASCII* message) { + DrawPanicHeader(); + OSLog("\tReason: %s\n", message); + DrawPanicFooter(); + Halt(); +} __attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) { UInt32 esr = frame->esr_el1; @@ -31,9 +57,8 @@ __attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) { UInt32 length = (esr >> 25) & 0x1; // Instruction length (Bit 25) UInt32 syndrome = esr & 0x1FFFFFF; // Syndrome (Bits 24:0) - PrintSeparator(); - OSLog("Kernel Panic! :(\n"); - PrintSeparator(); + DrawPanicHeader(); + OSLog("CPU Exception: %s (%d)\n", GetExceptionClassString(class), class); OSLog("ESR_EL1 (Syndrome): 0x%x (%d)\n", esr, syndrome); OSLog("Instruction pointer: 0x%x (%s)\n", frame->elr_el1, length ? "32-bit" : "64-bit"); @@ -84,12 +109,7 @@ __attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) { OSLog("x26 = 0x%X; x27 = 0x%X\n", frame->x26, frame->x27); OSLog("\t\tx28 = 0x%X\n", frame->x28); OSLog("FP = 0x%X; LR = 0x%X\n", frame->x29, frame->x30); - PrintSeparator(); - OSLog("System halted.\n"); - - while (1) { - CPUDisableInterrupts(); - CPUWaitForInterrupt(); - } + DrawPanicFooter(); + Halt(); } \ No newline at end of file