aboutsummaryrefslogtreecommitdiff
path: root/src/idt.cc
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-02-28 22:39:25 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-02-28 22:39:25 +0200
commitae4265ea5d77b68757af39d73fe47df1a3563b42 (patch)
tree7282e3d43c471b195bb5a4742ed911c7b7626dcb /src/idt.cc
parentFix interrupts causing exception 0xd (diff)
downloadkernel.cpp-ae4265ea5d77b68757af39d73fe47df1a3563b42.tar.xz
Add keyboard driver
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');
}