From 6677af27f6776b26e0ebe896e0ab7e5e44e3958c Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 9 Mar 2016 01:17:13 -0500 Subject: [PATCH] Rough outline of InterruptHandler --- src/Interrupts.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++ src/Interrupts.hh | 28 ++++++++++++++++++++++- src/SConscript | 1 + 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/Interrupts.cc diff --git a/src/Interrupts.cc b/src/Interrupts.cc new file mode 100644 index 0000000..3dd27ad --- /dev/null +++ b/src/Interrupts.cc @@ -0,0 +1,57 @@ +/* Interrupts.cc + * vim: set tw=80: + * Eryn Wells + */ +/** + * Implementation of interrupt handers and things. + */ + +#include "Interrupts.hh" + +namespace x86 { + +/* + * Static + */ + +InterruptHandler& +InterruptHandler::systemInterruptHandler() +{ + static InterruptHandler sInterruptHandler; + return sInterruptHandler; +} + +/* + * Public + */ + +InterruptHandler::InterruptHandler() + : mPIC(), + mIDT() +{ } + + +void +InterruptHandler::initialize() +{ + mIDT.load(); + mPIC.remap(0x20, 0x28, 2); // Map hardware IRQs to interrupt vectors 32 through 48. +} + + +void +InterruptHandler::enableInterrupts() + const +{ + asm("sti"); +} + + +void +InterruptHandler::disableInterrupts() + const +{ + asm("cli"); +} + +} /* namespace x86 */ diff --git a/src/Interrupts.hh b/src/Interrupts.hh index eccecc3..b579981 100644 --- a/src/Interrupts.hh +++ b/src/Interrupts.hh @@ -6,10 +6,18 @@ * Interrupts, exceptions. Spooky scary... */ +#ifndef __INTERRUPTS_HH__ +#define __INTERRUPTS_HH__ + +#include "Descriptors.hh" +#include "PIC.hh" + + namespace kernel { } /* namespace kernel */ + namespace x86 { enum class Interrupt { @@ -34,6 +42,24 @@ enum class Interrupt { XM = 19, // SIMD floating-point exception VE = 20, // Virtualization exception // Interrupts 21 through 31 reserved -} +}; + +struct InterruptHandler +{ + static InterruptHandler& systemInterruptHandler(); + + InterruptHandler(); + + void initialize(); + + void enableInterrupts() const; + void disableInterrupts() const; + +private: + PIC mPIC; + IDT mIDT; +}; } /* namespace x86 */ + +#endif /* __INTERRUPTS_HH__ */ diff --git a/src/SConscript b/src/SConscript index 65ec40c..b974fa5 100644 --- a/src/SConscript +++ b/src/SConscript @@ -12,6 +12,7 @@ files = [ 'Main.cc', 'Console.cc', 'Descriptors.cc', + 'Interrupts.cc', 'PIC.cc', 'cxa.cc', ]