Nucleus
Barry System headers (remove libc dependency) 18495cf (3 years, 2 months ago)
/*
* This file implements the kernel panic routine. It prints the error message
* to the debug port then halts the system. Since nothing runs after this, it
* is essentially a shutdown routine. In an idea kernel, this wouldn't need to
* be compiled in.
*/
#include <nucleus/cpu.h>
#include <nucleus/io.h>
#include <nucleus/kernel.h>
#include <nucleus/lib.h>
/* Kernel panic */
_Noreturn void
panic(char *fmt, ...)
{
if (!fmt)
goto halt;
Processor *proc;
for_each_cpu(proc) {
if (proc == cpu->self)
continue;
send_ipiq(proc->id, (ipiq_func_t) panic, NULL, IPIQ_ASYNC);
}
outb(0xE9, '\033');
outb(0xE9, '[');
outb(0xE9, '3');
outb(0xE9, '1');
outb(0xE9, 'm');
char buf[1024], *p = buf;
memset(buf, 0, 1024);
sprintf(buf, "[CPU#%d] ", cpu->id);
while (*p)
outb(0xE9, *p++);
memset(buf, 0, 1024);
p = buf;
/* Print error to serial port */
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
while (*p)
outb(0xE9, *p++);
outb(0xE9, '\n');
halt:
/* Halt processor */
while (1) asm volatile("cli; hlt");
__builtin_unreachable();
}