Annotation of coherent/d/PS2_KERNEL/io.386/putchar.c, revision 1.1

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

unix.superglobalmegacorp.com

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