//----------------------------------------------------------------------------// // GNU GPL OS/K // // // // Authors: spectral` // // NeoX // // // // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// #define _UNLOCKED_IO #include // // Failed assert() handler // noreturn void _assert_handler(const char *msg, const char *file, int line, const char *func) { DisableIRQs(); (void)file; (void)line; (void)func; // XXX sprintf() to create a proper panicstr StartPanic(msg); } // // Your best boy panic() // This is CPU local... // noreturn void StartPanic(const char *str) { DisableIRQs(); SetKernState(KSTATE_PANIC); if (GetCurProc()) __CurProc[GetCurCPU()] = NULL; if (GetStdOut() == NULL) CrashSystem(); GetStdOut()->ClearTermUnlocked(GetStdOut()); if (str == NULL) { str = "(no message given)"; } if (GetPanicStr()) { GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "double panic!\n"); HaltCPU(); } SetPanicStr(str); GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "PANIC! - "); GetStdOut()->PrintOnTermUnlocked(GetStdOut(), str); HaltCPU(); } // // Oh well // noreturn void CrashSystem(void) { DisableIRQs(); HaltCPU(); }