From ace65b453151845bc361f21f3e5b651c35f9f126 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Wed, 22 May 2024 13:00:41 -0400 Subject: massive refactor for mp and organization --- print.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 print.c (limited to 'print.c') 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); +} -- cgit v1.2.1