summaryrefslogtreecommitdiffstats
path: root/print.c
blob: dc5597bce330eec911d1bb2588262a6f89831cde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}