kprintf.c

Go to the documentation of this file.
00001 /*
00002  * printf for the kernel
00003  *
00004  * Changes:
00005  *   Dec 10, 2004   kernel printing to circular buffer  (Jorrit N. Herder)
00006  * 
00007  * This file contains the routines that take care of kernel messages, i.e.,
00008  * diagnostic output within the kernel. Kernel messages are not directly
00009  * displayed on the console, because this must be done by the output driver. 
00010  * Instead, the kernel accumulates characters in a buffer and notifies the
00011  * output driver when a new message is ready. 
00012  */
00013 
00014 #include "kernel.h"
00015 #include "proc.h"
00016 #include <signal.h>
00017 
00018 #define printf kprintf
00019 
00020 #include "../lib/sysutil/kprintf.c"
00021 
00022 #define END_OF_KMESS    0
00023 FORWARD _PROTOTYPE( void ser_putc, (char c));
00024 
00025 /*===========================================================================*
00026  *                              kputc                                        *
00027  *===========================================================================*/
00028 PUBLIC void kputc(c)
00029 int c;                                  /* character to append */
00030 {
00031 /* Accumulate a single character for a kernel message. Send a notification
00032  * to the output driver if an END_OF_KMESS is encountered. 
00033  */
00034   if (c != END_OF_KMESS) {
00035       if (do_serial_debug)
00036         ser_putc(c);
00037       kmess.km_buf[kmess.km_next] = c;  /* put normal char in buffer */
00038       if (kmess.km_size < KMESS_BUF_SIZE)
00039           kmess.km_size += 1;           
00040       kmess.km_next = (kmess.km_next + 1) % KMESS_BUF_SIZE;
00041   } else {
00042       int p, outprocs[] = OUTPUT_PROCS_ARRAY;
00043       for(p = 0; outprocs[p] != NONE; p++) {
00044          if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
00045            send_sig(outprocs[p], SIGKMESS);
00046          }
00047       }
00048   }
00049 }
00050 
00051 #define COM1_BASE       0x3F8
00052 #define COM1_THR        (COM1_BASE + 0)
00053 #define   LSR_THRE      0x20
00054 #define COM1_LSR        (COM1_BASE + 5)
00055 
00056 PRIVATE void ser_putc(char c)
00057 {
00058         int i;
00059         int lsr, thr;
00060 
00061         return;
00062 
00063         lsr= COM1_LSR;
00064         thr= COM1_THR;
00065         for (i= 0; i<100000; i++)
00066         {
00067                 if (inb(lsr) & LSR_THRE)
00068                         break;
00069         }
00070         outb(thr, c);
00071 }

Generated on Fri Apr 14 22:57:24 2006 for minix by  doxygen 1.4.6