From 65e59791087fd19f9ccdc91c2a3543a92aab96d7 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 25 Apr 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-04-25 --- pc/devether.c | 31 +++++++++++++++++++------------ pc/devhard.c | 41 ++++++++++++++++++++++++++++++++--------- pc/l.s | 2 +- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/pc/devether.c b/pc/devether.c index eec09709377d1f4ebdfb7583b1e29e9c51a0207c..ae169899bec0de0527da76d2209d52df5329bdbb 100644 --- a/pc/devether.c +++ b/pc/devether.c @@ -108,9 +108,10 @@ struct Ctlr { }; static Ctlr ctlr[Nctlr]; -void -etherinit(void) +Chan* +etherattach(char *spec) { + return devattach('l', spec); } Chan* @@ -179,7 +180,7 @@ isobuf(void *arg) { Ctlr *cp = arg; - cp->tb[cp->th].owner == Host; + return cp->tb[cp->th].owner == Host; } static void @@ -246,7 +247,6 @@ etheroput(Queue *q, Block *bp) * wait till we get an output buffer. * should try to restart. */ -print("oput sleep\n"); sleep(&cp->tr, isobuf, cp); tb = &cp->tb[cp->th]; @@ -291,7 +291,6 @@ print("oput sleep\n"); freeb(bp); qunlock(&cp->tlock); -print("oput done\n"); poperror(); } @@ -509,8 +508,8 @@ etherreset(void) cp->net.info[1].fill = typefill; } -Chan* -etherattach(char *spec) +void +etherinit(void) { int ctlrno = 0; Ctlr *cp = &ctlr[ctlrno]; @@ -536,7 +535,6 @@ etherattach(char *spec) sprint(cp->name, "ether%dkproc", ctlrno); kproc(cp->name, etherkproc, cp); } - return devattach('l', spec); } typedef struct { @@ -610,7 +608,6 @@ wd8013reset(Ctlr *cp) int i; uchar msr; -print("reset\n"); cp->rb = ialloc(sizeof(Buffer)*Nrb, 0); cp->nrb = Nrb; cp->tb = ialloc(sizeof(Buffer)*Ntb, 0); @@ -705,7 +702,7 @@ wd8013receive(Ctlr *cp) uchar data[256-4]; } Ring; Ring *p; - int len; + int len0, len1; bnry = IN(hw, r.bnry); next = NEXT(bnry, HOWMANY(hw->ramsz, 256)); @@ -719,12 +716,22 @@ wd8013receive(Ctlr *cp) break; cp->inpackets++; p = &((Ring*)hw->ram)[next]; - len = (p->len1<<8)|p->len0; + len0 = (p->len1<<8)|p->len0-4; + len1 = 0; rb = &cp->rb[cp->ri]; if(rb->owner == Interface){ - rb->len = len; + rb->len = len0; /*copy in packet*/ + if(p->data+len0 >= (uchar*)hw->ram+hw->ramsz){ + len1 = p->data+len0 - (uchar*)hw->ram+hw->ramsz; + len0 = (uchar*)hw->ram+hw->ramsz - p->data; + } + memmove((uchar*)&rb->pkt, p->data, len0); + if(len1) + memmove((uchar*)&rb->pkt+len0, + (uchar*)hw->ram+ROUNDUP(sizeof(Etherpkt), 256), + len1); rb->owner = Host; cp->ri = NEXT(cp->ri, Nrb); } diff --git a/pc/devhard.c b/pc/devhard.c index 941c97ccc182af8980332110ae2df1754f4880de..8116c65b9ede31ad07253df418944ad9d27baf07 100644 --- a/pc/devhard.c +++ b/pc/devhard.c @@ -128,6 +128,7 @@ struct Controller * current operation */ int cmd; /* current command */ + int lastcmd; /* debugging info */ Rendez r; /* wait here for command termination */ char *buf; /* xfer buffer */ int tcyl; /* target cylinder */ @@ -201,6 +202,7 @@ hardreset(void) dp->cp = cp; if((drive&1) == 0){ cp->buf = ialloc(Maxxfer, 0); + cp->lastcmd = cp->cmd; cp->cmd = 0; cp->pbase = Pbase + (cp-hardc)*8; /* BUG!! guessing */ setvec(Hardvec + (cp-hardc)*8, hardintr); /* BUG!! guessing */ @@ -674,11 +676,15 @@ hardintr(Ureg *ur) loop = 0; while((cp->status = inb(cp->pbase+Pstatus)) & Sbusy) - if(++loop > 10000) - panic("hardintr 0"); + if(++loop > 10000) { + print("cmd=%lux status=%lux\n", + cp->cmd, inb(cp->pbase+Pstatus)); + panic("hardintr: wait busy"); + } switch(cp->cmd){ case Cwrite: if(cp->status & Serr){ + cp->lastcmd = cp->cmd; cp->cmd = 0; cp->error = inb(cp->pbase+Perror); wakeup(&cp->r); @@ -688,18 +694,30 @@ hardintr(Ureg *ur) if(cp->sofar < cp->nsecs){ loop = 0; while((inb(cp->pbase+Pstatus) & Sdrq) == 0) - if(++loop > 10000) - panic("hardintr 1"); + if(++loop > 10000) { + print("cmd=%lux status=%lux\n", + cp->cmd, inb(cp->pbase+Pstatus)); + panic("hardintr: write"); + } outss(cp->pbase+Pdata, &cp->buf[cp->sofar*dp->bytes], dp->bytes/2); } else{ + cp->lastcmd = cp->cmd; cp->cmd = 0; wakeup(&cp->r); } break; case Cread: case Cident: + loop = 0; + while((inb(cp->pbase+Pstatus) & Sbusy) != 0) + if(++loop > 10000) { + print("cmd=%lux status=%lux\n", + cp->cmd, inb(cp->pbase+Pstatus)); + panic("hardintr: wait busy"); + } if(cp->status & Serr){ + cp->lastcmd = cp->cmd; cp->cmd = 0; cp->error = inb(cp->pbase+Perror); wakeup(&cp->r); @@ -707,23 +725,28 @@ hardintr(Ureg *ur) } loop = 0; while((inb(cp->pbase+Pstatus) & Sdrq) == 0) - if(++loop > 10000) - panic("hardintr 2"); + if(++loop > 10000) { + print("cmd=%lux status=%lux\n", + cp->cmd, inb(cp->pbase+Pstatus)); + panic("hardintr: read/ident"); + } inss(cp->pbase+Pdata, &cp->buf[cp->sofar*dp->bytes], dp->bytes/2); cp->sofar++; if(cp->sofar >= cp->nsecs){ + cp->lastcmd = cp->cmd; cp->cmd = 0; wakeup(&cp->r); } break; case Csetbuf: + cp->lastcmd = cp->cmd; cp->cmd = 0; wakeup(&cp->r); break; - case 0: /* - * These don't seem to mean anything. Should we wakeup? - */ + case 0: + print("interrupt cmd=0, lastcmd=%02x status=%02x\n", + cp->lastcmd, cp->status); break; default: print("weird disk interrupt, cmd=%02x, status=%02x\n", diff --git a/pc/l.s b/pc/l.s index dc1e60b7704979d3574417b6342656833f1a29d5..9534569f0b1625fa2e450f6b743495414458cbe4 100644 --- a/pc/l.s +++ b/pc/l.s @@ -54,7 +54,7 @@ TEXT lowcore(SB),$0 MOVL AX,CR0 /* - * clear prefetch queue (wierd code to avoid optimizations) + * clear prefetch queue (weird code to avoid optimizations) */ CLC JCC flush