summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-09-14 15:11:20 +0200
committerCarlos Maiolino <[email protected]>2025-09-14 15:11:20 +0200
commit9c7a059f64c86e5026cbbc5c6ae2f48be0f56c0c (patch)
tree752a262b102bb7a40e0296e06e7aa51ec14b1e16
parent364b023b2c50a7e810bf4f975150fc50c179e135 (diff)
Enable interrupts only after IDT is set
So far we've been playing a dangerous game... We enabled interrupts before we actually had the interrupt descriptor table setup. Fix this so we prevent IRQs to fire before the table is initialized and attempt to run garbage instead of code Signed-off-by: Carlos Maiolino <[email protected]>
-rw-r--r--src/idt/idt.asm9
-rw-r--r--src/include/toxic/idt.h2
-rw-r--r--src/kernel.asm2
-rw-r--r--src/kernel.c2
4 files changed, 13 insertions, 2 deletions
diff --git a/src/idt/idt.asm b/src/idt/idt.asm
index 235f46b..d15e565 100644
--- a/src/idt/idt.asm
+++ b/src/idt/idt.asm
@@ -6,7 +6,16 @@ extern default_int_handler
global int21h
global default_handler
global idt_load
+global enable_interrupts
+global disable_interrupts
+enable_interrupts:
+ sti
+ ret
+
+disable_interrupts:
+ cli
+ ret
idt_load:
push ebp
diff --git a/src/include/toxic/idt.h b/src/include/toxic/idt.h
index f54f7f7..175e84f 100644
--- a/src/include/toxic/idt.h
+++ b/src/include/toxic/idt.h
@@ -24,4 +24,6 @@ struct int_reg_descriptor {
} __attribute__((packed));
void interrupts_init(void);
+void enable_interrupts(void);
+void disable_interrupts(void);
#endif /* IDT_H */
diff --git a/src/kernel.asm b/src/kernel.asm
index bd22761..47f5f71 100644
--- a/src/kernel.asm
+++ b/src/kernel.asm
@@ -35,8 +35,6 @@ _start:
mov al, 00000001b ; Put the PIC in x86 mode
out 0x21, al
- sti
-
; Jump to C code
call start_kernel
jmp $
diff --git a/src/kernel.c b/src/kernel.c
index cd9f9d7..1605191 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -16,6 +16,8 @@ void start_kernel()
kernel_heap_init();
interrupts_init();
+ enable_interrupts();
+
void *ptr = kmalloc(50);
void *ptr2 = kmalloc(5000);