1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/sortix/panic.cpp

128 lines
4.3 KiB
C++
Raw Normal View History

/*******************************************************************************
2011-08-05 08:25:00 -04:00
Copyright(C) Jonas 'Sortie' Termansen 2011, 2013.
2011-08-05 08:25:00 -04:00
This file is part of Sortix.
2011-08-05 08:25:00 -04:00
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
2011-08-05 08:25:00 -04:00
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
2011-08-05 08:25:00 -04:00
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
2011-08-05 08:25:00 -04:00
panic.cpp
Displays an error whenever something critical happens.
2011-08-05 08:25:00 -04:00
*******************************************************************************/
2011-08-05 08:25:00 -04:00
2013-05-13 08:52:15 -04:00
#include <string.h>
#include <sortix/kernel/calltrace.h>
2013-01-09 17:30:36 -05:00
#include <sortix/kernel/interrupt.h>
2013-10-26 20:42:10 -04:00
#include <sortix/kernel/kernel.h>
#include <sortix/kernel/log.h>
#include <sortix/kernel/panic.h>
2011-08-05 08:25:00 -04:00
namespace Sortix {
#if defined(PANIC_SHORT)
const bool longpanic = false;
#else
const bool longpanic = true;
#endif
2011-08-05 08:25:00 -04:00
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");
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");
}
2011-08-05 08:25:00 -04:00
void PanicInit()
{
Interrupt::Disable();
2011-08-05 08:25:00 -04:00
// Handle the case where the panic code caused another system crash.
if ( panicing )
2011-08-05 08:25:00 -04:00
{
Log::PrintF("Panic while panicing:\n");
doublepanic = true;
return;
2011-08-05 08:25:00 -04:00
}
panicing = true;
2011-08-05 08:25:00 -04:00
// 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();
2011-08-05 08:25:00 -04:00
}
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