Add kernel panic function

This commit is contained in:
Bananymous 2022-11-14 18:53:00 +02:00
parent b185ed4fd3
commit 9e933a5ec5
4 changed files with 31 additions and 2 deletions

View File

@ -30,6 +30,7 @@ LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
KERNEL_OBJS=\
$(KERNEL_ARCH_OBJS) \
kernel/kernel.o \
kernel/panic.o \
kernel/ssp.o \
OBJS=\

View File

@ -0,0 +1,9 @@
#pragma once
namespace Kernel
{
__attribute__((__noreturn__))
void panic(const char* message);
}

16
kernel/kernel/panic.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <kernel/panic.h>
#include <kernel/tty.h>
namespace Kernel
{
__attribute__((__noreturn__))
void panic(const char* message)
{
terminal_writestring("Kernel panic: ");
terminal_writestring(message);
asm volatile("hlt");
__builtin_unreachable();
}
}

View File

@ -1,12 +1,15 @@
#include <stdlib.h>
#include <stdio.h>
#if defined(__is_libk)
#include <kernel/panic.h>
#endif
__attribute__((__noreturn__))
void abort(void)
{
#if defined(__is_libk)
printf("Kernel panic: abort()\n");
asm volatile("hlt");
Kernel::panic("abort()");
#else
printf("abort()\n");
#endif