From cd39d95a1ce1cf8ce6920978215d8b78db650406 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 13 Mar 2016 18:44:13 -0400 Subject: [PATCH] Move interrupt dispatch to InterruptHandler; make individual handlers private --- src/Interrupts.cc | 52 ++++++++++++++++++++++++++++++++--------------- src/Interrupts.hh | 9 +++++--- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/Interrupts.cc b/src/Interrupts.cc index dac2141..4fe4d68 100644 --- a/src/Interrupts.cc +++ b/src/Interrupts.cc @@ -52,6 +52,7 @@ InterruptHandler::initialize() for (size_t i = 0; i < IDT::Size; i++) { mIDT.setDescriptor(i, IDT::DescriptorSpec::exceptionHandler(0x8, &unhandledInterrupt)); } + mIDT.setDescriptor(0x20, IDT::DescriptorSpec::exceptionHandler(0x8, &handleHardwareInterrupt0)); mIDT.setDescriptor(0x21, IDT::DescriptorSpec::exceptionHandler(0x8, &handleHardwareInterrupt1)); mIDT.load(); @@ -83,15 +84,45 @@ InterruptHandler::disableInterrupts() void -InterruptHandler::postInterrupt(uint8_t interrupt) - const +InterruptHandler::dispatchHardwareInterrupt(uint8_t irq) { - asm("int %0": : "a"(interrupt)); + switch (irq) { + case 0: + doTimerInterrupt(); + break; + case 1: + doKeyboardInterrupt(); + break; + default: + // TODO: Implement a panic function... + break; + } + finishHardwareInterrupt(irq); +} + +/* + * Private + */ + +void +InterruptHandler::doTimerInterrupt() +{ + auto& console = kernel::Console::systemConsole(); + console.printString("Thyme!\n"); } void +InterruptHandler::doKeyboardInterrupt() +{ + auto& console = kernel::Console::systemConsole(); + console.printString("Key!\n"); +} + + +inline void InterruptHandler::finishHardwareInterrupt(uint8_t irq) + const { mPIC.endOfInterrupt(irq); } @@ -136,21 +167,10 @@ dispatchExceptionHandler(size_t vector) console.printString("\nAbort. :("); } -extern "C" -void -handleTimerInterrupt() -{ - auto& console = kernel::Console::systemConsole(); - console.printString("Thyme!\n"); -} extern "C" void -handleKeyboardInterrupt() +dispatchHardwareInterrupt(size_t irq) { - auto& console = kernel::Console::systemConsole(); - console.printString("Key!\n"); - - auto& interruptHandler = x86::InterruptHandler::systemInterruptHandler(); - interruptHandler.finishHardwareInterrupt(1); + x86::InterruptHandler::systemInterruptHandler().dispatchHardwareInterrupt(irq); } diff --git a/src/Interrupts.hh b/src/Interrupts.hh index 1829c64..897a054 100644 --- a/src/Interrupts.hh +++ b/src/Interrupts.hh @@ -55,13 +55,16 @@ struct InterruptHandler void enableInterrupts() const; void disableInterrupts() const; - void postInterrupt(uint8_t interrupt); - - void finishHardwareInterrupt(uint8_t irq); + void dispatchHardwareInterrupt(uint8_t irq); private: PIC mPIC; IDT mIDT; + + void doTimerInterrupt(); + void doKeyboardInterrupt(); + + void finishHardwareInterrupt(uint8_t irq) const; }; } /* namespace x86 */