2023-01-09 14:56:20 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-25 21:39:03 +02:00
|
|
|
#include <kernel/Debug.h>
|
2023-01-09 14:56:20 +02:00
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
#define panic(...) detail::panic_impl(__FILE__, __LINE__, __VA_ARGS__)
|
2023-01-09 14:56:20 +02:00
|
|
|
|
2023-04-16 00:04:49 +03:00
|
|
|
namespace Kernel::detail
|
2023-01-09 14:56:20 +02:00
|
|
|
{
|
|
|
|
|
2023-04-16 00:04:49 +03:00
|
|
|
extern bool g_paniced;
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
__attribute__((__noreturn__))
|
2023-10-30 16:17:26 +02:00
|
|
|
static void panic_impl(const char* file, int line, const char* message, Args&&... args)
|
2023-01-09 14:56:20 +02:00
|
|
|
{
|
2023-04-16 00:04:49 +03:00
|
|
|
asm volatile("cli");
|
|
|
|
derrorln("Kernel panic at {}:{}", file, line);
|
2023-10-30 16:17:26 +02:00
|
|
|
derrorln(message, BAN::forward<Args>(args)...);
|
2023-04-16 00:04:49 +03:00
|
|
|
if (!g_paniced)
|
2023-02-01 21:05:44 +02:00
|
|
|
{
|
2023-04-16 00:04:49 +03:00
|
|
|
g_paniced = true;
|
2023-02-01 21:05:44 +02:00
|
|
|
Debug::dump_stack_trace();
|
|
|
|
}
|
2023-04-16 00:04:49 +03:00
|
|
|
for (;;)
|
|
|
|
asm volatile("hlt");
|
|
|
|
__builtin_unreachable();
|
2023-01-09 14:56:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|