33 lines
746 B
C
33 lines
746 B
C
#include <mini-printf.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <uart.h>
|
|
|
|
/** Helper routine to put characters into our uart device */
|
|
static int stdout_puts(char *s, int len, void *unused) {
|
|
(void)unused;
|
|
for (int i = 0; i < len; i++) uart_putc(s[i]);
|
|
return len;
|
|
}
|
|
|
|
/**
|
|
* Printf-like functionality for the kernel.
|
|
*
|
|
* %% - print '%',
|
|
* %c - character,
|
|
* %s - string,
|
|
* %d, %u - decimal integer,
|
|
* %x, %X - hex integer,
|
|
*/
|
|
int kprintf(const char *restrict fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
int ret = kvprintf(fmt, ap);
|
|
va_end(ap);
|
|
return ret;
|
|
}
|
|
|
|
int kvprintf(const char *fmt, va_list ap) {
|
|
int ret = mini_vpprintf(stdout_puts, NULL, fmt, ap);
|
|
return ret;
|
|
}
|