1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/kernel/ke/panic.c
2019-01-21 11:07:11 +01:00

70 lines
1.8 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: How NOT to panic 101 //
//----------------------------------------------------------------------------//
#include <kaleid.h>
//
// 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();
}