2019-06-07 11:41:11 +02:00
|
|
|
#include <AK/PrintfImplementation.h>
|
|
|
|
|
#include <AK/Types.h>
|
2019-04-10 22:49:11 +02:00
|
|
|
#include <Kernel/Console.h>
|
|
|
|
|
#include <Kernel/IO.h>
|
|
|
|
|
#include <Kernel/Process.h>
|
2019-06-07 11:41:11 +02:00
|
|
|
#include <Kernel/kstdio.h>
|
|
|
|
|
#include <LibC/stdarg.h>
|
2018-10-22 13:20:35 +02:00
|
|
|
|
2018-10-29 21:54:11 +01:00
|
|
|
static void console_putch(char*&, char ch)
|
2018-10-22 13:20:35 +02:00
|
|
|
{
|
2019-03-23 22:03:17 +01:00
|
|
|
if (!current) {
|
|
|
|
|
IO::out8(0xe9, ch);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-29 13:58:40 +02:00
|
|
|
Console::the().put_char(ch);
|
2018-10-22 13:20:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int kprintf(const char* fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
2019-01-31 17:31:23 +01:00
|
|
|
int ret = printf_internal(console_putch, nullptr, fmt, ap);
|
2018-10-22 13:20:35 +02:00
|
|
|
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);
|
2019-01-31 17:31:23 +01:00
|
|
|
int ret = printf_internal(buffer_putch, buffer, fmt, ap);
|
2018-10-22 13:20:35 +02:00
|
|
|
buffer[ret] = '\0';
|
|
|
|
|
va_end(ap);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-10-29 21:54:11 +01:00
|
|
|
|
|
|
|
|
static void debugger_putch(char*&, char ch)
|
|
|
|
|
{
|
|
|
|
|
IO::out8(0xe9, ch);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 20:00:42 +01:00
|
|
|
extern "C" int dbgprintf(const char* fmt, ...)
|
2018-10-29 21:54:11 +01:00
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
2019-01-31 17:31:23 +01:00
|
|
|
int ret = printf_internal(debugger_putch, nullptr, fmt, ap);
|
2018-10-29 21:54:11 +01:00
|
|
|
va_end(ap);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|