BarryServer : Git

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

// Related

Nucleus

Barry Kernel printf routines 120a213 (3 years, 2 months ago)
diff --git a/drivers/devices.c b/drivers/devices.c
index 9e0203a..7e1b709 100644
--- a/drivers/devices.c
+++ b/drivers/devices.c
@@ -5,8 +5,8 @@
 
 #include <stdint.h>
 #include <stddef.h>
+#include <nucleus/kernel.h>
 #include <nucleus/pci.h>
-#include <nucleus/panic.h>
 
 /* Structure for a Device */
 struct Device {
diff --git a/include/nucleus/panic.h b/include/nucleus/kernel.h
similarity index 52%
rename from include/nucleus/panic.h
rename to include/nucleus/kernel.h
index e51df78..50bba3d 100644
--- a/include/nucleus/panic.h
+++ b/include/nucleus/kernel.h
@@ -1,9 +1,12 @@
-#ifndef _NUCLEUS_PANIC_H
-#define _NUCLEUS_PANIC_H
+#ifndef _NUCLEUS_KERNEL_H
+#define _NUCLEUS_KERNEL_H
 
-int sprintf(char *buf, char *fmt, ...);
+#include <stdarg.h>
+
+int vsprintf(char *buf, const char *fmt, va_list args);
+int sprintf(char *buf, const char *fmt, ...);
+void dbgprintf(char *str);
 void kprintf(char *fmt, ...);
-void dbgprintf(char *msg);
 _Noreturn void panic(char *fmt, ...);
 
 #define ASSERT(c) ({ \
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');
+}
diff --git a/lib/printf.c b/lib/printf.c
index 006ef40..9836835 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -1,15 +1,7 @@
-/*
- * This file implements the *printf routines, as well as the full kernel panic
- * routine.  The kernel panic routine does not return, and halts the processor
- * after running, the other *printf routines work as they normally would.
- * kprintf() outputs to the debug port rather than to the screen.
- */
-
 #include <stdint.h>
 #include <stdarg.h>
 #include <string.h>
 #include <io.h>
-#include <nucleus/task.h>
 
 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
 
@@ -100,7 +92,7 @@ number(char *str, int num, int base, int size, int precision, int type)
 }
 
 /* Print formatted to a buffer */
-static int
+int
 vsprintf(char *buf, const char *fmt, va_list args)
 {
 	int len, i;
@@ -259,64 +251,3 @@ sprintf(char *buf, char *fmt, ...)
 	va_end(args);
 	return ret;
 }
-
-/* 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 serial 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 *msg)
-{
-	size_t len = 1024;
-	if (!msg || !verify_access(msg, strnlen(msg, len), PROT_READ))
-		return;
-
-	/* Print to debug port */
-	kprintf("\033[93;01m(%d:%d): \033[0m%s",
-	        current->tgid, current->tid, msg);
-}
-
-/* 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');
-
-	asm volatile("sti");
-	while (1)
-		asm volatile("hlt");
-}
diff --git a/memory/fault.c b/memory/fault.c
index 02c95ca..e916368 100644
--- a/memory/fault.c
+++ b/memory/fault.c
@@ -10,9 +10,9 @@
 #include <stdint.h>
 #include <string.h>
 #include <nucleus/cpu.h>
+#include <nucleus/kernel.h>
 #include <nucleus/memory.h>
 #include <nucleus/task.h>
-#include <nucleus/panic.h>
 #include "paging.h"
 #include "namespace.h"
 
diff --git a/memory/frame.c b/memory/frame.c
index 2e063d5..33ae7ef 100644
--- a/memory/frame.c
+++ b/memory/frame.c
@@ -9,8 +9,8 @@
 #include <stddef.h>
 #include <string.h>
 #include <sys/types.h>
+#include <nucleus/kernel.h>
 #include <nucleus/memory.h>
-#include <nucleus/panic.h>
 
 #define INDEX(a) ((a)/32)
 #define OFFSET(a) ((a)%32)
diff --git a/object/lock.c b/object/lock.c
index e4c77c9..b3d2fb8 100644
--- a/object/lock.c
+++ b/object/lock.c
@@ -5,9 +5,9 @@
  * that CPU/task to acquire it multiple times and safely release it.
  */
 
+#include <nucleus/kernel.h>
 #include <nucleus/object.h>
 #include <nucleus/task.h>
-#include <nucleus/panic.h>
 
 /* Check if already holding */
 static int