1#pragma once
2#include <asm.h>
3#include <compiler.h>
4#include <limine.h>
5
6void debug_print_stack();
7extern void panic_entry();
8void panic_broadcast_nmi();
9typedef __noreturn void (*panic_handler_t)(const char *file, int line,
10 const char *func, const char *fmt,
11 ...);
12
13static inline void qemu_exit(int code) {
14 outb(port: 0xf4, value: ((code << 1) | 1) & 0xFF);
15}
16
17struct panic_hook {
18 _Atomic panic_handler_t impl;
19 bool enabled;
20};
21
22struct panic_regs {
23 uint64_t rsp;
24 uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
25 uint64_t rsi, rdi, rbp, rdx, rcx, rbx, rax;
26};
27
28__noreturn void panic_impl_default(const char *file, int line, const char *func,
29 const char *fmt, ...);
30
31#define panic(fmt, ...) \
32 panic_impl_default(__FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__)
33
34#define panic_with_impl(hook, fmt, ...) \
35 hook.impl(__FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__)
36
37#define oops(fmt, ...)
38