From 848a8ecaf2979fba75c3d398d6411d011b901061 Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Mon, 28 Jun 1982 10:56:39 -0800 Subject: [PATCH] date and time created 82/06/28 03:56:39 by sam SCCS-vsn: sys/vax/stand/imptst.c 4.1 --- usr/src/sys/vax/stand/imptst.c | 290 +++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 usr/src/sys/vax/stand/imptst.c diff --git a/usr/src/sys/vax/stand/imptst.c b/usr/src/sys/vax/stand/imptst.c new file mode 100644 index 0000000000..24db8f02fe --- /dev/null +++ b/usr/src/sys/vax/stand/imptst.c @@ -0,0 +1,290 @@ +#include "../h/param.h" +#include "../h/pte.h" +#include "../h/ubareg.h" +#include "../net/in.h" +#include "../net/in_systm.h" +#define IMPLEADERS +#include "../net/if_imp.h" +#include "../net/if_acc.h" +#include "../h/inode.h" +#include "saio.h" +#include "savax.h" + +#define min(a,b) (a 255) { + printf("range [0, 255], re-enter: "); + gets(input); + } + printf("imp number: "); + gets(input); + while ((impno = (short)atol(input)) < 0 || impno > 32767) { + printf("range [0, 32767], re-enter: "); + gets(input); + } + printf("link number: "); + gets(input); + while ((link = (short)atol(input)) < 0 || link > 255) { + printf("range [0, 255], re-enter: "); + gets(input); + } + } + printf("initialization starting...\n"); + impinit(); + /* send 3 noops and init imp leader buffer */ + impnoops((struct control_leader *)ip); + printf("initialization complete\n"); + if (writeflg) { + printf("starting write test...\n"); + ip->il_host = host; + ip->il_imp = htons((u_short)impno); + ip->il_link = link; + while (!error) + error = impwrite(ip, sizeof (*ip)); + printf("imp write error, ocsr=%b\n", (short)error, + ACC_OUTBITS); + } else { + printf("starting read test...\n"); + while (!error) { +printf("impread(%d)\n", sizeof (*ip)); + error = impread(ip, sizeof (*ip)); +printf("impread, error=%b\n", error, ACC_INBITS); + printleader(ip); + len = ntohs(ip->il_length); +printf("length=%d\n", len); + /* read any data */ + while ((error & IN_EOM) == 0 && + (error & ~IN_EOM) == 0 && len > 0) { + i = min(len, BUFSIZ); +printf("impread(%d)\n", i); + error = impread(inbuf, i); + len -= i; +printf("error=%b, len=%d\n", error, ACC_INBITS, len); + } + error &= ~IN_EOM; + if (error == 0 && (len > 0 || addr->iwc)) + printf("imp input length mismatch\n"); + } + printf("imp read error, icsr=%b\n", (short)error, ACC_INBITS); + } + printf("...imptest exiting\n"); +} + +impnoops(cp) + register struct control_leader *cp; +{ + register i, error; + + bzero((caddr_t)cp, sizeof (struct control_leader)); + cp->dl_format = IMP_NFF; + cp->dl_mtype = IMPTYPE_NOOP; + for (i = 0; i < IMP_DROPCNT + 1; i++ ) { + cp->dl_link = i; + if ((error = impwrite(ip, sizeof (*ip))) != 0) { + printf("imp init error, ocsr=%b\n", (short)error, + ACC_OUTBITS); + _stop(); + } + } +} + +impwrite(buf, len) + register struct imp *buf; + register len; +{ + register uba, error; + struct iob io; + register struct accdevice *addr = + (struct accdevice *)ubamem(0, 0767600); + + /* set up uba mapping */ + io.i_ma = (caddr_t)buf; + io.i_cc = len; + uba = ubasetup(&io, 0); + + /* set regs and perform i/o */ + addr->oba = (u_short)uba; + addr->owc = -((io.i_cc + 1) >> 1); + addr->ocsr = ((short) ((uba & 0x30000) >> 12) | OUT_ENLB | ACC_GO); + while ((addr->ocsr & ACC_RDY) == 0) + ; + error = addr->ocsr & (ACC_NXM|ACC_ERR); + ubafree(uba); + return(error); +} + +impread(buf, len) + register struct imp *buf; + register len; +{ + register uba, error; + struct iob io; + register struct accdevice *addr = + (struct accdevice *)ubamem(0, 0767600); + + /* set up uba mapping */ + io.i_ma = (caddr_t)buf; + io.i_cc = len; + uba = ubasetup(&io, 0); + /* set regs and perform i/o */ + addr->iba = (u_short)uba; + addr->iwc = -(io.i_cc >> 1); + addr->icsr = IN_MRDY | IN_WEN | ((uba & 0x30000) >> 12) | ACC_GO; + while ((addr->icsr & ACC_RDY) == 0) + ; + error = addr->icsr & (IN_EOM|ACC_ERR|IN_RMR|ACC_NXM); + ubafree(uba); + return(error); +} + +impinit() +{ + register struct accdevice *addr = + (struct accdevice *)ubamem(0, 0767600); + register int i; + + /* + * Reset the imp interface; + * the delays are pure guesswork. + */ + addr->icsr = ACC_RESET; DELAY(5000); + addr->ocsr = ACC_RESET; DELAY(5000); + addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */ + addr->ocsr = 0; + addr->icsr = IN_MRDY | IN_WEN; /* close the relay */ + DELAY(10000); + /* YECH!!! */ + for (i = 0; i < 500; i++) { + if ((addr->icsr & IN_HRDY) && + (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0) + return; + addr->icsr = IN_MRDY | IN_WEN; DELAY(10000); + /* keep turning IN_RMR off */ + } + printf("imp doesn't respond, icsr=%b, ocsr=%b\n", + addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS); +} + +/* + * Convert null-terminated ascii string to binary + * and return value. + * 1st char in string : + * 0 -> octal + * x -> hex + * else decimal + */ +atol(as) + register char *as; +{ + register value = 0; + register base = 10; + register sign = 1; + register digit = 0; + +aloop : + if ((digit = (*as++)) == 0) + return(value) ; /* null */ + if (digit == '-') { + sign = -sign; + goto aloop ; + } + if (digit == '0') + base = 8 ; + else if (digit == 'x') + base = 16 ; + else + value = digit - '0'; + while (digit = (*as++)) { + if (digit < '0') + return(0); + switch (base) { + + case 8 : + if (digit > '7') + return(0); + digit -= '0'; + break; + + case 10 : + if (digit > '9') + return(0); + digit -= '0'; + break; + + case 16 : + if (digit <= '9') { + digit -= 060 ; + break; + } + if ((digit >= 'A') && (digit <= 'F')) { + digit -= 'A' + 10; + break; + } + if ((digit >= 'a') && (digit <= 'f')) { + digit -= 'a' + 10 ; + break; + } + return(0); + } + value = (value * base) + digit; + } + return (value * sign); +} + +printleader(ip) + register struct imp_leader *ip; +{ + printbyte((char *)ip, 12); + printf("il_format, ip->il_network, + ip->il_flags); + if (ip->il_mtype <= IMPTYPE_READY) + printf("%s,", impleaders[ip->il_mtype]); + else + printf("%x,", ip->il_mtype); + printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, + ntohs(ip->il_imp)); + if (ip->il_link == IMPLINK_IP) + printf("ip,"); + else + printf("%x,", ip->il_link); + printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); +} + +printbyte(cp, n) + register char *cp; + int n; +{ + register i, j, c; + + for (i=0; i>((1-j)*4))&0xf]); + putchar(' '); + } + putchar('\n'); +} -- 2.20.1