os-k/src/kaleid/kernel/ke/panic.c

64 lines
1.6 KiB
C
Raw Normal View History

2018-12-24 22:38:14 +01:00
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: How NOT to panic 101 //
//----------------------------------------------------------------------------//
#include "kernel/ke/panic.h"
2018-12-29 23:51:00 +01:00
#include "kernel/ke/state.h"
#include "kernel/io/terminal.h"
2018-12-24 22:38:14 +01:00
//
// Panic message
//
const char *panicstr = NULL;
//
// Failed assert() handler
//
noreturn void ___assert_handler(const char *msg, const char *file, int line, const char *func)
{
// not getting out of here
2018-12-29 23:51:00 +01:00
DosDisableInterrupts();
2018-12-24 22:38:14 +01:00
(void)file; (void)line; (void)func;
// XXX sprintf() to create a proper panicstr
2018-12-29 23:51:00 +01:00
DosPanic(msg);
2018-12-24 22:38:14 +01:00
}
//
// Your best boy panic()
//
2018-12-29 23:51:00 +01:00
void DosPanic(const char *str)
2018-12-24 22:38:14 +01:00
{
2018-12-29 23:51:00 +01:00
DosDisableInterrupts();
2018-12-24 22:38:14 +01:00
2018-12-29 23:51:00 +01:00
DosSetKernState(KSTATE_PANIC);
DosClearTerm(stdout);
2018-12-24 22:38:14 +01:00
if (str == NULL) {
str = "(no message given)";
}
if (panicstr) {
// shouldn't be possible
2018-12-29 23:51:00 +01:00
DosPrintOnTerm(stdout, "double panic!\n");
DosHaltCPU();
2018-12-24 22:38:14 +01:00
}
panicstr = str;
2018-12-29 23:51:00 +01:00
DosPrintOnTerm(stdout, "panic! - ");
DosPrintOnTerm(stdout, str);
2018-12-24 22:38:14 +01:00
while (TRUE) {
2018-12-29 23:51:00 +01:00
DosHaltCPU();
2018-12-24 22:38:14 +01:00
}
}