Use panic() for exceptions and interrupts

This commit is contained in:
Eryn Wells 2016-03-23 01:55:46 -04:00
parent 6aa4453f77
commit c18af4d222

View file

@ -9,6 +9,8 @@
#include "Interrupts.hh" #include "Interrupts.hh"
#include "Console.hh" #include "Console.hh"
#include "IO.hh" #include "IO.hh"
#include "Kernel.hh"
extern "C" { extern "C" {
// Assembly functions. See isr.S. // Assembly functions. See isr.S.
@ -21,6 +23,33 @@ extern "C" {
void handleHardwareInterrupt1(); 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 { namespace x86 {
/* /*
@ -95,28 +124,8 @@ InterruptHandler::disableInterrupts()
void void
InterruptHandler::dispatchException(uint8_t exception) InterruptHandler::dispatchException(uint8_t exception)
{ {
using x86::Interrupt; auto& kernel = kernel::Kernel::systemKernel();
kernel.panic("Received %s exception.", sExceptionIdentifiers[exception]);
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. :(");
} }
@ -130,9 +139,11 @@ InterruptHandler::dispatchHardwareInterrupt(uint8_t irq)
case 1: case 1:
doKeyboardInterrupt(); doKeyboardInterrupt();
break; break;
default: default: {
// TODO: Implement a panic function... auto& kernel = kernel::Kernel::systemKernel();
kernel.panic("Unhandled interrupt.");
break; break;
}
} }
finishHardwareInterrupt(irq); finishHardwareInterrupt(irq);
} }
@ -179,8 +190,8 @@ extern "C"
void void
doUnhandledInterrupt() doUnhandledInterrupt()
{ {
auto& console = kernel::Console::systemConsole(); auto& kernel = kernel::Kernel::systemKernel();
console.printString("Received unhandled interrupt.\nAbort. :("); kernel.panic("Unhandled interrupt.");
} }