Update kernel panic code to current coding conventions.
This commit is contained in:
parent
a44138f72f
commit
2e64286ae5
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2013.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -22,20 +22,16 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#ifndef SORTIX_PANIC_H
|
#ifndef INCLUDE_SORTIX_KERNEL_PANIC_H
|
||||||
#define SORTIX_PANIC_H
|
#define INCLUDE_SORTIX_KERNEL_PANIC_H
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
{
|
|
||||||
// This function halts the kernel. If you wish to give an error message first,
|
|
||||||
// then you ought to call Panic instead.
|
|
||||||
extern "C" __attribute__((noreturn)) void HaltKernel();
|
|
||||||
|
|
||||||
extern "C" __attribute__((noreturn)) void Panic(const char* Error);
|
|
||||||
extern "C" __attribute__((noreturn)) void PanicF(const char* Format, ...);
|
|
||||||
extern "C" void WaitForInterrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
extern "C" __attribute__((noreturn)) void HaltKernel();
|
||||||
|
extern "C" __attribute__((noreturn)) void Panic(const char* error);
|
||||||
|
extern "C" __attribute__((noreturn)) void PanicF(const char* format, ...);
|
||||||
|
extern "C" void WaitForInterrupt();
|
||||||
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
183
sortix/panic.cpp
183
sortix/panic.cpp
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2013.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -25,102 +25,103 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
|
#include <sortix/kernel/calltrace.h>
|
||||||
#include <sortix/kernel/interrupt.h>
|
#include <sortix/kernel/interrupt.h>
|
||||||
#include <sortix/kernel/log.h>
|
#include <sortix/kernel/log.h>
|
||||||
#include <sortix/kernel/panic.h>
|
#include <sortix/kernel/panic.h>
|
||||||
#include <sortix/kernel/calltrace.h>
|
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
{
|
|
||||||
#if defined(DEBUG) || defined(PANIC_SHORT)
|
#if defined(PANIC_SHORT)
|
||||||
bool longpanic = false;
|
const bool longpanic = false;
|
||||||
#else
|
#else
|
||||||
bool longpanic = true;
|
const bool longpanic = true;
|
||||||
#endif
|
#endif
|
||||||
bool panicing = false;
|
|
||||||
bool doublepanic = false;
|
|
||||||
|
|
||||||
void PanicInit()
|
static bool panicing = false;
|
||||||
{
|
static bool doublepanic = false;
|
||||||
Interrupt::Disable();
|
|
||||||
if ( panicing )
|
|
||||||
{
|
|
||||||
Log::PrintF("Panic while panicing:\n");
|
|
||||||
doublepanic = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
panicing = true;
|
|
||||||
if ( longpanic )
|
|
||||||
{
|
|
||||||
Log::Print("\e[m\e[31;40m\e[2J\e[H");
|
|
||||||
Log::Print(" _ \n");
|
|
||||||
Log::Print(" / \\ \n");
|
|
||||||
Log::Print(" /\\ /\\ / \\ \n");
|
|
||||||
Log::Print(" / \\ / \\ | | \n");
|
|
||||||
Log::Print(" / \\/ \\ | | \n");
|
|
||||||
Log::Print(" | X X \\_______________________ / | \n");
|
|
||||||
Log::Print(" | | \n");
|
|
||||||
Log::Print(" | _________ / \n");
|
|
||||||
Log::Print(" \\ / \n");
|
|
||||||
Log::Print(" ------ --------------- ---/ \n");
|
|
||||||
Log::Print(" / \\ / \\ \n");
|
|
||||||
Log::Print(" / \\ / \\ \n");
|
|
||||||
Log::Print(" / \\ / \\ \n");
|
|
||||||
Log::Print(" /_____________\\ /____________\\ \n");
|
|
||||||
Log::Print(" \n");
|
|
||||||
Log::Print(" \n");
|
|
||||||
Log::Print(" RED MAXSI OF DEATH \n");
|
|
||||||
Log::Print(" \n");
|
|
||||||
Log::Print("A critical error occured within the kernel of the operating system and it has\n");
|
|
||||||
Log::Print("forcefully shut down as a last resort.\n");
|
|
||||||
Log::Print("\n");
|
|
||||||
Log::Print("Technical information:\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log::Print("\e[m\e[31m\e[0J");
|
|
||||||
Log::Print("RED MAXSI OF DEATH\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PanicCalltrace()
|
static void PanicLogoLong()
|
||||||
{
|
{
|
||||||
Log::Print("\n");
|
Log::Print("\e[m\e[31;40m\e[2J\e[H");
|
||||||
Calltrace::Perform();
|
Log::Print(" _ \n");
|
||||||
}
|
Log::Print(" / \\ \n");
|
||||||
|
Log::Print(" /\\ /\\ / \\ \n");
|
||||||
void PanicHooks()
|
Log::Print(" / \\ / \\ | | \n");
|
||||||
{
|
Log::Print(" / \\/ \\ | | \n");
|
||||||
if ( doublepanic ) { return; }
|
Log::Print(" | X X \\_______________________ / | \n");
|
||||||
if ( ENABLE_CALLTRACE ) { PanicCalltrace(); }
|
Log::Print(" | | \n");
|
||||||
}
|
Log::Print(" | _________ / \n");
|
||||||
|
Log::Print(" \\ / \n");
|
||||||
__attribute__((noreturn))
|
Log::Print(" ------ --------------- ---/ \n");
|
||||||
void PanicHalt()
|
Log::Print(" / \\ / \\ \n");
|
||||||
{
|
Log::Print(" / \\ / \\ \n");
|
||||||
#ifdef JSSORTIX
|
Log::Print(" / \\ / \\ \n");
|
||||||
JSSortix::Exit();
|
Log::Print(" /_____________\\ /____________\\ \n");
|
||||||
#endif
|
Log::Print(" \n");
|
||||||
HaltKernel();
|
Log::Print(" \n");
|
||||||
__builtin_unreachable();
|
Log::Print(" RED MAXSI OF DEATH \n");
|
||||||
}
|
Log::Print(" \n");
|
||||||
|
Log::Print("A critical error occured within the kernel of the operating system and it has\n");
|
||||||
extern "C" void Panic(const char* Error)
|
Log::Print("forcefully shut down as a last resort.\n");
|
||||||
{
|
Log::Print("\n");
|
||||||
PanicInit();
|
Log::Print("Technical information:\n");
|
||||||
Log::Print(Error);
|
|
||||||
PanicHooks();
|
|
||||||
PanicHalt();
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void PanicF(const char* Format, ...)
|
|
||||||
{
|
|
||||||
PanicInit();
|
|
||||||
va_list list;
|
|
||||||
va_start(list, Format);
|
|
||||||
Log::PrintFV(Format, list);
|
|
||||||
va_end(list);
|
|
||||||
PanicHooks();
|
|
||||||
PanicHalt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PanicLogoShort()
|
||||||
|
{
|
||||||
|
Log::Print("\e[m\e[31m\e[0J");
|
||||||
|
Log::Print("RED MAXSI OF DEATH\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PanicInit()
|
||||||
|
{
|
||||||
|
Interrupt::Disable();
|
||||||
|
|
||||||
|
// Handle the case where the panic code caused another system crash.
|
||||||
|
if ( panicing )
|
||||||
|
{
|
||||||
|
Log::PrintF("Panic while panicing:\n");
|
||||||
|
doublepanic = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
panicing = true;
|
||||||
|
|
||||||
|
// Render a notice that the system has crashed and forcefully shut down.
|
||||||
|
longpanic ? PanicLogoLong() : PanicLogoShort();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PanicCalltrace()
|
||||||
|
{
|
||||||
|
Log::Print("\n");
|
||||||
|
Calltrace::Perform();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PanicHooks()
|
||||||
|
{
|
||||||
|
if ( doublepanic )
|
||||||
|
return;
|
||||||
|
if ( ENABLE_CALLTRACE )
|
||||||
|
PanicCalltrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" __attribute__((noreturn)) void Panic(const char* error)
|
||||||
|
{
|
||||||
|
PanicInit();
|
||||||
|
Log::Print(error);
|
||||||
|
PanicHooks();
|
||||||
|
HaltKernel();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" __attribute__((noreturn)) void PanicF(const char* format, ...)
|
||||||
|
{
|
||||||
|
PanicInit();
|
||||||
|
va_list list;
|
||||||
|
va_start(list, format);
|
||||||
|
Log::PrintFV(format, list);
|
||||||
|
va_end(list);
|
||||||
|
PanicHooks();
|
||||||
|
HaltKernel();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
Loading…
Reference in New Issue