Nucleus
Barry Kernel printf routines 120a213 (3 years, 2 months ago)
diff --git a/kernel/printf.c b/kernel/printf.c
new file mode 100644
index 0000000..d0d55fa
--- /dev/null
+++ b/kernel/printf.c
@@ -0,0 +1,50 @@
+/*
+ * This file implements the kernel printf routine and the debug print system
+ * call. These routines output to the debug port and do not print to the
+ * screen.
+ */
+
+#include <string.h>
+#include <nucleus/kernel.h>
+#include <nucleus/memory.h>
+#include <nucleus/task.h>
+#include <io.h>
+
+/* Print formatted text to debug port */
+void
+kprintf(char *fmt, ...)
+{
+ outb(0xE9, '\033');
+ outb(0xE9, '[');
+ outb(0xE9, '3');
+ outb(0xE9, '6');
+ outb(0xE9, 'm');
+
+ char buf[1024], *p = buf;
+
+ /* Print message to debug port */
+ va_list args;
+ va_start(args, fmt);
+ vsprintf(buf, fmt, args);
+ va_end(args);
+ while (*p)
+ outb(0xE9, *p++);
+ outb(0xE9, '\n');
+}
+
+/* Debug print */
+void
+dbgprintf(char *str)
+{
+ size_t len = 1024;
+ if (!str || !verify_access(str, strnlen(str, len), PROT_READ))
+ return;
+ char buf[1024], *p = buf;
+
+ /* Print message to debug port */
+ sprintf(buf, "\033[93;01m(%d:%d): \033[0m%s",
+ current->tgid, current->tid, str);
+ while (*p)
+ outb(0xE9, *p++);
+ outb(0xE9, '\n');
+}