1 /* A server must occasionally print some message. It uses a simple version of 2 * printf() found in the system lib that calls kputc() to output characters. 3 * Printing is done with a call to the kernel, and not by going through FS. 4 * 5 * This routine can only be used by servers and device drivers. The kernel 6 * must define its own kputc(). Note that the log driver also defines its own 7 * kputc() to directly call the TTY instead of going through this library. 8 */ 9 10 #include "sysutil.h" 11 12 static char print_buf[DIAG_BUFSIZE]; /* output is buffered here */ 13 14 /*===========================================================================* 15 * kputc * 16 *===========================================================================*/ 17 void kputc(int c) 18 { 19 /* Accumulate another character. If 0 or buffer full, print it. */ 20 static int buf_count; /* # characters in the buffer */ 21 22 if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) { 23 sys_diagctl_diag(print_buf, buf_count); 24 buf_count = 0; 25 } 26 if (c != 0) { 27 28 /* Append a single character to the output buffer. */ 29 print_buf[buf_count] = c; 30 buf_count++; 31 } 32 } 33