Add kprintf for DEBUG(); differentiated from printf()
This commit is contained in:
@@ -65,6 +65,38 @@ void internal_putc(int c, void *_)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* debug_putc - Internal DEBUG putchar function
|
||||
* @c: char to print
|
||||
* @_: (unused, for nanoprintf)
|
||||
*
|
||||
* Prints a character to the terminal if it's ready and if
|
||||
* the kernel is still initializing, and also always to the
|
||||
* serial interface if it's ready.
|
||||
*/
|
||||
void debug_putc(int c, void *_)
|
||||
{
|
||||
(void)_;
|
||||
char ch = (char)c;
|
||||
|
||||
if (init.terminal && (!init.all || panic_count > 0)) {
|
||||
if (panic_count == 0) {
|
||||
spinlock_acquire(&term_lock);
|
||||
flanterm_write(ft_ctx, &ch, 1);
|
||||
spinlock_release(&term_lock);
|
||||
} else {
|
||||
flanterm_write(ft_ctx, &ch, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (init.serial) {
|
||||
if (ch == '\n') {
|
||||
skputc('\r');
|
||||
}
|
||||
skputc(ch);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* printf - Fromatted printing
|
||||
* @fmt: format string
|
||||
@@ -96,6 +128,38 @@ int printf(const char* fmt, ...)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* kprintf - Fromatted DEBUG printing
|
||||
* @fmt: format string
|
||||
* @...: variadic arguments
|
||||
*
|
||||
* Wrapper for nanoprintf; to be used only for
|
||||
* kernel/debug messages.
|
||||
*
|
||||
* Return:
|
||||
* <ret> - number of characters sent to the callback
|
||||
* %-1 - error
|
||||
*/
|
||||
int kprintf(const char* fmt, ...)
|
||||
{
|
||||
if (panic_count == 0) {
|
||||
spinlock_acquire(&printf_lock);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = npf_vpprintf(debug_putc, NULL, fmt, args);
|
||||
va_end(args);
|
||||
spinlock_release(&printf_lock);
|
||||
return ret;
|
||||
} else {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = npf_vpprintf(debug_putc, NULL, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* kputs - Kernel puts
|
||||
* @str: String to write
|
||||
|
||||
Reference in New Issue
Block a user