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"
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

View file

@ -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