From 023f5277aa279aef626051dd1657bd151e5ca7b1 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 7 Sep 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-09-07 --- gnot/errno.h | 2 +- gnot/stream.c | 2 +- port/chan.c | 3 ++ port/devcons.c | 1 + port/stream.c | 114 +++++++++++++++++++++++++++++++------------------ power/dat.h | 1 + power/duart.c | 20 +++++++++ power/errno.h | 2 +- power/fns.h | 5 ++- power/io.h | 6 +-- power/main.c | 51 +++++++++------------- power/mem.h | 2 +- power/trap.c | 70 ++++++++++++++---------------- 13 files changed, 160 insertions(+), 119 deletions(-) diff --git a/gnot/errno.h b/gnot/errno.h index 9502813e1b4ca8524405cbef0d9533f816c302fe..f6093cb80d312acced140b59a489d9089d446cff 100644 --- a/gnot/errno.h +++ b/gnot/errno.h @@ -56,5 +56,5 @@ enum{ Ebadcnt, /* read count greater than requested */ Enofont, /* out of font descriptors */ Enovmem, /* virtual memory allocation failed */ - Egreg, /* rob made me do it */ + Egreg, /* ken hasn't implemented datakit */ }; diff --git a/gnot/stream.c b/gnot/stream.c index 3afd951b6e0eb3ab1ced2b60c4006e47be287774..0811be98c0d1a246f4573626404fdddfdd637ec2 100644 --- a/gnot/stream.c +++ b/gnot/stream.c @@ -246,7 +246,7 @@ padb(Block *bp, int n) nbp = allocb(n); nbp->wptr = nbp->lim; nbp->rptr = nbp->wptr - n; - nbp->next = nbp; + nbp->next = bp; return nbp; } } diff --git a/port/chan.c b/port/chan.c index 8f759071cdb0c6919441d2b884367b17d3b516ec..5db16ffadb35821a9190612fee4af42f5bc97a4c 100644 --- a/port/chan.c +++ b/port/chan.c @@ -96,11 +96,14 @@ loop: void close(Chan *c) { + if(c->flag & CFREE) + panic("close"); if(decref(c) == 0){ if(!waserror()){ (*devtab[c->type].close)(c); poperror(); } + c->flag = CFREE; lock(&chanalloc); c->next = chanalloc.free; chanalloc.free = c; diff --git a/port/devcons.c b/port/devcons.c index 694b3c9d7f9bad81a008affa49db3352bca38e93..d37f190e65718a58ad274dc1aab341c832a4a6c3 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -169,6 +169,7 @@ panic(char *fmt, ...) n = doprint(buf+7, buf+sizeof(buf), fmt, (&fmt+1)) - buf; buf[n] = '\n'; putstrn(buf, n+1); + dumpstack(); exit(); } diff --git a/port/stream.c b/port/stream.c index fbe4f530e32493c2d550618a86d242faec30565b..9c65b4161f06682796d39dbd4e7fc82ed5ed0db9 100644 --- a/port/stream.c +++ b/port/stream.c @@ -24,6 +24,19 @@ Qinfo procinfo = { stputq, nullput, 0, 0, "process" }; */ static Qinfo *lds[Nlds+1]; +void +newqinfo(Qinfo *qi) +{ + int i; + + for(i=0; isize){ - if(bcp->size > left){ - left = bcp->size>4096 ? bcp->size : 4096; - ptr = (uchar *)ialloc(left, 1); - } - bp->base = ptr; - ptr += bcp->size; - left -= bcp->size; - } + if(bcp->size) + bp->base = (uchar *)ialloc(bcp->size, i == 0); bp->lim = bp->base + bcp->size; bp->flags = class; freeb(bp); @@ -487,6 +478,54 @@ getb(Blist *q) return bp; } +/* + * make sure the first block has n bytes + */ +Block * +pullup(Block *bp, int n) +{ + Block *nbp; + int i; + + /* + * this should almost always be true, the rest it + * just for to avoid every caller checking. + */ + if(BLEN(bp) >= n) + return bp; + + /* + * if not enough room in the first block, + * add another to the front of the list. + if(bp->lim - bp->rptr < n){ + nbp = allocb(n); + nbp->next = bp; + bp = nbp; + } + + /* + * copy bytes from the trailing blocks into the first + */ + n -= BLEN(bp); + while(nbp = bp->next){ + i = BLEN(nbp); + if(i > n) { + memcpy(bp->wptr, nbp->rptr, n); + bp->wptr += n; + nbp->rptr += n; + return bp; + } else { + memcpy(bp->wptr, nbp->rptr, i); + bp->wptr += i; + bp->next = nbp->next; + nbp->next = 0; + freeb(nbp); + } + } + freeb(bp); + return 0; +} + /* * grow the front of a list of blocks by n bytes */ @@ -586,6 +625,14 @@ streamparse(char *name, Block *bp) return 0; } +/* + * the per stream directory structure + */ +Dirtab streamdir[]={ + "data", Sdataqid, 0, 0600, + "ctl", Sctlqid, 0, 0600, +}; + /* * A stream device consists of the contents of streamdir plus * any directory supplied by the actual device. @@ -1150,20 +1197,3 @@ streamstat(Chan *c, char *db, char *name) devdir(c, c->qid, name, n, 0, &dir); convD2M(&dir, db); } - -/* - * announce a line discipline that can be pushed - */ -void -newqinfo(Qinfo *qi) -{ - int i; - - for(i=0; icmnd = ENB_TX; duart->data = c; } + +void +duartputs(char *s) +{ + int i; + while(*s){ + duartputc(*s++); + } + for(i=0; i < 1000000; i++) + ; +} + +void +iprint(char *s, void *a, void *b, void *c, void *d) +{ + char buf[1024]; + + sprint(buf, s, a, b, c, d); + duartputs(buf); +} diff --git a/power/errno.h b/power/errno.h index 5f5c20bbfe5cad0b5d3294757770fd5b5fa42051..d23af7433fb18e67d3a2d7d3a04b142353048053 100644 --- a/power/errno.h +++ b/power/errno.h @@ -51,5 +51,5 @@ enum{ Ebadcnt, /* read count greater than requested */ Enoannounce, /* listening on an unannounced network connection */ Enovmem, /* virtual memory allocation failed */ - Egreg, /* rob made me do it */ + Egreg, /* ken hasn't implemented datakit */ }; diff --git a/power/fns.h b/power/fns.h index b9f9ec7bd9c38385cb22267b470a1a15fb1cd2d7..3aecfa837eb005aacd73233792d654da2e397220 100644 --- a/power/fns.h +++ b/power/fns.h @@ -43,6 +43,7 @@ int devwalk(Chan*, char*, Dirtab*, int, Devgen*); void duartinit(void); void duartintr(void); int duartputc(int); +void duartputs(char*); void duartreset(void); void duartxmit(int); void dumpregs(Ureg*); @@ -97,7 +98,6 @@ Orig *lookorig(ulong, ulong, int, Chan*); void machinit(void); void mapstack(Proc*); int mount(Chan*, Chan*, int); -void mpbuserror(void); Chan *namec(char*, int, int, ulong); void nexterror(void); Alarm *newalarm(void); @@ -160,11 +160,14 @@ Seg *seg(Proc*, ulong); int segaddr(Seg*, ulong, ulong); int setlabel(Label*); void setvmevec(int, void (*)(int)); +void sinit(void); char* skipslash(char*); void sleep(Rendez*, int(*)(void*), void*); +uchar* smap(int, uchar*); int splhi(void); int spllo(void); void splx(int); +void sunmap(int, uchar*); Devgen streamgen; void streamclose(Chan*); int streamenter(Stream*); diff --git a/power/io.h b/power/io.h index c540598170401ec437a2cc747da4bfcb10c3e88d..c8f207e133ea2d5e54ee20d4dbc1f980ceecdac2 100644 --- a/power/io.h +++ b/power/io.h @@ -44,8 +44,8 @@ struct SBCC #define LANCERAM IO2(uchar, 0xE00000) #define LANCEEND IO2(uchar, 0xF00000) -#define LANCE3RAM IO2(uchar, 0xFF4000) -#define LANCE3END IO2(uchar, 0xFF8000) +#define LANCE3RAM IO2(ushort, 0xFF4000) +#define LANCE3END IO2(ushort, 0xFF8000) #define LANCERDP IO2(ushort, 0xFC0002) #define LANCERAP IO2(ushort, 0xFC000a) #define LANCEID IO2(ushort, 0xFF0002) @@ -102,4 +102,4 @@ enum { Scsi0map, /* SCSI bus 0 address space */ Nomap, }; -#define WRITEMAP IO2(ulong, 0xFA0000); +#define WRITEMAP IO2(ulong, 0xFA0000) diff --git a/power/main.c b/power/main.c index 496162d6097c92b141f4159b26bf8ae11115b147..ed90255ab1927be90e7e571b805fd5a55f6093af 100644 --- a/power/main.c +++ b/power/main.c @@ -35,17 +35,13 @@ char confbuf[4*1024]; char sysname[64]; /* - * IO board type, number of interrupt levels, and interrupt enable mask + * IO board type */ int ioid; -int iolevels; -int iomask; void main(void) { - int i; - machinit(); active.exiting = 0; active.machs = 1; @@ -61,12 +57,12 @@ main(void) clockinit(); alarminit(); ioboardinit(); + ioboardid(); chandevreset(); streaminit(); sysloginit(); pageinit(); userinit(); - ioboardid(); launchinit(); schedinit(); } @@ -113,16 +109,16 @@ ioboardid(void) { switch(ioid){ case IO2R1: - print("IO2 revision 1\n"); + iprint("IO2 revision 1\n"); break; case IO2R2: - print("IO2 revision 2\n"); + iprint("IO2 revision 2\n"); break; case IO3R1: - print("IO3 revision 1\n"); + iprint("IO3 revision 1\n"); break; default: - print("unknown IO board\n"); + iprint("unknown IO board\n"); break; } } @@ -135,31 +131,16 @@ void ioboardinit(void) { long i; - int intrs; - /* - * set up interrupts based on IO board type - */ ioid = *IOID; - switch(ioid){ - case IO2R1: - case IO2R2: - iolevels = 8; - iomask = 0xff; - break; - case IO3R1: - iolevels = 11; - iomask = 0x7fe; - break; - } /* * reset VME bus (MODEREG is on the IO2) */ - MODEREG->resetforce = (1<<1); + MODEREG->resetforce = (1<<1) | (1<<0); for(i=0; i<1000000; i++) ; - MODEREG->resetforce = 0; + MODEREG->resetforce = (1<<0); MODEREG->masterslave = (SLAVE<<4) | MASTER; /* @@ -169,9 +150,9 @@ ioboardinit(void) setvmevec(i, novme); /* - * tell IO2 to send all interrupts to CPU 0's SBCC + * tell IO2 to sent all interrupts to CPU 0's SBCC */ - for(i=0; ii[i].vec = 0<<8; /* @@ -191,13 +172,13 @@ ioboardinit(void) * The SBCC 16 bit registers are read/written as ulong, but only * bits 23-16 and 7-0 are meaningful. */ - SBCCREG->fintenable |= iomask; /* turn on all interrupts */ + SBCCREG->fintenable |= 0xff; /* allow all interrupts on the IO2 */ SBCCREG->idintenable |= 0x800000; /* allow interrupts from the IO2 */ /* * enable all interrupts on the IO2 */ - *IO2SETMASK = iomask; + *IO2SETMASK = 0xff; } void @@ -605,6 +586,11 @@ confinit(void) conf.npage0 = i*1024/4; conf.npage = conf.npage0; + /* + * clear MP bus error caused by sizing memory + */ + i = *SBEADDR; + /* * set minimal default values */ @@ -628,6 +614,9 @@ confinit(void) conf.npte = 4 * conf.npage; conf.nqueue = 5 * conf.nstream; conf.nblock = 16 * conf.nstream; + conf.nnoifc = 1; + conf.nnoconv = 32; + conf.nurp = 256; confread(); diff --git a/power/mem.h b/power/mem.h index b344341aa5bd8e3529bf261fbd702797e69fcb8f..4c82935e39585ca021a0e1602fc16908a711b5e6 100644 --- a/power/mem.h +++ b/power/mem.h @@ -109,7 +109,7 @@ #define USTKTOP KZERO /* byte just beyond user stack */ #define TSTKTOP (USERADDR+100*BY2PG) /* top of temporary stack */ #define KZERO KSEG0 /* base of kernel address space */ -#define KTZERO (KSEG0+0x20000) /* first address in kernel text */ +#define KTZERO (KZERO+0x20000) /* first address in kernel text */ #define USTACKSIZE (4*1024*1024) /* size of user stack */ /* * Exception codes diff --git a/power/trap.c b/power/trap.c index 75ac2fe00732c93d7d8a0570efcc3200fa7c8ca5..a0d78d497619f8c6fe37e8efd35daa8c3809d536 100644 --- a/power/trap.c +++ b/power/trap.c @@ -179,14 +179,6 @@ trap(Ureg *ur) } } -void -mpbuserror(void) -{ - print("io2 mp bus error %d %lux %lux\n", 0, - *MPBERR0, *MPBERR1); - *MPBERR0 = 0; -} - void intr(ulong cause, ulong pc) { @@ -205,7 +197,7 @@ intr(ulong cause, ulong pc) if(cause & INTR5){ if(!(*MPBERR1 & (1<<8))){ - print("MP bus error %lux %lux\n", *MPBERR0, *MPBERR1); /**/ + iprint("MP bus error %lux %lux\n", *MPBERR0, *MPBERR1); /**/ *MPBERR0 = 0; i = *SBEADDR; } @@ -235,34 +227,33 @@ intr(ulong cause, ulong pc) /* * 5a. process lance, scsi */ + loop: if(pend & 1) { v = INTVECREG->i[0].vec; - if(!(v & (1<<12))) - mpbuserror(); - if(!(v & (1<<2))) - lanceintr(); - if(!(v & (1<<1))) - lanceparity(); - if(!(v & (1<<0))) - print("SCSI interrupt\n"); - } - if(pend & (1<<10)) { - v = INTVECREG->i[10].vec; - if(!(v & (1<<12))) - mpbuserror(); - lance3intr(); - } - if(pend & (1<<8)) { - v = INTVECREG->i[10].vec; - if(!(v & (1<<12))) - mpbuserror(); - print("SCSI0 interrupt\n"); - } - if(pend & (1<<9)) { - v = INTVECREG->i[10].vec; - if(!(v & (1<<12))) - mpbuserror(); - print("SCSI1 interrupt\n"); + if(!(v & (1<<12))){ + print("io2 mp bus error %d %lux %lux\n", 0, + *MPBERR0, *MPBERR1); + *MPBERR0 = 0; + } + switch(ioid){ + case IO2R1: + case IO2R2: + if(!(v & (1<<2))) + lanceintr(); + if(!(v & (1<<1))) + lanceparity(); + if(!(v & (1<<0))) + print("SCSI interrupt\n"); + break; + case IO3R1: + if(v & (1<<2)) + lance3intr(); + if(v & (1<<1)) + print("SCSI 1 interrupt\n"); + if(v & (1<<0)) + print("SCSI 0 interrupt\n"); + break; + } } /* * 5b. process vme @@ -272,8 +263,11 @@ intr(ulong cause, ulong pc) for(i=1; pend; i++) { if(pend & 1) { v = INTVECREG->i[i].vec; - if(!(v & (1<<12))) - mpbuserror(); + if(!(v & (1<<12))){ + print("io2 mp bus error %d %lux %lux\n", i, + *MPBERR0, *MPBERR1); + *MPBERR0 = 0; + } v &= 0xff; (*vmevec[v])(v); } @@ -282,7 +276,7 @@ intr(ulong cause, ulong pc) /* * 6. re-enable interrupts */ - *IO2SETMASK = iomask; + *IO2SETMASK = 0xff; cause &= ~INTR5; } if(cause)