diff options
| author | Ada Christine <adachristine18@gmail.com> | 2021-04-12 15:10:16 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2021-04-12 15:10:16 +0000 |
| commit | ef1166f6e83d72df360a6dfc2f6643d826ce07ba (patch) | |
| tree | 1363fee07ae473b2bf81bb863792e58b1d53bb90 /kernel | |
| parent | ce2c1768fc9c0537136ff0af563766e23f2e9355 (diff) | |
panic() and halt() now in kernel private interface
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/Makefile | 3 | ||||
| -rw-r--r-- | kernel/entry_efi.c | 12 | ||||
| -rw-r--r-- | kernel/panic.c | 21 | ||||
| -rw-r--r-- | kernel/panic.h | 12 |
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); |
