mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Update kernel panic code to current coding conventions.
This commit is contained in:
parent
a44138f72f
commit
2e64286ae5
2 changed files with 101 additions and 104 deletions
|
@ -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 {
|
||||
|
||||
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" __attribute__((noreturn)) void Panic(const char* error);
|
||||
extern "C" __attribute__((noreturn)) void PanicF(const char* format, ...);
|
||||
extern "C" void WaitForInterrupt();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Sortix
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2013.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -25,32 +25,23 @@
|
|||
#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 )
|
||||
static bool panicing = false;
|
||||
static bool doublepanic = false;
|
||||
|
||||
static void PanicLogoLong()
|
||||
{
|
||||
Log::Print("\e[m\e[31;40m\e[2J\e[H");
|
||||
Log::Print(" _ \n");
|
||||
|
@ -76,51 +67,61 @@ namespace Sortix
|
|||
Log::Print("\n");
|
||||
Log::Print("Technical information:\n");
|
||||
}
|
||||
else
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void PanicCalltrace()
|
||||
static void PanicCalltrace()
|
||||
{
|
||||
Log::Print("\n");
|
||||
Calltrace::Perform();
|
||||
}
|
||||
|
||||
void PanicHooks()
|
||||
static void PanicHooks()
|
||||
{
|
||||
if ( doublepanic ) { return; }
|
||||
if ( ENABLE_CALLTRACE ) { PanicCalltrace(); }
|
||||
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)
|
||||
extern "C" __attribute__((noreturn)) void Panic(const char* error)
|
||||
{
|
||||
PanicInit();
|
||||
Log::Print(Error);
|
||||
Log::Print(error);
|
||||
PanicHooks();
|
||||
PanicHalt();
|
||||
HaltKernel();
|
||||
}
|
||||
|
||||
extern "C" void PanicF(const char* Format, ...)
|
||||
extern "C" __attribute__((noreturn)) void PanicF(const char* format, ...)
|
||||
{
|
||||
PanicInit();
|
||||
va_list list;
|
||||
va_start(list, Format);
|
||||
Log::PrintFV(Format, list);
|
||||
va_start(list, format);
|
||||
Log::PrintFV(format, list);
|
||||
va_end(list);
|
||||
PanicHooks();
|
||||
PanicHalt();
|
||||
}
|
||||
HaltKernel();
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
|
Loading…
Add table
Reference in a new issue