summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2021-07-09 18:27:47 +0200
committerdzwdz2021-07-09 18:27:47 +0200
commit9566dac198f685ef947d82facee0be182a77495e (patch)
tree1e09721f226bf3293e11f37777f2964a2c59d529
parent5cfe5443e678e3354ed3488baea9c91cbb9e7697 (diff)
implement basic kernel panics
-rw-r--r--kernel/isr.c3
-rw-r--r--kernel/main.c8
-rw-r--r--kernel/panic.h14
-rw-r--r--kernel/proc.c2
-rw-r--r--platform/asm.h (renamed from platform/sysenter.h)5
-rw-r--r--platform/boot.s5
6 files changed, 30 insertions, 7 deletions
diff --git a/kernel/isr.c b/kernel/isr.c
index 331e9a5..e6a9871 100644
--- a/kernel/isr.c
+++ b/kernel/isr.c
@@ -1,4 +1,5 @@
#include <kernel/isr.h>
+#include <kernel/panic.h>
#include <kernel/tty.h>
#include <stdbool.h>
#include <stdint.h>
@@ -8,7 +9,7 @@ bool isr_test_interrupt_called = false;
__attribute__((interrupt))
void isr_double_fault(struct interrupt_frame *frame) {
tty_const("#DF");
- for(;;);
+ panic();
}
__attribute__((interrupt))
diff --git a/kernel/main.c b/kernel/main.c
index bc1e0d3..85a85d6 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -1,9 +1,10 @@
#include <kernel/gdt.h>
#include <kernel/idt.h>
#include <kernel/mem.h>
+#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/tty.h>
-#include <platform/sysenter.h>
+#include <platform/asm.h>
void r3_test();
@@ -23,7 +24,6 @@ void kmain()
void r3_test() {
tty_const("ok");
- asm("cli"); // privileged instruction, should cause a GP
- tty_const(" this shouldn't happen");
- for (;;) {}
+ asm("cli");
+ panic();
}
diff --git a/kernel/panic.h b/kernel/panic.h
new file mode 100644
index 0000000..7d2ea5f
--- /dev/null
+++ b/kernel/panic.h
@@ -0,0 +1,14 @@
+#pragma once
+#include <kernel/tty.h>
+#include <platform/asm.h>
+
+// dumb c shit
+#define panic_tostr2(x) #x
+#define panic_tostr(x) panic_tostr2(x)
+
+#define panic() do { \
+ tty_const(" PANIC! at the "); \
+ tty_const(__func__); \
+ tty_const(" (" __FILE__ ":" panic_tostr(__LINE__) ") "); \
+ halt_cpu(); \
+} while (0)
diff --git a/kernel/proc.c b/kernel/proc.c
index 959ef94..776238c 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -1,6 +1,6 @@
#include <kernel/mem.h>
#include <kernel/proc.h>
-#include <platform/sysenter.h>
+#include <platform/asm.h>
struct process *process_current;
diff --git a/platform/sysenter.h b/platform/asm.h
index b0495cc..6f72617 100644
--- a/platform/sysenter.h
+++ b/platform/asm.h
@@ -1,4 +1,9 @@
#pragma once
+// boot.s
+__attribute__((noreturn))
+void halt_cpu();
+
+// sysenter.c
void sysexit(void (*fun)(), void *stack_top);
void sysenter_setup();
diff --git a/platform/boot.s b/platform/boot.s
index 6052347..c2a06c3 100644
--- a/platform/boot.s
+++ b/platform/boot.s
@@ -27,7 +27,10 @@ _start:
mov $stack_top, %esp
call kmain
- cli /* disable interrupts */
+.global halt_cpu
+.type halt_cpu, @function
+halt_cpu:
+ cli
1: hlt
jmp 1b