From 9566dac198f685ef947d82facee0be182a77495e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 9 Jul 2021 18:27:47 +0200 Subject: implement basic kernel panics --- kernel/isr.c | 3 ++- kernel/main.c | 8 ++++---- kernel/panic.h | 14 ++++++++++++++ kernel/proc.c | 2 +- platform/asm.h | 9 +++++++++ platform/boot.s | 5 ++++- platform/sysenter.h | 4 ---- 7 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 kernel/panic.h create mode 100644 platform/asm.h delete mode 100644 platform/sysenter.h 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 +#include #include #include #include @@ -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 #include #include +#include #include #include -#include +#include 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 +#include + +// 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 #include -#include +#include struct process *process_current; diff --git a/platform/asm.h b/platform/asm.h new file mode 100644 index 0000000..6f72617 --- /dev/null +++ b/platform/asm.h @@ -0,0 +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 diff --git a/platform/sysenter.h b/platform/sysenter.h deleted file mode 100644 index b0495cc..0000000 --- a/platform/sysenter.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -void sysexit(void (*fun)(), void *stack_top); -void sysenter_setup(); -- cgit v1.2.3