BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / d46e09a34ca8cd546f3a4312976cf3b6a5a55ccf / kernel / panic.c

// Related

Nucleus

Barry Improved context switching and interrupt handling d46e09a (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/kernel.h>
#include <io.h>

/* Kernel panic */
_Noreturn void
panic(char *fmt, ...)
{
	outb(0xE9, '\033');
	outb(0xE9, '[');
	outb(0xE9, '3');
	outb(0xE9, '1');
	outb(0xE9, 'm');

	char buf[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 processor */
	while (1) asm volatile("cli; hlt");
	__builtin_unreachable();
}