all kernel headers have been moved from include/mango to include/kernel and include definitions that are only relevant to kernel-space. any definitions that are relevant to both kernel- and user-space (i.e. type definitions, syscall IDs) have been moved to include/mango within libmango.
53 lines
1.0 KiB
C
53 lines
1.0 KiB
C
#include <kernel/cpu.h>
|
|
#include <kernel/libc/stdio.h>
|
|
#include <kernel/machine/panic.h>
|
|
#include <kernel/printk.h>
|
|
#include <kernel/sched.h>
|
|
#include <stdarg.h>
|
|
|
|
static int has_panicked = 0;
|
|
|
|
void panic_irq(struct ml_cpu_context *ctx, const char *fmt, ...)
|
|
{
|
|
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__);
|
|
|
|
struct task *task = current_task();
|
|
struct thread *thr = current_thread();
|
|
|
|
if (task && thr) {
|
|
printk("task: %s (id: %d, thread: %d)",
|
|
task->t_name,
|
|
task->t_id,
|
|
thr->tr_id);
|
|
} else {
|
|
printk("task: [bootstrap]");
|
|
}
|
|
|
|
printk("cpu: %u", this_cpu());
|
|
|
|
ml_print_cpu_state(ctx);
|
|
|
|
if (READ_ONCE(has_panicked)) {
|
|
ml_halt_cpu();
|
|
}
|
|
|
|
WRITE_ONCE(has_panicked, 1);
|
|
|
|
if (ctx) {
|
|
ml_print_stack_trace_irq(ctx);
|
|
} else {
|
|
uintptr_t ip = (uintptr_t)__builtin_return_address(0);
|
|
ml_print_stack_trace(ip);
|
|
}
|
|
|
|
printk("---[ end kernel panic: %s", buf);
|
|
ml_halt_cpu();
|
|
}
|