2026-02-08 12:17:27 +00:00
|
|
|
#include <mango/cpu.h>
|
2024-11-02 11:31:51 +00:00
|
|
|
#include <mango/libc/stdio.h>
|
2026-02-08 12:17:27 +00:00
|
|
|
#include <mango/machine/panic.h>
|
2024-11-02 11:31:51 +00:00
|
|
|
#include <mango/printk.h>
|
|
|
|
|
#include <mango/sched.h>
|
2026-02-08 12:17:27 +00:00
|
|
|
#include <stdarg.h>
|
2023-04-09 16:35:15 +01:00
|
|
|
|
|
|
|
|
static int has_panicked = 0;
|
|
|
|
|
|
2026-02-08 12:17:27 +00:00
|
|
|
void panic_irq(struct ml_cpu_context *ctx, const char *fmt, ...)
|
2023-04-09 16:35:15 +01:00
|
|
|
{
|
|
|
|
|
char buf[512];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
printk("---[ kernel panic: %s", buf);
|
|
|
|
|
printk("kernel: " BUILD_ID ", compiler version: " __VERSION__);
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct task *task = current_task();
|
|
|
|
|
struct thread *thr = current_thread();
|
2023-04-09 16:35:15 +01:00
|
|
|
|
|
|
|
|
if (task && thr) {
|
2026-02-08 12:17:27 +00:00
|
|
|
printk("task: %s (id: %d, thread: %d)",
|
|
|
|
|
task->t_name,
|
|
|
|
|
task->t_id,
|
|
|
|
|
thr->tr_id);
|
2023-04-09 16:35:15 +01:00
|
|
|
} else {
|
|
|
|
|
printk("task: [bootstrap]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printk("cpu: %u", this_cpu());
|
|
|
|
|
|
2023-05-03 19:22:12 +01:00
|
|
|
ml_print_cpu_state(ctx);
|
2023-04-09 16:35:15 +01:00
|
|
|
|
|
|
|
|
if (READ_ONCE(has_panicked)) {
|
|
|
|
|
ml_halt_cpu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WRITE_ONCE(has_panicked, 1);
|
|
|
|
|
|
2023-05-06 22:18:34 +01:00
|
|
|
if (ctx) {
|
|
|
|
|
ml_print_stack_trace_irq(ctx);
|
|
|
|
|
} else {
|
|
|
|
|
uintptr_t ip = (uintptr_t)__builtin_return_address(0);
|
|
|
|
|
ml_print_stack_trace(ip);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 16:35:15 +01:00
|
|
|
printk("---[ end kernel panic: %s", buf);
|
|
|
|
|
ml_halt_cpu();
|
|
|
|
|
}
|