From 2e64286ae52cd312d32187e9d74fbb2340ca079e Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 20 Jun 2013 16:37:25 +0200 Subject: [PATCH] Update kernel panic code to current coding conventions. --- sortix/include/sortix/kernel/panic.h | 22 ++-- sortix/panic.cpp | 183 ++++++++++++++------------- 2 files changed, 101 insertions(+), 104 deletions(-) diff --git a/sortix/include/sortix/kernel/panic.h b/sortix/include/sortix/kernel/panic.h index 4785d027..79995b9c 100644 --- a/sortix/include/sortix/kernel/panic.h +++ b/sortix/include/sortix/kernel/panic.h @@ -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 diff --git a/sortix/panic.cpp b/sortix/panic.cpp index 42c76544..f3e7f467 100644 --- a/sortix/panic.cpp +++ b/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. @@ -25,102 +25,103 @@ #include #include +#include #include #include #include -#include -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