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