From ef1166f6e83d72df360a6dfc2f6643d826ce07ba Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Mon, 12 Apr 2021 15:10:16 +0000 Subject: panic() and halt() now in kernel private interface --- kernel/Makefile | 3 ++- kernel/entry_efi.c | 12 ++---------- kernel/panic.c | 21 +++++++++++++++++++++ kernel/panic.h | 12 ++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 kernel/panic.c create mode 100644 kernel/panic.h 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(" 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 + +enum panic_reason +{ + GENERAL_PANIC, + UNHANDLED_FAULT, +}; + +noreturn void panic(enum panic_reason reason); +noreturn void halt(void); -- cgit v1.3.1-1-g115d