Add some system exception handlers and clean up assemply a bit

This commit is contained in:
Eryn Wells 2016-03-13 19:33:10 -04:00
parent 0948c0cc46
commit 7a15e00cc2
2 changed files with 32 additions and 14 deletions

View file

@ -11,11 +11,10 @@
#include "IO.hh" #include "IO.hh"
extern "C" { extern "C" {
void dispatchExceptionHandler(size_t vector);
// Assembly functions. See isr.S. // Assembly functions. See isr.S.
void unhandledInterrupt(); void unhandledInterrupt();
void handleDEException(); void handleDEException();
void handleNMIInterrupt();
void handleDFException(); void handleDFException();
void handleGPException(); void handleGPException();
void handleHardwareInterrupt0(); void handleHardwareInterrupt0();
@ -50,14 +49,23 @@ InterruptHandler::initialize()
{ {
auto& console = kernel::Console::systemConsole(); auto& console = kernel::Console::systemConsole();
// All interrupts start out as "unhandled"
for (size_t i = 0; i < IDT::Size; i++) { for (size_t i = 0; i < IDT::Size; i++) {
mIDT.setDescriptor(i, IDT::DescriptorSpec::exceptionHandler(0x8, &unhandledInterrupt)); 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(0x20, IDT::DescriptorSpec::exceptionHandler(0x8, &handleHardwareInterrupt0));
mIDT.setDescriptor(0x21, IDT::DescriptorSpec::exceptionHandler(0x8, &handleHardwareInterrupt1)); 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. mPIC.initialize(0x20, 0x28); // Map hardware IRQs to interrupt vectors 32 through 48.
console.printString("Hardware interrupts initialized\n"); console.printString("Hardware interrupts initialized\n");
@ -164,6 +172,9 @@ InterruptHandler::finishHardwareInterrupt(uint8_t irq)
} /* namespace x86 */ } /* namespace x86 */
/*
* Interrupt handlers
*/
extern "C" extern "C"
void void

View file

@ -5,7 +5,7 @@
.section .text .section .text
.global unhandledInterrupt .global unhandledInterrupt
.global handleDEException, handleDFException, handleGPException .global handleDEException, handleNMIInterrupt, handleDFException, handleGPException
.global handleHardwareInterrupt0, handleHardwareInterrupt1 .global handleHardwareInterrupt0, handleHardwareInterrupt1
#define SaveContext \ #define SaveContext \
@ -21,15 +21,6 @@
cli; \ cli; \
hlt hlt
#define SaveContextForHardwareInterrupt(irq) \
SaveContext \
pushl $irq
#define RestoreContextForHardwareInterrupt(irq) \
addl $4, %esp; \
RestoreContext
// Generic handler // Generic handler
unhandledInterrupt: unhandledInterrupt:
SaveContext SaveContext
@ -44,6 +35,14 @@ handleDEException:
add $4, %esp add $4, %esp
RestoreContextAndHalt RestoreContextAndHalt
// NMI interrupt
handleNMIInterrupt:
SaveContext
pushl $2
call dispatchExceptionHandler
add $4, %esp
RestoreContextAndHalt
// Double fault // Double fault
handleDFException: handleDFException:
SaveContext SaveContext
@ -64,6 +63,14 @@ handleGPException:
* Hardware Interrupts * Hardware Interrupts
*/ */
#define SaveContextForHardwareInterrupt(irq) \
SaveContext \
pushl $irq
#define RestoreContextForHardwareInterrupt(irq) \
addl $4, %esp; \
RestoreContext
handleHardwareInterrupt0: handleHardwareInterrupt0:
SaveContextForHardwareInterrupt(0) SaveContextForHardwareInterrupt(0)
call dispatchHardwareInterrupt call dispatchHardwareInterrupt