summaryrefslogtreecommitdiff
path: root/src/idt/idt.c
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-08-01 21:03:16 +0200
committerCarlos Maiolino <[email protected]>2025-08-01 21:03:16 +0200
commit2725b95a1f78d2feac553d37252f2e560c2f9aac (patch)
tree3e68aaf21c25fc2a46e3ee29fb4f23b188e3b3a4 /src/idt/idt.c
parent57d8e2b236c7a185bdd941c247ef0dcc5961a24e (diff)
Setup interrupt handling
Remap master PIC to IOAddress 0x20 to avoid collisions with CPU exceptions. Setup a default interrupt handler and map all interrupts to this handler by default. Setup a Keyboard interrupt handler for testing purposes Wire everything up in the Makefile Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'src/idt/idt.c')
-rw-r--r--src/idt/idt.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/idt/idt.c b/src/idt/idt.c
index d7a6743..a83c612 100644
--- a/src/idt/idt.c
+++ b/src/idt/idt.c
@@ -3,11 +3,28 @@
#include <toxic/string.h>
#include <toxic/vga.h>
#include <toxic/idt.h>
+#include <toxic/io.h>
struct int_descriptor int_table[TOTAL_INTERRUPTS];
struct int_reg_descriptor idtr_descriptor;
extern void idt_load(struct int_reg_descriptor *desc);
+extern void int21h();
+extern void default_handler();
+
+void
+int21h_handler(void)
+{
+ vprintl("Keyboard pressed\n");
+ outb(0x20, 0x20);
+}
+
+void
+default_int_handler(void)
+{
+ /* Ack the Interrupt */
+ outb(0x20, 0x20);
+}
static void
idt_zero()
@@ -30,12 +47,18 @@ idt_set(int int_num, void *addr)
void
interrupts_init(void)
{
+ int i;
+
memset(int_table, 0, sizeof(int_table));
idtr_descriptor.limit = sizeof(int_table) - 1;
idtr_descriptor.base = (uint32_t) int_table;
+ for (i = 0; i < TOTAL_INTERRUPTS; i++)
+ idt_set(i, default_handler);
+
idt_set(0, idt_zero);
+ idt_set(0x21, int21h);
idt_load(&idtr_descriptor);
}