Working kernel written on C and userspace-ready #1
@@ -3,4 +3,5 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
#include <Arch/Exceptions.h>
|
#include <Arch/Exceptions.h>
|
||||||
|
|
||||||
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame);
|
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame);
|
||||||
|
__attribute__((noreturn)) void OSPanic(const ASCII* message);
|
||||||
+30
-10
@@ -20,10 +20,36 @@ static const ASCII* GetExceptionClassString(UInt32 class) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((noreturn)) static void Halt() {
|
||||||
|
while (1) {
|
||||||
|
CPUDisableInterrupts();
|
||||||
|
CPUWaitForInterrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void PrintSeparator() {
|
static void PrintSeparator() {
|
||||||
OSLog("--------------------------------\n");
|
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) {
|
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame) {
|
||||||
UInt32 esr = frame->esr_el1;
|
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 length = (esr >> 25) & 0x1; // Instruction length (Bit 25)
|
||||||
UInt32 syndrome = esr & 0x1FFFFFF; // Syndrome (Bits 24:0)
|
UInt32 syndrome = esr & 0x1FFFFFF; // Syndrome (Bits 24:0)
|
||||||
|
|
||||||
PrintSeparator();
|
DrawPanicHeader();
|
||||||
OSLog("Kernel Panic! :(\n");
|
|
||||||
PrintSeparator();
|
|
||||||
OSLog("CPU Exception: %s (%d)\n", GetExceptionClassString(class), class);
|
OSLog("CPU Exception: %s (%d)\n", GetExceptionClassString(class), class);
|
||||||
OSLog("ESR_EL1 (Syndrome): 0x%x (%d)\n", esr, syndrome);
|
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");
|
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("x26 = 0x%X; x27 = 0x%X\n", frame->x26, frame->x27);
|
||||||
OSLog("\t\tx28 = 0x%X\n", frame->x28);
|
OSLog("\t\tx28 = 0x%X\n", frame->x28);
|
||||||
OSLog("FP = 0x%X; LR = 0x%X\n", frame->x29, frame->x30);
|
OSLog("FP = 0x%X; LR = 0x%X\n", frame->x29, frame->x30);
|
||||||
PrintSeparator();
|
|
||||||
|
|
||||||
OSLog("System halted.\n");
|
DrawPanicFooter();
|
||||||
|
Halt();
|
||||||
while (1) {
|
|
||||||
CPUDisableInterrupts();
|
|
||||||
CPUWaitForInterrupt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user