From 1a2446fca695102b04e20a385c147e894f264ab4 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 7 Sep 2011 17:48:01 +0200 Subject: [PATCH] Added a friendly message on panic, and SIGSEGV no longer panics. --- sortix/isr.cpp | 27 ++++++++++++++++++++++++--- sortix/panic.cpp | 8 ++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/sortix/isr.cpp b/sortix/isr.cpp index aac28c84..efe4b046 100644 --- a/sortix/isr.cpp +++ b/sortix/isr.cpp @@ -10,6 +10,11 @@ #include "isr.h" #include "panic.h" +#include "process.h" // Hack for SIGSEGV +#include "sound.h" // Hack for SIGSEGV + +using namespace Sortix; + size_t numknownexceptions = 19; const char* exceptions[] = { "Divide by zero", "Debug", "Non maskable interrupt", "Breakpoint", "Into detected overflow", "Out of bounds", "Invalid opcode", @@ -31,10 +36,26 @@ const char* exceptions[] = { "Divide by zero", "Debug", "Non maskable interrupt" #ifdef PLATFORM_X86 if ( Regs->int_no < 32 ) { - const char* message = ( Regs->int_no < numknownexceptions ) ? exceptions[Regs->int_no] : "Unknown"; - //Sortix::Log::PrintF("eax=0x%x\tebx=0x%x\tecx=0x%x\tedx=0x%x\tesi=0x%x\tedi=0x%x\tesp=0x%x\tuseresp=0x%x\tebp=0x%x\teip=0x%x\n", Regs->eax, Regs->ebx, Regs->ecx, Regs->edx, Regs->esi, Regs->edi, Regs->esp, Regs->useresp, Regs->ebp, Regs->eip); + const char* message = ( Regs->int_no < numknownexceptions ) + ? exceptions[Regs->int_no] : "Unknown"; - Sortix::PanicF("Unhandled CPU Exception id %zu '%s' at eip=0x%zx (cr2=0x%p, err_code=0x%p)", Regs->int_no, message, Regs->eip, Regs->cr2, Regs->err_code); + // Halt and catch fire if we are the kernel. + if ( (Regs->cs & (0x4-1)) == 0 ) + { + PanicF("Unhandled CPU Exception id %zu '%s' at eip=0x%zx " + "(cr2=0x%p, err_code=0x%p)", Regs->int_no, message, + Regs->eip, Regs->cr2, Regs->err_code); + } + + Log::Print("The current program has crashed and was terminated:\n"); + Log::PrintF("%s exception at eip=0x%zx (cr2=0x%p, err_code=0x%p)\n", + message, Regs->eip, Regs->cr2, Regs->err_code); + + Sound::Mute(); + const char* programname = "sh"; + Regs->ebx = (uint32_t) programname; + SysExecute(Regs); + return; } if ( interrupt_handlers[Regs->int_no] != NULL ) diff --git a/sortix/panic.cpp b/sortix/panic.cpp index af659ed5..ecb5ff95 100644 --- a/sortix/panic.cpp +++ b/sortix/panic.cpp @@ -32,7 +32,11 @@ using namespace Maxsi; namespace Sortix { +#if defined(DEBUG) || defined(PANIC_LONG) bool longpanic = false; +#else + bool longpanic = true; +#endif void PanicInit() { @@ -57,6 +61,10 @@ namespace Sortix 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 {