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