|
|
@@ -1,5 +1,5 @@
|
|
|
|
#include <OS/Panic.h>
|
|
|
|
#include <OS/Panic.h>
|
|
|
|
#include <IO/Serial.h>
|
|
|
|
#include <OS/Log.h>
|
|
|
|
#include <Arch/CPU.h>
|
|
|
|
#include <Arch/CPU.h>
|
|
|
|
|
|
|
|
|
|
|
|
static const ASCII* GetExceptionClassString(UInt32 class) {
|
|
|
|
static const ASCII* GetExceptionClassString(UInt32 class) {
|
|
|
@@ -20,6 +20,10 @@ static const ASCII* GetExceptionClassString(UInt32 class) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void PrintSeparator() {
|
|
|
|
|
|
|
|
OSLog("--------------------------------\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) {
|
|
|
|
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) {
|
|
|
|
UInt32 esr = frame->esr_el1;
|
|
|
|
UInt32 esr = frame->esr_el1;
|
|
|
@@ -27,14 +31,62 @@ __attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) {
|
|
|
|
UInt32 length = (esr >> 25) & 0x1; // Instruction length (Bit 25)
|
|
|
|
UInt32 length = (esr >> 25) & 0x1; // Instruction length (Bit 25)
|
|
|
|
UInt32 syndrome = esr & 0x1FFFFFF; // Syndrome (Bits 24:0)
|
|
|
|
UInt32 syndrome = esr & 0x1FFFFFF; // Syndrome (Bits 24:0)
|
|
|
|
|
|
|
|
|
|
|
|
// i cant show any info since i have no formatter yet :(
|
|
|
|
PrintSeparator();
|
|
|
|
IOSerialPutString("\n-------------------\n");
|
|
|
|
OSLog("Kernel Panic! :(\n");
|
|
|
|
IOSerialPutString("Kernel Panic! :(\n");
|
|
|
|
PrintSeparator();
|
|
|
|
IOSerialPutString("-------------------\n");
|
|
|
|
OSLog("CPU Exception: %s (%d)\n", GetExceptionClassString(class), class);
|
|
|
|
IOSerialPutString("CPU Exception: ");
|
|
|
|
OSLog("ESR_EL1 (Syndrome): 0x%x (%d)\n", esr, syndrome);
|
|
|
|
IOSerialPutString(GetExceptionClassString(class));
|
|
|
|
OSLog("Instruction pointer: 0x%x (%s)\n", frame->elr_el1, length ? "32-bit" : "64-bit");
|
|
|
|
IOSerialPutString("\n-------------------\n");
|
|
|
|
OSLog("CPU status: 0x%x\n", frame->spsr_el1);
|
|
|
|
IOSerialPutString("System halted.\n");
|
|
|
|
|
|
|
|
|
|
|
|
if (class == 0x25 || class == 0x24 || class == 0x20 || class == 0x21 ) {
|
|
|
|
|
|
|
|
PrintSeparator();
|
|
|
|
|
|
|
|
OSLog("Memory abort helper:\n");
|
|
|
|
|
|
|
|
PrintSeparator();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UInt64 far = CPUGetFAR();
|
|
|
|
|
|
|
|
OSLog("Faulting address: 0x%x\n", far);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UInt32 wnr = (syndrome >> 6) & 0x1;
|
|
|
|
|
|
|
|
if (class == 0x24 || class == 0x25) {
|
|
|
|
|
|
|
|
OSLog("[W] Caused by %s\n", wnr ? "WRITE" : "READ");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
OSLog("[T] Tried to execute code from NX/Invalid memory\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UInt32 dfsc = syndrome & 0x3F;
|
|
|
|
|
|
|
|
switch (dfsc & 0b111100) {
|
|
|
|
|
|
|
|
case 0b000000: OSLog("[P] Reason: Address size fault (Bad pointer format)\n"); break;
|
|
|
|
|
|
|
|
case 0b000100: OSLog("[P] Reason: Translation fault\n"); break;
|
|
|
|
|
|
|
|
case 0b001100: OSLog("[P] Reason: Permission fault (Page protection violation)\n"); break;
|
|
|
|
|
|
|
|
case 0b010000: OSLog("[P] Reason: Synchronous external abort\n"); break;
|
|
|
|
|
|
|
|
case 0b100000: OSLog("[P] Reason: Alignment fault\n"); break;
|
|
|
|
|
|
|
|
default: OSLog("[P] Reason: Unknown fault code (0x%X)\n", dfsc); break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintSeparator();
|
|
|
|
|
|
|
|
OSLog("Registers:\n");
|
|
|
|
|
|
|
|
PrintSeparator();
|
|
|
|
|
|
|
|
OSLog("x0 = 0x%X; x1 = 0x%X\n", frame->x0, frame->x1);
|
|
|
|
|
|
|
|
OSLog("x2 = 0x%X; x3 = 0x%X\n", frame->x2, frame->x3);
|
|
|
|
|
|
|
|
OSLog("x4 = 0x%X; x5 = 0x%X\n", frame->x4, frame->x5);
|
|
|
|
|
|
|
|
OSLog("x6 = 0x%X; x7 = 0x%X\n", frame->x6, frame->x7);
|
|
|
|
|
|
|
|
OSLog("x8 = 0x%X; x9 = 0x%X\n", frame->x8, frame->x9);
|
|
|
|
|
|
|
|
OSLog("x10 = 0x%X; x11 = 0x%X\n", frame->x10, frame->x11);
|
|
|
|
|
|
|
|
OSLog("x12 = 0x%X; x13 = 0x%X\n", frame->x12, frame->x13);
|
|
|
|
|
|
|
|
OSLog("x14 = 0x%X; x15 = 0x%X\n", frame->x14, frame->x15);
|
|
|
|
|
|
|
|
OSLog("x16 = 0x%X; x17 = 0x%X\n", frame->x16, frame->x17);
|
|
|
|
|
|
|
|
OSLog("x18 = 0x%X; x19 = 0x%X\n", frame->x18, frame->x19);
|
|
|
|
|
|
|
|
OSLog("x20 = 0x%X; x21 = 0x%X\n", frame->x20, frame->x21);
|
|
|
|
|
|
|
|
OSLog("x22 = 0x%X; x23 = 0x%X\n", frame->x22, frame->x23);
|
|
|
|
|
|
|
|
OSLog("x24 = 0x%X; x25 = 0x%X\n", frame->x24, frame->x25);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
while (1) {
|
|
|
|
CPUDisableInterrupts();
|
|
|
|
CPUDisableInterrupts();
|
|
|
|