//----------------------------------------------------------------------------// // GNU GPL OS/K // // // // Authors: spectral` // // NeoX // // // // Desc: How NOT to panic 101 // //----------------------------------------------------------------------------// #include #include #define _UNLOCKED_IO #include // // Panic message // const char *__panicmsg = NULL; // // Failed assert() handler // noreturn void _assert_handler(const char *msg, const char *file, int line, const char *func) { // not getting out of here DisableInterrupts(); (void)file; (void)line; (void)func; // XXX sprintf() to create a proper panicstr StartPanic(msg); } // // Your best boy panic() // void StartPanic(const char *str) { DisableInterrupts(); SetKernState(KSTATE_PANIC); ClearTermUnlocked(stdout); if (str == NULL) { str = "(no message given)"; } if (GetPanicStr()) { PrintOnTermUnlocked(stdout, "double panic!\n"); HaltCPU(); } SetPanicStr(str); // we cannot lock anything when panicking PrintOnTermUnlocked(stdout, "panic! - "); PrintOnTermUnlocked(stdout, str); while (TRUE) { HaltCPU(); } }