aboutsummaryrefslogtreecommitdiff
path: root/src/idt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/idt.cc')
-rw-r--r--src/idt.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/idt.cc b/src/idt.cc
index fefe53e..68ae260 100644
--- a/src/idt.cc
+++ b/src/idt.cc
@@ -4,7 +4,23 @@
#include "ports.h"
static_assert(sizeof(IDT::Pointer) == 6);
-static_assert(sizeof(IDT::Entry) == 8); // size of IDT::Entry in protected mode is 64 bits
+
+static InterruptHandler* handlers[256] = {nullptr};
+
+bool IDT::install(uint8_t irq, InterruptHandler* h) {
+ if (h != nullptr && handlers[irq] == nullptr) {
+ handlers[irq] = h;
+ return true;
+ }
+ return false;
+}
+bool IDT::uninstall(uint8_t irq, InterruptHandler* h) {
+ if (handlers[irq] == h) {
+ handlers[irq] = nullptr;
+ return true;
+ }
+ return false;
+}
/* reinitialize the PIC controllers, giving them specified vector offsets
rather than 8h and 70h, as configured by default */
@@ -22,7 +38,10 @@ static_assert(sizeof(IDT::Entry) == 8); // size of IDT::Entry in protected mode
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
extern "C" uint32_t handle_interrupt(uint8_t irq, uint32_t esp) {
- printk("interrupt ", uhex{irq}, '\n');
+ if (handlers[irq] != nullptr) {
+ handlers[irq]->trigger();
+ }
+
pic1_t pic1;
pic1.write(0x20);
if (irq > 7) {
@@ -91,7 +110,6 @@ IDT::IDT(const uint16_t selector) {
Pointer ptr{.limit = sizeof(table), .base = reinterpret_cast<uint32_t>(table)};
asm volatile("lidt %0" : : "m"(ptr));
- asm volatile("sti");
printk("IDT installed at ", uhex{ptr.base}, '\n');
}