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
|
|
|
|
2024-03-04 11:41:54 +02:00
|
|
|
#define __panic_stringify_helper(s) #s
|
|
|
|
#define __panic_stringify(s) __panic_stringify_helper(s)
|
2023-01-09 14:56:20 +02:00
|
|
|
|
2024-03-04 11:41:54 +02:00
|
|
|
#define panic(...) panic_impl(__FILE__ ":" __panic_stringify(__LINE__), __VA_ARGS__)
|
|
|
|
|
|
|
|
namespace Kernel
|
2023-01-09 14:56:20 +02:00
|
|
|
{
|
|
|
|
|
2024-03-04 11:41:54 +02:00
|
|
|
extern volatile bool g_paniced;
|
2023-04-16 00:04:49 +03:00
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
__attribute__((__noreturn__))
|
2024-03-04 11:41:54 +02:00
|
|
|
static void panic_impl(const char* location, const char* message, Args&&... args)
|
2023-01-09 14:56:20 +02:00
|
|
|
{
|
2023-04-16 00:04:49 +03:00
|
|
|
asm volatile("cli");
|
2024-09-18 00:56:02 +03:00
|
|
|
|
|
|
|
const bool had_debug_lock = Debug::s_debug_lock.current_processor_has_lock();
|
2024-03-04 11:41:54 +02:00
|
|
|
derrorln("Kernel panic at {}", location);
|
2024-09-18 00:56:02 +03:00
|
|
|
if (had_debug_lock)
|
|
|
|
derrorln(" while having debug lock...");
|
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();
|
|
|
|
}
|
2024-03-04 11:41:54 +02:00
|
|
|
asm volatile("ud2");
|
2024-06-18 20:32:43 +03:00
|
|
|
__builtin_unreachable();
|
2023-01-09 14:56:20 +02:00
|
|
|
}
|
|
|
|
|
2024-01-24 14:43:46 +02:00
|
|
|
}
|