summaryrefslogtreecommitdiffstats
path: root/print.c
diff options
context:
space:
mode:
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);
+}