Annotation of 43BSD/sys/stand/imptst.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986 Regents of the University of California.
                      3:  * All rights reserved.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  *
                      6:  *     @(#)imptst.c    7.1 (Berkeley) 6/5/86
                      7:  */
                      8: 
                      9: #include "../h/param.h"
                     10: #include "../h/inode.h"
                     11: 
                     12: #include "../vaxuba/ubareg.h"
                     13: #include "../netinet/in.h"
                     14: #include "../netinet/in_systm.h"
                     15: #define        IMPLEADERS
                     16: #include "../netimp/if_imp.h"
                     17: #include "../vaxif/if_acc.h"
                     18: 
                     19: #include "saio.h"
                     20: #include "savax.h"
                     21: 
                     22: #define min(a,b) (a<b ? a : b)
                     23: #define BUFSIZ 512
                     24: 
                     25: char   input[132];
                     26: struct imp_leader imps, *ip = &imps;
                     27: char   inbuf[BUFSIZ];
                     28: int    writeflg = 0;       
                     29: 
                     30: main()
                     31: {
                     32:        register error = 0, i, len;
                     33:        short type, host, impno, link;
                     34:        register struct accdevice *addr =
                     35:                (struct accdevice *)ubamem(0, 0767700);
                     36: 
                     37:        printf("imp interface diagnostic\n");
                     38:        printf("read or write test(r or w)? ");
                     39:        gets(input);
                     40:        while (*input != 'r' && *input != 'w') {
                     41:                printf("reply r or w: ");
                     42:                gets(input);
                     43:        }
                     44:        if (*input == 'w') {
                     45:                writeflg++;
                     46:                printf("enter destination host number: ");
                     47:                gets(input);
                     48:                while ((host = (short)atol(input)) < 0 || host > 255) {
                     49:                        printf("range [0, 255], re-enter: ");
                     50:                        gets(input);
                     51:                }
                     52:                printf("imp number: ");
                     53:                gets(input);
                     54:                while ((impno = (short)atol(input)) < 0 || impno > 32767) {
                     55:                        printf("range [0, 32767], re-enter: ");
                     56:                        gets(input);
                     57:                }
                     58:                printf("link number: ");
                     59:                gets(input);
                     60:                while ((link = (short)atol(input)) < 0 || link > 255) {
                     61:                        printf("range [0, 255], re-enter: ");
                     62:                        gets(input);
                     63:                }
                     64:        }
                     65:        printf("initialization starting...\n");
                     66:        impinit();
                     67:        /* send 3 noops and init imp leader buffer */
                     68:        impnoops((struct control_leader *)ip);
                     69:        printf("initialization complete\n");
                     70:        if (writeflg) {
                     71:                printf("starting write test...\n");
                     72:                ip->il_host = host;
                     73:                ip->il_imp = htons((u_short)impno);
                     74:                ip->il_link = link;
                     75:                while (!error)
                     76:                        error = impwrite(ip, sizeof (*ip));
                     77:                printf("imp write error, ocsr=%b\n", (short)error,
                     78:                        ACC_OUTBITS);
                     79:        } else {
                     80:                printf("starting read test...\n");
                     81:                while (!error) {
                     82: printf("impread(%d)\n", sizeof (*ip));
                     83:                        error = impread(ip, sizeof (*ip));
                     84: printf("impread, error=%b\n", error, ACC_INBITS);
                     85:                        printleader(ip);
                     86:                        len = ntohs(ip->il_length);
                     87: printf("length=%d\n", len);
                     88:                        /* read any data */
                     89:                        while ((error & IN_EOM) == 0 &&
                     90:                          (error & ~IN_EOM) == 0 && len > 0) {
                     91:                                i = min(len, BUFSIZ);
                     92: printf("impread(%d)\n", i);
                     93:                                error = impread(inbuf, i);
                     94:                                len -= i;
                     95: printf("error=%b, len=%d\n", error, ACC_INBITS, len);
                     96:                        }
                     97:                        error &= ~IN_EOM;
                     98:                        if (error == 0 && (len > 0 || addr->iwc))
                     99:                                printf("imp input length mismatch\n");
                    100:                }
                    101:                printf("imp read error, icsr=%b\n", (short)error, ACC_INBITS);
                    102:        }
                    103:        printf("...imptest exiting\n");
                    104: }
                    105: 
                    106: impnoops(cp)
                    107:        register struct control_leader *cp;
                    108: {
                    109:        register i, error;
                    110: 
                    111:        bzero((caddr_t)cp, sizeof (struct control_leader));
                    112:        cp->dl_format = IMP_NFF;
                    113:        cp->dl_mtype = IMPTYPE_NOOP;
                    114:        for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 
                    115:                 cp->dl_link = i;
                    116:                if ((error = impwrite(ip, sizeof (*ip))) != 0) {
                    117:                        printf("imp init error, ocsr=%b\n", (short)error,
                    118:                                ACC_OUTBITS);
                    119:                        _stop();
                    120:                }
                    121:        }
                    122: }
                    123: 
                    124: impwrite(buf, len)
                    125:        register struct imp *buf;
                    126:        register len;
                    127: {
                    128:        register uba, error;
                    129:        struct iob io;
                    130:        register struct accdevice *addr =
                    131:            (struct accdevice *)ubamem(0, 0767600);
                    132: 
                    133:        /* set up uba mapping */
                    134:        io.i_ma = (caddr_t)buf;
                    135:        io.i_cc = len;
                    136:        uba = ubasetup(&io, 0);
                    137: 
                    138:        /* set regs and perform i/o */
                    139:        addr->oba = (u_short)uba;
                    140:        addr->owc = -((io.i_cc + 1) >> 1);
                    141:        addr->ocsr = ((short) ((uba & 0x30000) >> 12) | OUT_ENLB | ACC_GO);
                    142:        while ((addr->ocsr & ACC_RDY) == 0)
                    143:                ;
                    144:        error = addr->ocsr & (ACC_NXM|ACC_ERR);
                    145:        ubafree(uba);
                    146:        return(error);
                    147: }
                    148: 
                    149: impread(buf, len)
                    150:        register struct imp *buf;
                    151:        register len;
                    152: {
                    153:        register uba, error;
                    154:        struct iob io;
                    155:        register struct accdevice *addr =
                    156:            (struct accdevice *)ubamem(0, 0767600);
                    157: 
                    158:        /* set up uba mapping */
                    159:        io.i_ma = (caddr_t)buf;
                    160:        io.i_cc = len;
                    161:        uba = ubasetup(&io, 0);
                    162:        /* set regs and perform i/o */
                    163:        addr->iba = (u_short)uba;
                    164:        addr->iwc = -(io.i_cc >> 1);
                    165:        addr->icsr = IN_MRDY | IN_WEN | ((uba & 0x30000) >> 12) | ACC_GO;
                    166:        while ((addr->icsr & ACC_RDY) == 0)
                    167:                ;
                    168:        error = addr->icsr & (IN_EOM|ACC_ERR|IN_RMR|ACC_NXM);
                    169:        ubafree(uba);
                    170:        return(error);
                    171: }
                    172: 
                    173: impinit()
                    174: {      
                    175:        register struct accdevice *addr = 
                    176:                (struct accdevice *)ubamem(0, 0767600);
                    177:        register int i;
                    178: 
                    179:        /*
                    180:         * Reset the imp interface;
                    181:         * the delays are pure guesswork.
                    182:         */
                    183:        addr->icsr = ACC_RESET; DELAY(5000);
                    184:         addr->ocsr = ACC_RESET; DELAY(5000);
                    185:        addr->ocsr = OUT_BBACK; DELAY(5000);    /* reset host master ready */
                    186:        addr->ocsr = 0;
                    187:        addr->icsr = IN_MRDY | IN_WEN;          /* close the relay */
                    188:        DELAY(10000);
                    189:        /* YECH!!! */
                    190:        for (i = 0; i < 500; i++) {
                    191:                if ((addr->icsr & IN_HRDY) &&
                    192:                    (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0)
                    193:                        return;
                    194:                addr->icsr = IN_MRDY | IN_WEN; DELAY(10000);
                    195:                /* keep turning IN_RMR off */
                    196:        }
                    197:        printf("imp doesn't respond, icsr=%b, ocsr=%b\n",
                    198:                addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS);
                    199: }
                    200: 
                    201: /*
                    202:  *  Convert null-terminated ascii string to binary
                    203:  *  and return value.
                    204:  *  1st char in string :
                    205:  *     0 -> octal
                    206:  *     x -> hex
                    207:  *     else decimal
                    208:  */
                    209: atol(as)
                    210:        register char *as;
                    211: {
                    212:        register value = 0;
                    213:        register base = 10;
                    214:        register sign = 1;
                    215:        register digit = 0;
                    216:  
                    217: aloop :
                    218:        if ((digit = (*as++)) == 0)
                    219:                return(value) ; /* null */
                    220:        if (digit == '-') {
                    221:                sign = -sign;
                    222:                goto aloop ;
                    223:        }
                    224:        if (digit == '0')
                    225:                base = 8 ;
                    226:        else if (digit == 'x')
                    227:                base = 16 ;
                    228:        else
                    229:                value = digit - '0';
                    230:        while (digit = (*as++)) {
                    231:                if (digit < '0')
                    232:                        return(0);
                    233:                switch (base) {
                    234: 
                    235:                case 8 :
                    236:                        if (digit > '7')
                    237:                                return(0);
                    238:                        digit -= '0';
                    239:                        break;
                    240: 
                    241:                case 10 :
                    242:                        if (digit > '9')
                    243:                                return(0);
                    244:                        digit -= '0';
                    245:                        break;
                    246: 
                    247:                case 16 :
                    248:                        if (digit <= '9') {
                    249:                                digit -= 060 ;
                    250:                                break;
                    251:                        }
                    252:                        if ((digit >= 'A') && (digit <= 'F')) {
                    253:                                digit -= 'A' + 10;
                    254:                                break;
                    255:                        }
                    256:                        if ((digit >= 'a') && (digit <= 'f')) {
                    257:                                digit -= 'a' + 10 ;
                    258:                                break;
                    259:                        }
                    260:                        return(0);
                    261:                }
                    262:                value = (value * base) + digit;
                    263:        }
                    264:        return (value * sign);
                    265: }
                    266: 
                    267: printleader(ip)
                    268:        register struct imp_leader *ip;
                    269: {
                    270:        printbyte((char *)ip, 12);
                    271:        printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network,
                    272:                ip->il_flags);
                    273:        if (ip->il_mtype <= IMPTYPE_READY)
                    274:                printf("%s,", impleaders[ip->il_mtype]);
                    275:        else
                    276:                printf("%x,", ip->il_mtype);
                    277:        printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host,
                    278:                ntohs(ip->il_imp));
                    279:        if (ip->il_link == IMPLINK_IP)
                    280:                printf("ip,");
                    281:        else
                    282:                printf("%x,", ip->il_link);
                    283:        printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3);
                    284: }
                    285: 
                    286: printbyte(cp, n)
                    287:        register char *cp;
                    288:        int n;
                    289: {
                    290:        register i, j, c;
                    291: 
                    292:        for (i=0; i<n; i++) {
                    293:                c = *cp++;
                    294:                for (j=0; j<2; j++)
                    295:                        putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]);
                    296:                putchar(' ');
                    297:        }
                    298:        putchar('\n');
                    299: }

unix.superglobalmegacorp.com

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