Nucleus
Barry Kernel printf routines 120a213 (3 years, 2 months ago)
diff --git a/kernel/panic.c b/kernel/panic.c
new file mode 100644
index 0000000..a489a0a
--- /dev/null
+++ b/kernel/panic.c
@@ -0,0 +1,37 @@
+/*
+ * 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 */
+ asm volatile("cli");
+ while (1)
+ asm volatile("hlt");
+ __builtin_unreachable();
+}