diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 9c88bc1d6a..7e25c039e8 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -27,6 +27,7 @@ set(KERNEL_SOURCES kernel/kernel.cpp kernel/Memory/Heap.cpp kernel/Memory/kmalloc.cpp + kernel/Panic.cpp kernel/PCI.cpp kernel/PIC.cpp kernel/PIT.cpp diff --git a/kernel/include/kernel/Panic.h b/kernel/include/kernel/Panic.h index 75e15b8d88..74d82ecae0 100644 --- a/kernel/include/kernel/Panic.h +++ b/kernel/include/kernel/Panic.h @@ -4,23 +4,26 @@ #define panic(...) detail::panic_impl(__FILE__, __LINE__, __VA_ARGS__) -namespace Kernel +namespace Kernel::detail { - namespace detail + extern bool g_paniced; + + template + __attribute__((__noreturn__)) + static void panic_impl(const char* file, int line, const char* message, Args... args) { - template - __attribute__((__noreturn__)) - static void panic_impl(const char* file, int line, const char* message, Args... args) + asm volatile("cli"); + derrorln("Kernel panic at {}:{}", file, line); + derrorln(message, args...); + if (!g_paniced) { - asm volatile("cli"); - derrorln("Kernel panic at {}:{}", file, line); - derrorln(message, args...); + g_paniced = true; Debug::dump_stack_trace(); - for (;;) - asm volatile("hlt"); - __builtin_unreachable(); } + for (;;) + asm volatile("hlt"); + __builtin_unreachable(); } } \ No newline at end of file diff --git a/kernel/kernel/Panic.cpp b/kernel/kernel/Panic.cpp new file mode 100644 index 0000000000..1c0ad8a7a5 --- /dev/null +++ b/kernel/kernel/Panic.cpp @@ -0,0 +1,6 @@ +#include + +namespace Kernel::detail +{ + bool g_paniced = false; +}