1 // io/console/misc.cc -- Generic code relating to kernel debug consoles
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
15 #include <kern/console.h>
16 #include <kern/libc.h>
17 #include <util/spinlock.h>
21 void Console::write(char *data, size_t len)
24 write(Array<octet>((octet *)data, len), &len64);
27 // All consoles will set this to themselves; the last console
28 // to be initialized will be used. At some point, the console
29 // used will be configurable (including the ability to broadcast
30 // to multiple consoles).
32 Console *primary_console;
36 static const size_t printf_buffer_size = 4096;
37 static char printf_buffer[printf_buffer_size];
38 Lock::SpinLock printf_lock;
40 // Note: this will not retry with a larger buffer if overflow
41 // happens. If you really need that, you'll need to call snprintf
42 // and primary_console->write yourself.
44 void vga_write(uint8_t *buf, u64 len);
46 size_t printf(const char *str, ...)
48 Lock::AutoSpinLockRecIRQ autolock(printf_lock);
52 size_t ret = vsnprintf(printf_buffer, printf_buffer_size, str, args);
55 if (ret > printf_buffer_size)
56 ret = printf_buffer_size;
58 IO::Console::primary_console->write(printf_buffer, ret);