//----------------------------------------------------------------------------// // 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(); // This should be made atomic 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(), "\nDouble panic!\n"); HaltCPU(); } _SetPanicStr(str); GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "PANIC! - "); GetStdOut()->PrintOnTermUnlocked(GetStdOut(), str); HaltCPU(); } // // Oh well // noreturn void CrashSystem(void) { DisableIRQs(); HaltCPU(); }