From 7a15e00cc238051a2bb677159a665bc13e0c3d61 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 13 Mar 2016 19:33:10 -0400 Subject: [PATCH] Add some system exception handlers and clean up assemply a bit --- src/Interrupts.cc | 19 +++++++++++++++---- src/isr.S | 27 +++++++++++++++++---------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/Interrupts.cc b/src/Interrupts.cc index 97c5e12..607e5b3 100644 --- a/src/Interrupts.cc +++ b/src/Interrupts.cc @@ -11,11 +11,10 @@ #include "IO.hh" extern "C" { - void dispatchExceptionHandler(size_t vector); - // Assembly functions. See isr.S. void unhandledInterrupt(); void handleDEException(); + void handleNMIInterrupt(); void handleDFException(); void handleGPException(); void handleHardwareInterrupt0(); @@ -50,14 +49,23 @@ InterruptHandler::initialize() { auto& console = kernel::Console::systemConsole(); + // All interrupts start out as "unhandled" for (size_t i = 0; i < IDT::Size; i++) { mIDT.setDescriptor(i, IDT::DescriptorSpec::exceptionHandler(0x8, &unhandledInterrupt)); } + + // System exceptions/faults + mIDT.setDescriptor(0x00, IDT::DescriptorSpec::exceptionHandler(0x8, &handleDEException)); + mIDT.setDescriptor(0x02, IDT::DescriptorSpec::exceptionHandler(0x8, &handleNMIInterrupt)); + mIDT.setDescriptor(0x08, IDT::DescriptorSpec::exceptionHandler(0x8, &handleDFException)); + mIDT.setDescriptor(0x0D, IDT::DescriptorSpec::exceptionHandler(0x8, &handleGPException)); + + + // Hardware interrupts mIDT.setDescriptor(0x20, IDT::DescriptorSpec::exceptionHandler(0x8, &handleHardwareInterrupt0)); mIDT.setDescriptor(0x21, IDT::DescriptorSpec::exceptionHandler(0x8, &handleHardwareInterrupt1)); - mIDT.load(); - console.printString("IDT loaded\n"); + mIDT.load(); mPIC.initialize(0x20, 0x28); // Map hardware IRQs to interrupt vectors 32 through 48. console.printString("Hardware interrupts initialized\n"); @@ -164,6 +172,9 @@ InterruptHandler::finishHardwareInterrupt(uint8_t irq) } /* namespace x86 */ +/* + * Interrupt handlers + */ extern "C" void diff --git a/src/isr.S b/src/isr.S index afe83ca..205dcf6 100644 --- a/src/isr.S +++ b/src/isr.S @@ -5,7 +5,7 @@ .section .text .global unhandledInterrupt -.global handleDEException, handleDFException, handleGPException +.global handleDEException, handleNMIInterrupt, handleDFException, handleGPException .global handleHardwareInterrupt0, handleHardwareInterrupt1 #define SaveContext \ @@ -21,15 +21,6 @@ cli; \ hlt -#define SaveContextForHardwareInterrupt(irq) \ - SaveContext \ - pushl $irq - -#define RestoreContextForHardwareInterrupt(irq) \ - addl $4, %esp; \ - RestoreContext - - // Generic handler unhandledInterrupt: SaveContext @@ -44,6 +35,14 @@ handleDEException: add $4, %esp RestoreContextAndHalt +// NMI interrupt +handleNMIInterrupt: + SaveContext + pushl $2 + call dispatchExceptionHandler + add $4, %esp + RestoreContextAndHalt + // Double fault handleDFException: SaveContext @@ -64,6 +63,14 @@ handleGPException: * Hardware Interrupts */ +#define SaveContextForHardwareInterrupt(irq) \ + SaveContext \ + pushl $irq + +#define RestoreContextForHardwareInterrupt(irq) \ + addl $4, %esp; \ + RestoreContext + handleHardwareInterrupt0: SaveContextForHardwareInterrupt(0) call dispatchHardwareInterrupt