summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/Makefile3
-rw-r--r--kernel/entry_efi.c12
-rw-r--r--kernel/panic.c21
-rw-r--r--kernel/panic.h12
4 files changed, 37 insertions, 11 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index da4591d..7caf69c 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -19,7 +19,8 @@ LOADLIBES := -lgcc
SOBJS :=
GOBJS := entry_efi.o kprint.o serial.o port.o main.o memory.o \
- memset.o memcpy.o memmove.o memcmp.o cpu.o exceptions.o
+ memset.o memcpy.o memmove.o memcmp.o cpu.o exceptions.o \
+ panic.o
IOBJS :=
$(SOBJS): CFLAGS += -fPIC
diff --git a/kernel/entry_efi.c b/kernel/entry_efi.c
index 7d8e058..f4eeb9c 100644
--- a/kernel/entry_efi.c
+++ b/kernel/entry_efi.c
@@ -10,8 +10,7 @@
#include "serial.h"
#include "kprint.h"
#include "memory.h"
-
-static noreturn void hang(void);
+#include "panic.h"
static void efi_memory_init(struct efi_memory_map_data *map)
{
@@ -65,12 +64,5 @@ noreturn void kernel_entry(struct efi_boot_data *data)
serial_init();
kputs("<hacker voice> i'm in\r\n");
efi_memory_init(data->memory_map);
- hang();
+ halt();
}
-
-static noreturn void hang(void)
-{
- __asm__ ("cli\n\t");
- while (true) __asm__ ("hlt\n\t");
-}
-
diff --git a/kernel/panic.c b/kernel/panic.c
new file mode 100644
index 0000000..7a3a729
--- /dev/null
+++ b/kernel/panic.c
@@ -0,0 +1,21 @@
+#include "panic.h"
+
+static char const *reason_strings[] = {
+ "general panic",
+ "unhandled fault",
+};
+
+noreturn void panic(enum panic_reason reason)
+{
+ // TODO: kprintf() and friends
+ kputs("kernel panic: ")
+ kputs(reason_strings[reason]);
+ kputs("\n");
+ halt();
+}
+
+noreturn void halt(void)
+{
+ __asm__ ("cli\n\t");
+ while (true) __asm__ ("hlt\n\t");
+}
diff --git a/kernel/panic.h b/kernel/panic.h
new file mode 100644
index 0000000..8c6bda7
--- /dev/null
+++ b/kernel/panic.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <stdnoreturn.h>
+
+enum panic_reason
+{
+ GENERAL_PANIC,
+ UNHANDLED_FAULT,
+};
+
+noreturn void panic(enum panic_reason reason);
+noreturn void halt(void);