kernel/sys/panic.c

47 lines
1.1 KiB
C
Raw Normal View History

2020-01-27 21:42:49 +02:00
#if defined(AMD64_SMP)
2020-02-04 12:45:15 +02:00
#include "arch/amd64/smp/ipi.h"
#include "arch/amd64/smp/smp.h"
#endif
#include "sys/thread.h"
#include "sys/sched.h"
2019-10-12 13:40:48 +03:00
#include "sys/panic.h"
#include "sys/debug.h"
void panicf(const char *fmt, ...) {
2020-06-11 17:11:24 +03:00
uintptr_t rbp;
asm volatile ("movq %%rbp, %0":"=r"(rbp));
2019-10-12 13:40:48 +03:00
asm volatile ("cli");
va_list args;
2020-10-04 15:48:11 +03:00
kfatal("--- Panic (cpu%d) ---\n", get_cpu()->processor_id);
2019-10-12 13:40:48 +03:00
if (sched_ready) {
2020-07-26 21:47:38 +03:00
debugs(DEBUG_FATAL, "\033[41m");
thread_dump(DEBUG_FATAL, thread_self);
2020-07-26 21:47:38 +03:00
debugs(DEBUG_FATAL, "\033[0m");
}
2019-10-12 13:40:48 +03:00
va_start(args, fmt);
2020-01-14 11:32:06 +02:00
debugs(DEBUG_FATAL, "\033[41m");
2019-10-12 13:40:48 +03:00
debugfv(DEBUG_FATAL, fmt, args);
va_end(args);
2020-06-11 23:49:26 +03:00
debugs(DEBUG_FATAL, "Call trace:\n");
debug_backtrace(DEBUG_FATAL, rbp, 0, 10);
2020-06-11 23:49:26 +03:00
debugs(DEBUG_FATAL, "\033[0,");
2020-06-11 17:11:24 +03:00
2019-10-12 13:40:48 +03:00
kfatal("--- Panic ---\n");
2020-01-27 21:42:49 +02:00
#if defined(AMD64_SMP)
// Send PANIC IPIs to all other CPUs
size_t cpu = get_cpu()->processor_id;
for (size_t i = 0; i < smp_ncpus; ++i) {
if (i != cpu) {
amd64_ipi_send(i, IPI_VECTOR_PANIC);
}
}
#endif
2019-10-12 13:40:48 +03:00
panic_hlt();
}