summaryrefslogtreecommitdiff
path: root/Kernel/kprintf.cpp
blob: bc4da74c4d50f6a9602bf8a986b255edae5bfca7 (plain)
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
41
42
43
44
45
46
47
48
49
50
#include "kprintf.h"
#include "Console.h"
#include "IO.h"
#include <LibC/stdarg.h>
#include "Process.h"
#include <AK/Types.h>
#include <AK/printf.cpp>

static void console_putch(char*&, char ch)
{
    Console::the().write(*current, (byte*)&ch, 1);
}

int kprintf(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    int ret = printfInternal(console_putch, nullptr, fmt, ap);
    va_end(ap);
    return ret;
}

static void buffer_putch(char*& bufptr, char ch)
{
    *bufptr++ = ch;
}

int ksprintf(char* buffer, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    int ret = printfInternal(buffer_putch, buffer, fmt, ap);
    buffer[ret] = '\0';
    va_end(ap);
    return ret;
}

static void debugger_putch(char*&, char ch)
{
    IO::out8(0xe9, ch);
}

extern "C" int dbgprintf(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    int ret = printfInternal(debugger_putch, nullptr, fmt, ap);
    va_end(ap);
    return ret;
}