1 // Simple implementation of cprintf console output for the kernel,
2 // based on printfmt() and the kernel console's cputchar().
9 #include <arch/types.h>
15 uint32_t output_lock = 0;
17 void putch(int ch, int **cnt)
23 // buffered putch to (potentially) speed up printing.
24 // static buffer is safe because output_lock must be held.
25 // ch == -1 flushes the buffer.
26 void buffered_putch(int ch, int **cnt)
28 #define buffered_putch_bufsize 64
29 static char buf[buffered_putch_bufsize];
30 static int buflen = 0;
38 if(ch == -1 || buflen == buffered_putch_bufsize)
45 int vcprintf(const char *fmt, va_list ap)
51 // lock all output. this will catch any printfs at line granularity
52 spin_lock_irqsave(&output_lock);
54 // do the buffered printf
55 vprintfmt((void*)buffered_putch, (void**)&cntp, fmt, ap);
57 // write out remaining chars in the buffer
58 buffered_putch(-1,&cntp);
60 spin_unlock_irqsave(&output_lock);
65 int cprintf(const char *fmt, ...)
71 cnt = vcprintf(fmt, ap);