From 4910614536d4a073e991ca243bc20ab1484a9100 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 23 Jan 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-01-23 --- pc/ether509.c | 53 ++++++++++++++++++++++++++++++++++++++++++------- port/chan.c | 12 +++++------ port/devenv.c | 3 --- port/devkprof.c | 10 +++++----- port/stil.c | 6 +++--- port/stip.c | 6 +++--- power/main.c | 8 ++++---- ss/l.s | 10 ++++++++-- ss/mmu.c | 6 +++--- 9 files changed, 78 insertions(+), 36 deletions(-) diff --git a/pc/ether509.c b/pc/ether509.c index fd750d29e9958321b1fd80424e0fab8a654a2c33..7b33b09ccf27242b28a826eb89462861b7b38830 100644 --- a/pc/ether509.c +++ b/pc/ether509.c @@ -17,6 +17,7 @@ enum { StartCoax = 0x02, /* Start Coaxial Transceiver */ RxDisable = 0x03, /* RX Disable */ RxEnable = 0x04, /* RX Enable */ + RxReset = 0x05, /* RX Reset */ RxDiscard = 0x08, /* RX Discard Top Packet */ TxEnable = 0x09, /* TX Enable */ TxDisable = 0x0A, /* TX Disable */ @@ -49,6 +50,7 @@ enum { /* Status/Interrupt Bits */ Latch = 0x0001, /* Interrupt Latch */ + Failure = 0x0002, /* Adapter Failure */ TxComplete = 0x0004, /* TX Complete */ TxAvailable = 0x0008, /* TX Available */ RxComplete = 0x0010, /* RX Complete */ @@ -71,6 +73,15 @@ enum { RxErrCRC = 0x2800, /* CRC */ RxError = 0x4000, /* Error */ RxEmpty = 0x8000, /* Incomplete or FIFO empty */ + + FIFOdiag = 0x04, /* window 4 */ + + /* FIFOdiag bits */ + TxOverrun = 0x0400, /* TX Overrrun */ + RxOverrun = 0x0800, /* RX Overrun */ + RxStatusOverrun = 0x1000, /* RX Status Overrun */ + RxUnderrun = 0x2000, /* RX Underrun */ + RxReceiving = 0x8000, /* RX Receiving */ }; #define COMMAND(board, cmd, a) outs(board->io+Command, ((cmd)<<11)|(a)) @@ -252,7 +263,7 @@ getdiag(Board *board) int bytes; COMMAND(board, SelectWindow, 4); - bytes = ins(board->io+0x04); + bytes = ins(board->io+FIFOdiag); COMMAND(board, SelectWindow, 1); return bytes & 0xFFFF; } @@ -341,21 +352,22 @@ transmit(Ctlr *ctlr) /* * If there's no room in the FIFO for this packet, * set up an interrupt for when space becomes available. + * Output packet must be a multiple of 4 in length and + * we need 4 bytes for the preamble. */ - if(tb->len > ins(board->io+TxFreeBytes)){ - COMMAND(board, SetTxAvailable, tb->len); + len = ROUNDUP(tb->len, 4); + if(len > ins(board->io+TxFreeBytes)+4){ + COMMAND(board, SetTxAvailable, len); break; } /* * There's room, copy the packet to the FIFO and free * the buffer back to the host. - * Output packet must be a multiple of 4 in length. */ - len = ROUNDUP(tb->len, 4)/2; outs(board->io+Fifo, tb->len); outs(board->io+Fifo, 0); - outss(board->io+Fifo, tb->pkt, len); + outss(board->io+Fifo, tb->pkt, len/2); tb->owner = Host; ctlr->ti = NEXT(ctlr->ti, ctlr->ntb); } @@ -366,11 +378,38 @@ static void interrupt(Ctlr *ctlr) { Board *board = ctlr->board; - ushort status; + ushort status, diag; uchar txstatus, x; status = ins(board->io+Status); + if(status & Failure){ + /* + * Adapter failure, try to find out why. + * Reset if necessary. + * What happens if Tx is active and we reset, + * need to retransmit? + * This probably isn't right. + */ + diag = getdiag(board); + print("ether509: status #%ux, diag #%ux\n", status, diag); + + if(diag & TxOverrun){ + COMMAND(board, TxReset, 0); + COMMAND(board, TxEnable, 0); + } + + if(diag & RxUnderrun){ + COMMAND(board, RxReset, 0); + attach(ctlr); + } + + if(diag & TxOverrun) + transmit(ctlr); + + return; + } + if(status & RxComplete){ receive(ctlr); wakeup(&ctlr->rr); diff --git a/port/chan.c b/port/chan.c index b74987afe08f9fa364d13e2c64881d598437e368..77d40518efb248a3d2b329b91c0156951fdbfa80 100644 --- a/port/chan.c +++ b/port/chan.c @@ -671,20 +671,20 @@ char* nextelem(char *name, char *elem) { int w; - char *end; + char *nend; Rune r; if(*name == '/') error(Efilename); - end = utfrune(name, '/'); - if(end == 0) - end = strchr(name, 0); - w = end-name; + nend = utfrune(name, '/'); + if(nend == 0) + nend = strchr(name, 0); + w = nend-name; if(w >= NAMELEN) error(Efilename); memmove(elem, name, w); elem[w] = 0; - while(name < end){ + while(name < nend){ name += chartorune(&r, name); if(rentries; qlock(from); for(e = from->entries; e; e = e->link) { -if(e->name == 0) panic("e->name == 0"); -for(p = e->name; *p; p++) if(p - e->name >= NAMELEN) panic("e->name %.*s", NAMELEN, e->name); ne = smalloc(sizeof(Evalue)); ne->name = smalloc(strlen(e->name)+1); strcpy(ne->name, e->name); diff --git a/port/devkprof.c b/port/devkprof.c index fe6a7741a8a5952131ad84c817a0638f28af5638..a9ab57b5fd0cefd79bc23c864d2c4f519453831d 100644 --- a/port/devkprof.c +++ b/port/devkprof.c @@ -124,7 +124,7 @@ kprofclose(Chan *c) long kprofread(Chan *c, void *va, long n, ulong offset) { - ulong end; + ulong tabend; ulong w, *bp; uchar *a, *ea; @@ -133,15 +133,15 @@ kprofread(Chan *c, void *va, long n, ulong offset) return devdirread(c, va, n, kproftab, Nkproftab, devgen); case Kprofdataqid: - end = kprof.nbuf*SZ; + tabend = kprof.nbuf*SZ; if(offset & (SZ-1)) error(Ebadarg); - if(offset >= end){ + if(offset >= tabend){ n = 0; break; } - if(offset+n > end) - n = end-offset; + if(offset+n > tabend) + n = tabend-offset; n &= ~(SZ-1); a = va; ea = a + n; diff --git a/port/stil.c b/port/stil.c index b03c1533d793724514129d749c977b9ace6c343d..b5c9f3da77ce0691438376cb0c9b53cd9daf6075 100644 --- a/port/stil.c +++ b/port/stil.c @@ -736,16 +736,16 @@ void ilackproc(void *a) { Ipifc *ifc; - Ipconv **base, **p, **end, *s; + Ipconv **base, **p, **last, *s; Ilcb *ic; ifc = (Ipifc*)a; base = ifc->conv; - end = &base[Nipconv]; + last = &base[Nipconv]; for(;;) { tsleep(&ilackr, return0, 0, Iltickms); - for(p = base; p < end && *p; p++) { + for(p = base; p < last && *p; p++) { s = *p; ic = &s->ilctl; ic->timeout += Iltickms; diff --git a/port/stip.c b/port/stip.c index bc9884f4327547e83494befb4f4c89e3d6ab2078..6a91a8b4512c4c9175f341960e7d39c9324d75f0 100644 --- a/port/stip.c +++ b/port/stip.c @@ -370,7 +370,7 @@ ip_reassemble(int offset, Block *bp, Etherhdr *ip) ushort id; Block *bl, **l, *last, *prev; int ovlap, len, fragsize, pktposn; - int end; + int fend; /* Check ethrnet has handed us a contiguous buffer */ if(bp->next) @@ -453,10 +453,10 @@ ip_reassemble(int offset, Block *bp, Etherhdr *ip) /* Check to see if succeeding segments overlap */ if(bp->next) { l = &bp->next; - end = BLKFRAG(bp)->foff + BLKFRAG(bp)->flen; + fend = BLKFRAG(bp)->foff + BLKFRAG(bp)->flen; /* Take completely covered segements out */ while(*l){ - ovlap = end - BLKFRAG(*l)->foff; + ovlap = fend - BLKFRAG(*l)->foff; if(ovlap <= 0) break; fragstat.succ++; diff --git a/power/main.c b/power/main.c index 1feb5b9e3296b9688479c06b54e56d9cf0d1d5ce..b304287780a893b3ca39d2a0020b7cb7ffdd1a32 100644 --- a/power/main.c +++ b/power/main.c @@ -464,16 +464,16 @@ void confread(void) { char *line; - char *end; + char *lend; /* * process configuration file */ line = confbuf; - while(end = strchr(line, '\n')){ - *end = 0; + while(lend = strchr(line, '\n')){ + *lend = 0; confset(line); - line = end+1; + line = lend+1; } } diff --git a/ss/l.s b/ss/l.s index 6f219ac0a2aced76dea0a17292bc4a7e83484883..d534b847916ac60c6ebfd4cc7f428a866026efd0 100644 --- a/ss/l.s +++ b/ss/l.s @@ -7,12 +7,18 @@ TEXT start(SB), $-4 /* get virtual, fast */ /* we are executing in segment 0, mapped to pmeg 0. stack is there too */ - /* get virtual by mapping segment(KZERO) to pmeg 0., and next to 1 */ + /* get virtual by mapping segment(KZERO) to pmeg 0, and next to 1, etc. */ MOVW $KZERO, R7 MOVB R0, (R7, 3) - MOVW $(KZERO+BY2SEGM), R7 + ADD $(BY2SEGM), R7 MOVW $1, R9 MOVB R9, (R7, 3) + ADD $(BY2SEGM), R7 + MOVW $2, R9 + MOVB R9, (R7, 3) + ADD $(BY2SEGM), R7 + MOVW $3, R9 + MOVB R9, (R7, 3) /* now mapped correctly. jmpl to where we want to be */ MOVW $setSB(SB), R2 diff --git a/ss/mmu.c b/ss/mmu.c index 4dff6b14f820d82f0bd76f2515117c1c21764f1e..673915b9b5c4979083318b54c63b8ea39c1fe031 100644 --- a/ss/mmu.c +++ b/ss/mmu.c @@ -324,9 +324,9 @@ mmuinit(void) Ctx *ctx; /* - * mmuinit is entered with PMEG's 0 & 1 providing mappng - * for virtual addresses KZERO<->KZERO+2*BY2SEGM to physical - * 0<->2*BY2SEGM + * mmuinit is entered with PMEG's 0-3 providing mapping + * for virtual addresses KZERO<->KZERO+4*BY2SEGM to physical + * 0<->4*BY2SEGM */ compile();