summaryrefslogtreecommitdiffstats
path: root/print.c
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2024-05-22 13:00:41 -0400
committerJon Santmyer <jon@jonsantmyer.com>2024-05-22 13:00:41 -0400
commitace65b453151845bc361f21f3e5b651c35f9f126 (patch)
tree262ebd29b0ca1d8584f0b6f1efa7a00d9f4f3e43 /print.c
parentf004c1ade8d617a82cea2fe249434cccb47a2358 (diff)
downloadjove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.tar.gz
jove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.tar.bz2
jove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.zip
massive refactor for mp and organizationHEADmaster
Diffstat (limited to 'print.c')
-rw-r--r--print.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/print.c b/print.c
new file mode 100644
index 0000000..dc5597b
--- /dev/null
+++ b/print.c
@@ -0,0 +1,40 @@
+#include "print.h"
+#include "jove.h"
+#include "string.h"
+#include "device/serial.h"
+#include "klib/format.h"
+#include "klib/spinlock.h"
+
+static spinlock_t s_print_lock;
+static char s_print_buffer[PRINT_BUFFERW];
+
+static char *s_print_level_str[PRINT_ERROR + 1] = {
+ "[D] %s/%s:%i | ",
+ "[I] ",
+ "[W] %s/%s:%i | ",
+ "[!!E!!] %s/%s:%i | "
+};
+
+void
+_plogvf(const char *file, const char *func, int line, int lvl, const char *fmt, va_list ap)
+{
+ spinlock_acquire(s_print_lock);
+
+ char *buf = sfmt(s_print_buffer, PRINT_BUFFERW, s_print_level_str[lvl],
+ file, func, line);
+ size_t prew = strlen(buf);
+
+ svfmt(&buf[prew], PRINT_BUFFERW - 128, fmt, ap);
+ serial_write(&COM1, buf, strlen(buf));
+
+ spinlock_release(s_print_lock);
+}
+
+void
+_plogf(const char *file, const char *func, int line, int lvl, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _plogvf(file, func, line, lvl, fmt, ap);
+ va_end(ap);
+}