From 2e47c01ae3fdc519e8d391e55810f0d9f4cbc810 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 9 May 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-05-09 --- pc/devhard.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++---- port/qlock.c | 2 ++ port/stream.c | 2 -- power/clock.c | 5 ++++ power/io.h | 5 ++-- power/main.c | 2 ++ 6 files changed, 84 insertions(+), 10 deletions(-) diff --git a/pc/devhard.c b/pc/devhard.c index 56a5b560a721a1cbc7520248a320568c6e63019f..e42309968a5dad5b6235f20ef45ee517594595e4 100644 --- a/pc/devhard.c +++ b/pc/devhard.c @@ -10,6 +10,7 @@ typedef struct Drive Drive; typedef struct Ident Ident; typedef struct Controller Controller; typedef struct Partition Partition; +typedef struct Repl Repl; enum { @@ -42,8 +43,9 @@ enum Qdir= 0, Maxxfer= 4*1024, /* maximum transfer size/cmd */ - Maxread= 1024, /* maximum transfer size/read */ + Maxread= 4*1024, /* maximum transfer size/read */ Npart= 8+2, /* 8 sub partitions, disk, and partition */ + Nrepl= 16, /* maximum replacement blocks */ }; #define PART(x) ((x)&0xF) #define DRIVE(x) (((x)>>4)&0x7) @@ -94,6 +96,16 @@ struct Partition char name[NAMELEN+1]; }; +struct Repl +{ + Partition *p; + int nrepl; + ulong blk[Nrepl]; +}; + +#define PARTMAGIC "plan9 partitions" +#define REPLMAGIC "block replacements" + /* * a hard drive */ @@ -105,6 +117,7 @@ struct Drive int online; int npart; /* number of real partitions */ Partition p[Npart]; + Repl repl; ulong cap; /* total bytes */ int bytes; /* bytes/sector */ @@ -503,8 +516,7 @@ hardxfer(Drive *dp, Partition *pp, int cmd, long start, long len) cp->dp = dp; cp->sofar = 0; cp->status = 0; -/*print("xfer:\ttcyl %d, tsec %d, thead %d\n", cp->tcyl, cp->tsec, cp->thead); -print("\tnsecs %d, sofar %d\n", cp->nsecs, cp->sofar);/**/ + outb(cp->pbase+Pcount, cp->nsecs); outb(cp->pbase+Psector, cp->tsec); outb(cp->pbase+Pdh, 0x20 | (dp->drive<<4) | cp->thead); @@ -523,7 +535,7 @@ print("\tnsecs %d, sofar %d\n", cp->nsecs, cp->sofar);/**/ sleep(&cp->r, cmddone, cp); if(cp->status & Serr){ -print("hd%d err: status %lux, err %lux\n", dp-hard, cp->status, cp->error); +print("hd%d err: lsec %ld status %lux, err %lux\n", dp-hard, lsec, cp->status, cp->error); print("\ttcyl %d, tsec %d, thead %d\n", cp->tcyl, cp->tsec, cp->thead); print("\tnsecs %d, sofar %d\n", cp->nsecs, cp->sofar); error(Eio); @@ -602,10 +614,55 @@ hardident(Drive *dp) qunlock(cp); } + +/* + * Read block replacement table. + * The table is just ascii block numbers. + */ +static void +hardreplinit(Drive *dp) +{ + Controller *cp; + char *line[Nrepl+1]; + char *field[1]; + ulong n; + int i; + + /* + * check the partition is big enough + */ + if(dp->repl.p->end - dp->repl.p->start < Nrepl+1){ + dp->repl.p = 0; + return; + } + + cp = dp->cp; + + /* + * read replacement table from disk, null terminate + */ + hardxfer(dp, dp->repl.p, Cread, 0, dp->bytes); + cp->buf[dp->bytes-1] = 0; + + /* + * parse replacement table. + */ + n = getfields(cp->buf, line, Nrepl+1, '\n'); + if(strncmp(line[0], REPLMAGIC, sizeof(REPLMAGIC)-1)){ + dp->repl.p = 0; + return; + } + for(dp->repl.nrepl = 0, i = 1; i < n; i++, dp->repl.nrepl++){ + if(getfields(line[i], field, 1, ' ') != 1) + break; + if((dp->repl.blk[dp->repl.nrepl] = strtoul(field[1], 0, 0)) <= 0) + break; + } +} + /* * read partition table. The partition table is just ascii strings. */ -#define MAGIC "plan9 partitions" static void hardpart(Drive *dp) { @@ -638,6 +695,11 @@ hardpart(Drive *dp) pp->end = dp->p[0].end; dp->npart = 2; + /* + * initialise the bad-block replacement info + */ + dp->repl.p = 0; + /* * read partition table from disk, null terminate */ @@ -648,12 +710,14 @@ hardpart(Drive *dp) * parse partition table. */ n = getfields(cp->buf, line, Npart+1, '\n'); - if(strncmp(line[0], MAGIC, sizeof(MAGIC)-1) == 0){ + if(strncmp(line[0], PARTMAGIC, sizeof(PARTMAGIC)-1) == 0){ for(i = 1; i < n; i++){ pp++; if(getfields(line[i], field, 3, ' ') != 3) break; strncpy(pp->name, field[0], NAMELEN); + if(strncmp(pp->name, "repl", NAMELEN) == 0) + dp->repl.p = pp; pp->start = strtoul(field[1], 0, 0); pp->end = strtoul(field[2], 0, 0); if(pp->start > pp->end || pp->start >= dp->p[0].end) @@ -661,6 +725,8 @@ hardpart(Drive *dp) dp->npart++; } } + if(dp->repl.p) + hardreplinit(dp); qunlock(cp); poperror(); } diff --git a/port/qlock.c b/port/qlock.c index 7cb717dd91e237c7075b25c1a862ebe0e5d6efb5..3ee2d9644ecbba2f2e558b0902e7645eba22765e 100644 --- a/port/qlock.c +++ b/port/qlock.c @@ -10,6 +10,8 @@ qlock(QLock *q) { Proc *p, *mp; + if(u) + u->p->qlockpc = getcallerpc(((uchar*)&q) - sizeof(q)); lock(&q->use); if(!q->locked) { q->locked = 1; diff --git a/port/stream.c b/port/stream.c index 3e850080a34ef05e4fc819502e6d76518252950a..57e9de79b805a2ba81c73c484a6db335c1b634b4 100644 --- a/port/stream.c +++ b/port/stream.c @@ -1503,10 +1503,8 @@ dumpqueues(void) } print("%d queues\n", qcount); for(bcp=bclass; bcp<&bclass[Nclass]; bcp++){ - qlock(bcp); for(count = 0, bp = bcp->first; bp; count++, bp = bp->next) ; - qunlock(bcp); print("%d byte blocks: %d made %d free\n", bcp->size, bcp->made, count); } diff --git a/power/clock.c b/power/clock.c index 4f5f37362fea196e796051023dfcac96665d2921..9b3b2983a3cb39ef7a7d317278217fac04316e91 100644 --- a/power/clock.c +++ b/power/clock.c @@ -83,6 +83,11 @@ clock(Ureg *ur) i = *CLRTIM0; USED(i); m->ticks++; + if(m->ticks&(1<<4)) + LEDON(LEDpulse); + else + LEDOFF(LEDpulse); + if(m->machno == 0){ p = m->proc; if(p) { diff --git a/power/io.h b/power/io.h index 0d14f813790b44b8c9e456e478bdbb747498d492..64679e9f0808e285b6e0df34f9cc9dab63c8beaa 100644 --- a/power/io.h +++ b/power/io.h @@ -12,9 +12,10 @@ enum LEDhotintr= 1<<0, LEDclock= 1<<1, LEDfault= 1<<2, + LEDpulse= 1<<7, }; -#define LEDON(x) { m->ledval |= x; *LED = m->ledval; } -#define LEDOFF(x) { m->ledval &= ~x; *LED = m->ledval; } +#define LEDON(x) (m->ledval &= ~x, *LED = m->ledval) +#define LEDOFF(x) (m->ledval |= x, *LED = m->ledval) typedef struct SBCC SBCC; typedef struct Timer Timer; diff --git a/power/main.c b/power/main.c index 040838d0b7314f21e6d2abc8de207875c8b9c2c6..05a2b5c732a0980774fd02c2c9e1748c0f93607e 100644 --- a/power/main.c +++ b/power/main.c @@ -78,6 +78,8 @@ machinit(void) m->machno = n; m->stb = &stlb[n][0]; duartinit(); + + m->ledval = 0xff; } void