summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authordzwdz2021-07-09 16:49:59 +0200
committerdzwdz2021-07-09 16:49:59 +0200
commit5cfe5443e678e3354ed3488baea9c91cbb9e7697 (patch)
treefb545397520ceb2580aa9df3086444ea72e121e3 /kernel
parent79dbeb367cc7b39e965c052ebb62076a2118c54c (diff)
interrupt self-test
Diffstat (limited to 'kernel')
-rw-r--r--kernel/idt.c8
-rw-r--r--kernel/isr.c8
-rw-r--r--kernel/isr.h6
3 files changed, 21 insertions, 1 deletions
diff --git a/kernel/idt.c b/kernel/idt.c
index e1d45b9..cd032d3 100644
--- a/kernel/idt.c
+++ b/kernel/idt.c
@@ -1,6 +1,7 @@
#include <kernel/gdt.h>
#include <kernel/idt.h>
#include <kernel/isr.h>
+#include <kernel/tty.h> // used only for the selftest
#include <stdbool.h>
#include <stdint.h>
@@ -51,7 +52,8 @@ static void idt_prepare() {
for (int i = 0; i < 256; i++)
IDT[i].present = 0;
- idt_add(0x8, false, isr_double_fault);
+ idt_add(0x08, false, isr_double_fault);
+ idt_add(0x34, false, isr_test_interrupt);
}
static void idt_load() {
@@ -62,6 +64,10 @@ static void idt_load() {
static void idt_test() {
asm("int $0x34" : : : "memory");
+ if (!isr_test_interrupt_called) {
+ tty_const("IDT self test failed");
+ for(;;);
+ }
}
void idt_init() {
diff --git a/kernel/isr.c b/kernel/isr.c
index 69c688b..331e9a5 100644
--- a/kernel/isr.c
+++ b/kernel/isr.c
@@ -1,9 +1,17 @@
#include <kernel/isr.h>
#include <kernel/tty.h>
+#include <stdbool.h>
#include <stdint.h>
+bool isr_test_interrupt_called = false;
+
__attribute__((interrupt))
void isr_double_fault(struct interrupt_frame *frame) {
tty_const("#DF");
for(;;);
}
+
+__attribute__((interrupt))
+void isr_test_interrupt(struct interrupt_frame *frame) {
+ isr_test_interrupt_called = true;
+}
diff --git a/kernel/isr.h b/kernel/isr.h
index 7230986..624e9ad 100644
--- a/kernel/isr.h
+++ b/kernel/isr.h
@@ -1,6 +1,12 @@
#pragma once
+#include <stdbool.h>
struct interrupt_frame;
+extern bool isr_test_interrupt_called; // used in the self-test in idt.c
+
__attribute__((interrupt))
void isr_double_fault(struct interrupt_frame *frame);
+
+__attribute__((interrupt))
+void isr_test_interrupt(struct interrupt_frame *frame);