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