Update kernel panic code to current coding conventions.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-06-20 16:37:25 +02:00
parent a44138f72f
commit 2e64286ae5
2 changed files with 101 additions and 104 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2013.
This file is part of Sortix.
@ -22,20 +22,16 @@
*******************************************************************************/
#ifndef SORTIX_PANIC_H
#define SORTIX_PANIC_H
#ifndef INCLUDE_SORTIX_KERNEL_PANIC_H
#define INCLUDE_SORTIX_KERNEL_PANIC_H
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();
}
namespace Sortix {
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

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2013.
This file is part of Sortix.
@ -25,102 +25,103 @@
#include <string.h>
#include <sortix/kernel/platform.h>
#include <sortix/kernel/calltrace.h>
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/log.h>
#include <sortix/kernel/panic.h>
#include <sortix/kernel/calltrace.h>
namespace Sortix
{
#if defined(DEBUG) || defined(PANIC_SHORT)
bool longpanic = false;
namespace Sortix {
#if defined(PANIC_SHORT)
const bool longpanic = false;
#else
bool longpanic = true;
const bool longpanic = true;
#endif
bool panicing = false;
bool doublepanic = false;
void PanicInit()
{
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");
}
}
static bool panicing = false;
static bool doublepanic = false;
void PanicCalltrace()
{
Log::Print("\n");
Calltrace::Perform();
}
void PanicHooks()
{
if ( doublepanic ) { return; }
if ( ENABLE_CALLTRACE ) { PanicCalltrace(); }
}
__attribute__((noreturn))
void PanicHalt()
{
#ifdef JSSORTIX
JSSortix::Exit();
#endif
HaltKernel();
__builtin_unreachable();
}
extern "C" void Panic(const char* Error)
{
PanicInit();
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 PanicLogoLong()
{
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");
}
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