From fa2bef9d67f8fc929acbaf5630f2867fa4963627 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 15 Feb 1995 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1995-02-15 --- carrera/main.c | 2 -- pc/clock.c | 18 +++++++++- pc/devata.c | 93 +++++++++++++++++++++++++------------------------ pc/devi82365.c | 5 +++ port/devaudio.c | 1 - port/portdat.h | 1 + port/proc.c | 7 ++-- 7 files changed, 75 insertions(+), 52 deletions(-) diff --git a/carrera/main.c b/carrera/main.c index a6e1e61dfa1146410f906c6cadfa66eb43262690..be3f7b031bff701cd35f421893d061a1f19d13d5 100644 --- a/carrera/main.c +++ b/carrera/main.c @@ -487,8 +487,6 @@ isaconfig(char *class, int ctlrno, ISAConf *isa) { if(strcmp(class, "audio") == 0 && ctlrno == 0){ strcpy(isa->type, "sb16"); - isa->port = 0x220; - isa->irq = 7; return 1; } return 0; diff --git a/pc/clock.c b/pc/clock.c index 713f6efe2db9333190f94f19197ce9e9db36f84d..8942583c7de4f9ee1b160cca1b5643cb01dbf7ef 100644 --- a/pc/clock.c +++ b/pc/clock.c @@ -107,7 +107,23 @@ static X86type *cputype; void delay(int l) { - aamloop(l*loopconst); + l *= loopconst; + if(l <= 0) + l = 1; + aamloop(l); +} + +/* + * microsecond delay + */ +void +microdelay(int l) +{ + l *= loopconst; + l /= 1000; + if(l <= 0) + l = 1; + aamloop(l); } void diff --git a/pc/devata.c b/pc/devata.c index 6f7127192a859afa1ed638c70867b3ffc4686440..3a84ed65ea48397b90ecaa6033b2e1e94adf1c05 100644 --- a/pc/devata.c +++ b/pc/devata.c @@ -8,7 +8,7 @@ #include "devtab.h" -#define DPRINT if(1)print +#define DPRINT if(0)print typedef struct Drive Drive; typedef struct Ident Ident; @@ -55,6 +55,9 @@ enum Sidle, Spowerdown, + /* something we have to or into the drive/head reg */ + DHmagic= 0xA0, + /* file types */ Qdir= 0, @@ -167,7 +170,7 @@ atagen(Chan *c, Dirtab *tab, long ntab, long s, Dir *dirp) return -1; dp = &ata[drive]; - if(s >= dp->npart) + if(dp->online == 0 || s >= dp->npart) return 0; pp = &dp->p[s]; @@ -179,47 +182,42 @@ atagen(Chan *c, Dirtab *tab, long ntab, long s, Dir *dirp) return 1; } -/* - * we assume drives 0 and 1 are on the first controller, 2 and 3 on the - * second, etc. - */ void atareset(void) { Drive *dp; Controller *cp; - int drive; uchar equip; char *p; - ata = xalloc(conf.nhard * sizeof(Drive)); - atac = xalloc(((conf.nhard+1)/2) * sizeof(Controller)); - - /* - * read nvram for number of ata drives (2 max) - */ equip = nvramread(0x12); - if(conf.nhard > 0 && (equip>>4) == 0) - conf.nhard = 0; - if(conf.nhard > 1 && (equip&0xf) == 0) - conf.nhard = 1; - if(conf.nhard > 2) - conf.nhard = 2; + if(equip == 0) + equip = 0x10; /* the Globalyst 250 lies */ - for(drive = 0; drive < conf.nhard; drive++){ - dp = &ata[drive]; - cp = &atac[drive/2]; - dp->drive = drive&1; + ata = xalloc(2 * sizeof(Drive)); + atac = xalloc(sizeof(Controller)); + + cp = atac; + cp->buf = 0; + cp->lastcmd = cp->cmd; + cp->cmd = 0; + cp->pbase = Pbase; + setvec(Hardvec, ataintr, 0); + + dp = ata; + if(equip & 0xf0){ + dp->drive = 0; dp->online = 0; dp->cp = cp; - if((drive&1) == 0){ - cp->buf = 0; - cp->lastcmd = cp->cmd; - cp->cmd = 0; - cp->pbase = Pbase; - setvec(Hardvec, ataintr, 0); - } + dp++; + } + if((equip & 0x0f)){ + dp->drive = 1; + dp->online = 0; + dp->cp = cp; + dp++; } + conf.nhard = dp - ata; if(conf.nhard && (p = getconf("spindowntime"))) spindowntime = atoi(p); @@ -576,7 +574,7 @@ ataxfer(Drive *dp, Partition *pp, int cmd, long start, long len, char *buf) outb(cp->pbase+Pcount, cp->nsecs); outb(cp->pbase+Psector, sec); - outb(cp->pbase+Pdh, 0x20 | (dp->drive<<4) | (dp->lba<<6) | head); + outb(cp->pbase+Pdh, DHmagic | (dp->drive<<4) | (dp->lba<<6) | head); outb(cp->pbase+Pcyllsb, cyl); outb(cp->pbase+Pcylmsb, cyl>>8); outb(cp->pbase+Pcmd, cmd); @@ -649,7 +647,7 @@ atasetbuf(Drive *dp, int on) ilock(&cp->reglock); cp->cmd = Csetbuf; outb(cp->pbase+Pprecomp, on ? 0xAA : 0x55); /* read look ahead */ - outb(cp->pbase+Pdh, 0x20 | (dp->drive<<4)); + outb(cp->pbase+Pdh, DHmagic | (dp->drive<<4)); outb(cp->pbase+Pcmd, Csetbuf); iunlock(&cp->reglock); @@ -733,7 +731,7 @@ ataident(Drive *dp) cp->cmd = Cident; cp->dp = dp; cp->buf = buf; - outb(cp->pbase+Pdh, 0x20 | (dp->drive<<4)); + outb(cp->pbase+Pdh, DHmagic | (dp->drive<<4)); outb(cp->pbase+Pcmd, Cident); iunlock(&cp->reglock); @@ -761,8 +759,7 @@ ataident(Drive *dp) dp->lba = 1; dp->sectors = (ip->lbasecs[0]) | (ip->lbasecs[1]<<16); dp->cap = dp->bytes * dp->sectors; - print("ata%d model %s with %d lba sectors\n", dp->drive, - id, dp->sectors); +print("\nata%d model %s with %d lba sectors\n", dp->drive, id, dp->sectors); } else { dp->lba = 0; @@ -770,16 +767,15 @@ ataident(Drive *dp) dp->cyl = ip->cyls; dp->heads = ip->heads; dp->sectors = ip->s2t; - print("ata%d model %s with default %d cyl %d head %d sec\n", dp->drive, - id, dp->cyl, dp->heads, dp->sectors); +/*print("\nata%d model %s with default %d cyl %d head %d sec\n", dp->drive, + id, dp->cyl, dp->heads, dp->sectors);/**/ if(ip->cvalid&(1<<0)){ /* use current settings */ dp->cyl = ip->ccyls; dp->heads = ip->cheads; dp->sectors = ip->cs2t; - print("\tchanged to %d cyl %d head %d sec\n", dp->cyl, - dp->heads, dp->sectors); +/*print("\tchanged to %d cyl %d head %d sec\n", dp->cyl, dp->heads, dp->sectors);/**/ } dp->cap = dp->bytes * dp->cyl * dp->heads * dp->sectors; } @@ -821,7 +817,7 @@ ataprobe(Drive *dp, int cyl, int sec, int head) outb(cp->pbase+Pcount, 1); outb(cp->pbase+Psector, sec+1); - outb(cp->pbase+Pdh, 0x20 | head | (dp->drive<<4)); + outb(cp->pbase+Pdh, DHmagic | head | (dp->lba<<6) | (dp->drive<<4)); outb(cp->pbase+Pcyllsb, cyl); outb(cp->pbase+Pcylmsb, cyl>>8); outb(cp->pbase+Pcmd, Cread); @@ -857,7 +853,7 @@ ataparams(Drive *dp) ataident(dp); if(dp->lba){ i = dp->sectors - 1; - if(ataprobe(dp, (i>>8)&0xffff, i&0xff, (i>>24)&0xf) == 0) + if(ataprobe(dp, (i>>8)&0xffff, (i&0xff)-1, (i>>24)&0xf) == 0) return; } else { if(ataprobe(dp, dp->cyl-1, dp->sectors-1, dp->heads-1) == 0) @@ -868,7 +864,7 @@ ataparams(Drive *dp) * the drive lied, determine parameters by seeing which ones * work to read sectors. */ -print("ata%d lied. probing...\n", dp->drive); +print("ata%d probing...\n", dp->drive); dp->lba = 0; for(i = 0; i < 32; i++) if(ataprobe(dp, 0, 0, i) < 0) @@ -1038,6 +1034,11 @@ atapart(Drive *dp) atareplinit(dp); } +enum +{ + Maxloop= 10000, +}; + /* * we get an interrupt for every sector transferred */ @@ -1062,7 +1063,7 @@ ataintr(Ureg *ur, void *arg) loop = 0; while((cp->status = inb(cp->pbase+Pstatus)) & Sbusy){ - if(++loop > 100) { + if(++loop > Maxloop) { DPRINT("cmd=%lux status=%lux\n", cp->cmd, inb(cp->pbase+Pstatus)); panic("ataintr: wait busy"); @@ -1082,7 +1083,7 @@ ataintr(Ureg *ur, void *arg) if(cp->sofar < cp->nsecs){ loop = 0; while(((cp->status = inb(cp->pbase+Pstatus)) & Sdrq) == 0) - if(++loop > 100) { + if(++loop > Maxloop) { DPRINT("cmd=%lux status=%lux\n", cp->cmd, inb(cp->pbase+Pstatus)); panic("ataintr: write"); @@ -1102,7 +1103,7 @@ ataintr(Ureg *ur, void *arg) case Cident: loop = 0; while((cp->status & (Serr|Sdrq)) == 0){ - if(++loop > 10000) { + if(++loop > Maxloop) { DPRINT("cmd=%lux status=%lux\n", cp->cmd, inb(cp->pbase+Pstatus)); panic("ataintr: read/ident"); @@ -1175,7 +1176,7 @@ hardclock(void) ilock(&cp->reglock); cp->cmd = Cstandby; outb(cp->pbase+Pcount, 0); - outb(cp->pbase+Pdh, 0x20 | (dp->drive<<4) | 0); + outb(cp->pbase+Pdh, DHmagic | (dp->drive<<4) | 0); outb(cp->pbase+Pcmd, cp->cmd); iunlock(&cp->reglock); dp->state = Sstandby; diff --git a/pc/devi82365.c b/pc/devi82365.c index 813f1777df2bca4731183b8a4f8c261c1c0ca529..23d828fdb8bee7f6ed61b953d5b019974af3e454 100644 --- a/pc/devi82365.c +++ b/pc/devi82365.c @@ -184,13 +184,17 @@ static void cisread(Slot*); static uchar rdreg(Slot *pp, int index) { + microdelay(10); outb(pp->cp->xreg, pp->base + index); + microdelay(10); return inb(pp->cp->dreg); } static void wrreg(Slot *pp, int index, uchar val) { + microdelay(10); outb(pp->cp->xreg, pp->base + index); + microdelay(10); outb(pp->cp->dreg, val); } @@ -687,6 +691,7 @@ i82365read(Chan *c, void *a, long n, ulong offset) return devdirread(c, a, n, 0, 0, pcmgen); case Qmem: case Qattr: + pp = slot + DEV(c); qlock(&pp->mlock); n = pcmread(DEV(c), p==Qattr, a, n, offset); qunlock(&pp->mlock); diff --git a/port/devaudio.c b/port/devaudio.c index fc7e2d5fb95e271fd2b80cddeb8b80bd02b3c236..9da866ff6eb8f1d97f0dad204413b9c42d95cb40 100644 --- a/port/devaudio.c +++ b/port/devaudio.c @@ -81,7 +81,6 @@ static struct int speed; /* pcm sample rate, doesnt change w stereo */ int major; /* SB16 major version number (sb 4) */ int minor; /* SB16 minor version number */ - char place[20]; /* static place to decode words */ Buf buf[Nbuf]; /* buffers and queues */ Queue empty; diff --git a/port/portdat.h b/port/portdat.h index 7df3351283b071a5151161e5421a44323c2fa24d..e6a95bea63752dad41f02f60f591375b641b0f7c 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -492,6 +492,7 @@ enum Proc_stopme = 1, /* devproc requests */ Proc_exitme, Proc_traceme, + Proc_exitbig, TUser = 0, /* Proc.time */ TSys, diff --git a/port/proc.c b/port/proc.c index ebb7e04cd66a85c7fb76c3ee70dc1b33d70b0643..0b38830e2c012605d5514af283f5594725959037 100644 --- a/port/proc.c +++ b/port/proc.c @@ -882,6 +882,10 @@ procctl(Proc *p) ulong s; switch(p->procctl) { + case Proc_exitbig: + spllo(); + pexit("Killed: Insufficient physical memory", 1); + case Proc_exitme: spllo(); /* pexit has locks in it */ pexit("Killed", 1); @@ -962,7 +966,7 @@ killbig(void) max = l; } } - kp->procctl = Proc_exitme; + kp->procctl = Proc_exitbig; for(i = 0; i < NSEG; i++) { s = kp->seg[i]; if(s != 0 && canqlock(&s->lk)) { @@ -971,7 +975,6 @@ killbig(void) } } print("%d: %s killed because no swap configured\n", kp->pid, kp->text); - postnote(kp, 1, "killed: proc too big", NExit); } /*