From c18af4d222ce5dd0f251a3da57d9b93654735ddd Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 23 Mar 2016 01:55:46 -0400 Subject: [PATCH] Use panic() for exceptions and interrupts --- src/Interrupts.cc | 63 ++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/Interrupts.cc b/src/Interrupts.cc index a16656d..d66878e 100644 --- a/src/Interrupts.cc +++ b/src/Interrupts.cc @@ -9,6 +9,8 @@ #include "Interrupts.hh" #include "Console.hh" #include "IO.hh" +#include "Kernel.hh" + extern "C" { // Assembly functions. See isr.S. @@ -21,6 +23,33 @@ extern "C" { void handleHardwareInterrupt1(); } +namespace { + +static const char* sExceptionIdentifiers[] = { + "#DE", + "#DB", + "NMI", + "#BP", + "#OF", + "#BR", + "#UD", + "#NM", + "#DF", + "Int9", + "#TS", + "#NP", + "#SS", + "#GP", + "#PF", + "#MF", + "#AC", + "#MC", + "#XM", + "#VE", +}; + +} /* anonymous namespace */ + namespace x86 { /* @@ -95,28 +124,8 @@ InterruptHandler::disableInterrupts() void InterruptHandler::dispatchException(uint8_t exception) { - using x86::Interrupt; - - auto& console = kernel::Console::systemConsole(); - console.printString("Received exception "); - switch (Interrupt(exception)) { - case Interrupt::DE: - console.printString("#DE"); - break; - case Interrupt::NMI: - console.printString("NMI"); - break; - case Interrupt::DF: - console.printString("#DF"); - break; - case Interrupt::GP: - console.printString("#GP"); - break; - default: - console.printString("SOME OTHER THING"); - break; - } - console.printString("\nAbort. :("); + auto& kernel = kernel::Kernel::systemKernel(); + kernel.panic("Received %s exception.", sExceptionIdentifiers[exception]); } @@ -130,9 +139,11 @@ InterruptHandler::dispatchHardwareInterrupt(uint8_t irq) case 1: doKeyboardInterrupt(); break; - default: - // TODO: Implement a panic function... + default: { + auto& kernel = kernel::Kernel::systemKernel(); + kernel.panic("Unhandled interrupt."); break; + } } finishHardwareInterrupt(irq); } @@ -179,8 +190,8 @@ extern "C" void doUnhandledInterrupt() { - auto& console = kernel::Console::systemConsole(); - console.printString("Received unhandled interrupt.\nAbort. :("); + auto& kernel = kernel::Kernel::systemKernel(); + kernel.panic("Unhandled interrupt."); }