Annotation of coherent/b/STREAMS/io.386/putchar.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * File:       putchar.c
                      3:  *
                      4:  * $Log:       putchar.c,v $
                      5:  * Revision 2.2  93/07/26  15:32:13  nigel
                      6:  * Nigel's R80
                      7:  * 
                      8:  * Revision 1.5  93/04/14  10:12:14  root
                      9:  * r75
                     10:  * 
                     11:  * Revision 1.4  92/06/15  13:06:59  root
                     12:  * Use putchar_init on (2,0) as well as async.
                     13:  * 
                     14:  * Revision 1.3  92/06/11  21:05:27  root
                     15:  * *** empty log message ***
                     16:  * 
                     17:  */
                     18: 
                     19: #if KLAATU
                     20: #define SERIAL_CONSOLE 1
                     21: #define INS8250 0x3f8  /* klaatu */
                     22: #endif
                     23: 
                     24: #if GORT
                     25: #define SERIAL_CONSOLE 1
                     26: #define        INS8250 0x290   /* gort */
                     27: #endif
                     28: 
                     29: #include <sys/coherent.h>
                     30: #include <sys/stat.h>
                     31: #include <sys/con.h>
                     32: #include <sys/io.h>
                     33: #include <sys/devices.h>
                     34: #include <sys/file.h>
                     35: 
                     36: #define P_LEN 1024
                     37: /*
                     38:  * Stash messages in p_buf[] until we can print them.
                     39:  * Note that p_buf[] can not be safely kalloc()'d because even
                     40:  * those routines could generate printf()'s.
                     41:  */
                     42: static char    p_buf[P_LEN];
                     43: static int     p_off;  /* Offset into p_buff.  */
                     44: int ok_to_use_dev = 0; /* Can we use the console device yet?  */
                     45: 
                     46: int coninit = 0;
                     47: dev_t condev = makedev(2,0);
                     48: 
                     49: putchar(c)
                     50: int c;
                     51: {
                     52: #if SERIAL_CONSOLE
                     53: __putchar(c);
                     54: #else
                     55:        IO iob;
                     56: 
                     57:        /*
                     58:         * If we get a printf before the devices have been initialized,
                     59:         * keep as many characters as we can until we can print them.
                     60:         */
                     61:        if (!ok_to_use_dev) {
                     62:                if (p_off == P_LEN) {
                     63:                        p_buf[P_LEN-1] = '*';   /* Mark an overrun.  */
                     64:                } else {
                     65:                        p_buf[p_off++] = c;     /* Stash the character.  */
                     66:                }
                     67:                return;
                     68:        }
                     69: 
                     70:        if (coninit == 0) {
                     71:                ++coninit;
                     72:                dopen(condev, IPW, DFCHR);
                     73:        }
                     74: 
                     75:        if (c == '\n')
                     76:                putchar('\r');
                     77: 
                     78:        iob.io_seg  = IOSYS;
                     79:        iob.io_ioc  = 1;
                     80: #ifdef _I386
                     81:        iob.io.vbase = &c;
                     82: #else
                     83:        iob.io_base = &c;
                     84: #endif
                     85:        iob.io_flag = 0;
                     86:        dwrite(condev, &iob);
                     87: #endif
                     88: } /* putchar() */
                     89: 
                     90: /*
                     91:  * putchar_init() is called from main() once devices have been
                     92:  * initialized.  It marks the condev as usable, and then prints
                     93:  * anything that has been stored away.
                     94:  */
                     95: putchar_init()
                     96: {
                     97:        int i;
                     98: 
                     99:        /* Mark condev as usable.  */
                    100:        ok_to_use_dev = 1;
                    101: 
                    102:        /* Dump everything we've stored away.  */
                    103:        for (i = 0; i < p_off; ++i)
                    104:                putchar(p_buf[i]);
                    105: 
                    106:        if ('*' == p_buf[P_LEN-1])
                    107:                printf("\npb buffer overrun detected.\n");
                    108: } /* putchar_init() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.