Annotation of cci/d/io/Lib/cp.c, revision 1.1

1.1     ! root        1: /*     Console Processor Interface     */
        !             2: /*     Tahoe version, Nov. 1982        */
        !             3: 
        !             4: /****************************************/
        !             5: /*                                     */
        !             6: /*     Reduced DCB layout for byte     */
        !             7: /*     communication.                  */
        !             8: /*                                     */
        !             9: /****************************************/
        !            10: 
        !            11: asm(".set CPMDCB,21");
        !            12: 
        !            13: #define        CPBUFLEN 200            /* Output buffer length */
        !            14: struct cphdr
        !            15: {
        !            16:        char    cp_unit;        /* Done bit & unit # */
        !            17:        char    cp_comm;        /* Command */
        !            18:        short   cp_count;       /* Counter (when relevant) */
        !            19: };
        !            20: 
        !            21: struct cpdcb_o                 /* Output structure */
        !            22: {
        !            23:        struct  cphdr   cp_hdr;
        !            24:        char    cp_buf[CPBUFLEN]; /* Buffer for output or 'stty' */
        !            25: };
        !            26: 
        !            27: struct cpdcb_i                 /* Structure for input */
        !            28: {
        !            29:        struct  cphdr   cp_hdr;
        !            30:        char    cpi_buf[4];     /* Buffer for input */
        !            31: };
        !            32: 
        !            33: #define        CPDONE  0x80            /* 'Done' bit in cp_unit */
        !            34: #define        CPTAKE  0x40            /* CP 'ack' to this cpdcb */
        !            35: 
        !            36:                /* Values for 'unit' */
        !            37: #define        CPUNIT  0               /* The CP itself */
        !            38: #define        CPCONS  1               /* Console line */
        !            39: #define        CPREMOT 2               /* Remote line */
        !            40: 
        !            41:                /* Values for 'command' */
        !            42: #define        CPRESET 0
        !            43: #define        CPWRITE 1
        !            44: #define        CPREAD  2
        !            45: #define        CPSTTY  3
        !            46: #define        CPBOOT  4
        !            47: #define NCHAR  1
        !            48: 
        !            49: struct cpdcb_o cpout;                  /* DCB for output */
        !            50: struct cpdcb_i cpin;                   /* DCB for input */
        !            51: 
        !            52: putstr(str)
        !            53: char *str;
        !            54: {      long c_cnt;
        !            55: 
        !            56:        cpout.cp_hdr.cp_unit = CPCONS;          /* Reset done bit */
        !            57:        cpout.cp_hdr.cp_comm = CPWRITE;         /* Set command */
        !            58:        for(c_cnt=0;;c_cnt++) {
        !            59:                cpout.cp_buf[c_cnt] = *str++;
        !            60:                if (cpout.cp_buf[c_cnt]=='\n') {
        !            61:                         c_cnt++;
        !            62:                         cpout.cp_buf[c_cnt]='\r';
        !            63:                         }
        !            64:                if (cpout.cp_buf[c_cnt]=='\0') break;
        !            65:        }
        !            66:        if (c_cnt) {
        !            67:                cpout.cp_hdr.cp_count = c_cnt;
        !            68:                cp_poll('\0'); }
        !            69: }
        !            70: 
        !            71: /*     Put a char to CPU2 console */
        !            72: putchar(c)
        !            73: {
        !            74:        cpout.cp_hdr.cp_unit = CPCONS;          /* Reset done bit */
        !            75:        cpout.cp_hdr.cp_comm = CPWRITE;         /* Set command */
        !            76:        cpout.cp_buf[0] = c;
        !            77:        cpout.cp_hdr.cp_count = 1;
        !            78:        cp_poll(c);
        !            79: }
        !            80: 
        !            81: 
        !            82: char rdchar()
        !            83: {
        !            84: register long  r12;
        !            85:        cpin.cp_hdr.cp_unit = CPCONS;           /* Reset done bit */
        !            86:        cpin.cp_hdr.cp_comm = CPREAD;           /* Set command */
        !            87:        cpin.cp_hdr.cp_count = 1;
        !            88:        cp_pollr();
        !            89:        r12 = (long)(&cpin.cpi_buf[0]);
        !            90:        asm("mtpr r12,$0x1c");                  /* mtpr r11,$PDCS */
        !            91:        return(cpin.cpi_buf[0] & 0x7f);
        !            92: }
        !            93: 
        !            94: 
        !            95: /*     Poll CP on read
        !            96: */
        !            97: cp_pollr()
        !            98: {      register long r12, r11, time;
        !            99: 
        !           100:        time = 0xff0000;
        !           101:        r12 = ((long)&cpin) & 0xffffff;
        !           102:        asm("mtpr r12,$CPMDCB");
        !           103: 
        !           104:        r11 = (long)(&cpin.cp_hdr.cp_unit);
        !           105:        while (time-- && !(cpin.cp_hdr.cp_unit & CPDONE)) { 
        !           106:                asm("mtpr r11,$0x1c");                  /* mtpr r11,$PDCS */
        !           107:                }
        !           108:        if (!(cpin.cp_hdr.cp_unit & CPDONE)) cp_hlt();  /* Time out */
        !           109: }
        !           110: 
        !           111: 
        !           112: /*     Poll CP on write
        !           113: */
        !           114: cp_poll(c)
        !           115: char c;
        !           116: {      register long r12, r11, time;
        !           117: 
        !           118:        time = 200000;
        !           119:        r12 = ((long)&cpout) & 0xffffff;
        !           120:        asm("mtpr r12,$CPMDCB");
        !           121:        asm("mtpr r12,$CPMDCB");
        !           122: 
        !           123:        r11 = (long)(&cpout.cp_hdr.cp_unit);
        !           124:        while (time-- && !(cpout.cp_hdr.cp_unit & CPDONE)) { 
        !           125:                asm("mtpr r11,$0x1c");                  /* mtpr r11,$PDCS */
        !           126:                }
        !           127:        if (!(cpout.cp_hdr.cp_unit & CPDONE)) cp_hlt(); /* Time out */
        !           128:        if (c== '\n') putchar('\r');
        !           129: }
        !           130: 
        !           131: cp_hlt()
        !           132: {
        !           133:        asm("movl $0xeeeeeeee,r0");
        !           134:        asm("movl $0xeeeeeeee,r1");
        !           135:        asm("movl $0xeeeeeeee,r2");
        !           136:        asm("halt");
        !           137: }
        !           138: 

unix.superglobalmegacorp.com

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