BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 120a213e731827cb653242e5dc4b39229a539cb9 / kernel

// Related

Nucleus

Barry Kernel printf routines 120a213 (3 years, 2 months ago)
diff --git a/kernel/acpi/acpi.c b/kernel/acpi/acpi.c
index 431d471..64443b1 100644
--- a/kernel/acpi/acpi.c
+++ b/kernel/acpi/acpi.c
@@ -5,7 +5,7 @@
 
 #include <stdint.h>
 #include <string.h>
-#include <nucleus/panic.h>
+#include <nucleus/kernel.h>
 #include <nucleus/memory.h>
 #include "acpi.h"
 
diff --git a/kernel/acpi/dsdt.c b/kernel/acpi/dsdt.c
index 23b8178..15510a1 100644
--- a/kernel/acpi/dsdt.c
+++ b/kernel/acpi/dsdt.c
@@ -4,7 +4,7 @@
  * information on IO ports, IRQs, memory mappings and power management.
  */
 
-#include <nucleus/panic.h>
+#include <nucleus/kernel.h>
 #include <io.h>
 #include "acpi.h"
 
diff --git a/kernel/gdt.c b/kernel/gdt.c
index 21fcc14..bd083a6 100644
--- a/kernel/gdt.c
+++ b/kernel/gdt.c
@@ -11,7 +11,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <nucleus/memory.h>
-#include <nucleus/panic.h>
+#include <nucleus/kernel.h>
 #include <nucleus/cpu.h>
 #include "desc.h"
 
diff --git a/kernel/idt.c b/kernel/idt.c
index 0a93c55..d835d15 100644
--- a/kernel/idt.c
+++ b/kernel/idt.c
@@ -8,8 +8,8 @@
 #include <stdint.h>
 #include <string.h>
 #include <nucleus/cpu.h>
+#include <nucleus/kernel.h>
 #include <nucleus/memory.h>
-#include <nucleus/panic.h>
 #include <nucleus/task.h>
 #include <io.h>
 #include "desc.h"
diff --git a/kernel/main.c b/kernel/main.c
index aa2373a..5d95c4a 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -9,7 +9,7 @@
 #include <unistd.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
-#include <nucleus/panic.h>
+#include <nucleus/kernel.h>
 #include <nucleus/memory.h>
 #include <nucleus/task.h>
 #include <nucleus/vfs.h>
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();
+}
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');
+}