Move interrupt dispatch to InterruptHandler; make individual handlers private

This commit is contained in:
Eryn Wells 2016-03-13 18:44:13 -04:00
parent 683b79fa07
commit cd39d95a1c
2 changed files with 42 additions and 19 deletions

View file

@ -52,6 +52,7 @@ InterruptHandler::initialize()
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));
} }
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(); mIDT.load();
@ -83,15 +84,45 @@ InterruptHandler::disableInterrupts()
void void
InterruptHandler::postInterrupt(uint8_t interrupt) InterruptHandler::dispatchHardwareInterrupt(uint8_t irq)
const
{ {
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 void
InterruptHandler::doKeyboardInterrupt()
{
auto& console = kernel::Console::systemConsole();
console.printString("Key!\n");
}
inline void
InterruptHandler::finishHardwareInterrupt(uint8_t irq) InterruptHandler::finishHardwareInterrupt(uint8_t irq)
const
{ {
mPIC.endOfInterrupt(irq); mPIC.endOfInterrupt(irq);
} }
@ -136,21 +167,10 @@ dispatchExceptionHandler(size_t vector)
console.printString("\nAbort. :("); console.printString("\nAbort. :(");
} }
extern "C"
void
handleTimerInterrupt()
{
auto& console = kernel::Console::systemConsole();
console.printString("Thyme!\n");
}
extern "C" extern "C"
void void
handleKeyboardInterrupt() dispatchHardwareInterrupt(size_t irq)
{ {
auto& console = kernel::Console::systemConsole(); x86::InterruptHandler::systemInterruptHandler().dispatchHardwareInterrupt(irq);
console.printString("Key!\n");
auto& interruptHandler = x86::InterruptHandler::systemInterruptHandler();
interruptHandler.finishHardwareInterrupt(1);
} }

View file

@ -55,13 +55,16 @@ struct InterruptHandler
void enableInterrupts() const; void enableInterrupts() const;
void disableInterrupts() const; void disableInterrupts() const;
void postInterrupt(uint8_t interrupt); void dispatchHardwareInterrupt(uint8_t irq);
void finishHardwareInterrupt(uint8_t irq);
private: private:
PIC mPIC; PIC mPIC;
IDT mIDT; IDT mIDT;
void doTimerInterrupt();
void doKeyboardInterrupt();
void finishHardwareInterrupt(uint8_t irq) const;
}; };
} /* namespace x86 */ } /* namespace x86 */