From 9eb51cf5371a6fdfa6fcbae8fdb23ee2da672f32 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 5 Apr 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-04-05 --- carrera/main.c | 2 +- port/devmnt.c | 42 +++++++++++++++++++----------------------- port/portfns.h | 3 ++- port/sysfile.c | 42 +++++++++++++++++++++++++++++++++++++++++- port/systab.h | 6 +++--- power/conf.h | 1 + power/dat.h | 7 +++++++ power/lock.c | 34 ++++++++++++++++++++++++++++++++++ power/mem.h | 4 +++- 9 files changed, 111 insertions(+), 30 deletions(-) diff --git a/carrera/main.c b/carrera/main.c index 9db41f092b64793de522c6d9be48128760a6b351..ef2d4c89ddbb5b6f0dfb4e93414e79a02d6f3653 100644 --- a/carrera/main.c +++ b/carrera/main.c @@ -503,7 +503,7 @@ rdbginit(void) { uchar *vec; ulong jba; -return; +return;/**/ /* Only interested in the PC */ Mipsjmpbuf.pc = 0x8001C020; diff --git a/port/devmnt.c b/port/devmnt.c index df2867fc71908a5971f6591cce1ed9a6a7fb17f5..fc1f542316005ea47357c1816039e39063af57fd 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -79,7 +79,6 @@ Chan* mntattach(char *muxattach) { Mnt *m; - int nest; Chan *c, *mc; char buf[NAMELEN]; struct bogus{ @@ -168,23 +167,6 @@ mntattach(char *muxattach) mattach(m, c, bogus.spec); poperror(); -#ifdef STUPIDHACK - /* Work out how deep we are nested and reduce the blocksize - * accordingly - */ - nest = 0; - mc = m->c; - while(mc) { - if(mc->type != devno('M', 0)) - break; - nest++; - if(mc->mntptr == 0) - break; - mc = mc->mntptr->c; - } - m->blocksize -= nest * 32; -#endif STUPIDHACK - /* * Detect a recursive mount for a mount point served by exportfs. * If CHDIR is clear in the returned qid the foreign server is @@ -495,6 +477,12 @@ mntwstat(Chan *c, char *dp) mntfree(r); } +long +mntread9p(Chan *c, void *buf, long n, ulong offset) +{ + return mntrdwr(Tread, c, buf, n, offset, 1); +} + long mntread(Chan *c, void *buf, long n, ulong offset) { @@ -563,9 +551,14 @@ mntrdwr(int type, Chan *c, void *buf, long n, ulong offset, int p9msg) r->request.fid = c->fid; r->request.offset = offset; r->request.data = uba; - if(p9msg) - r->request.count = limit(n, m->blocksize + MAXMSG - 20); - else + if(p9msg) { + if(n > MAXRPC-32){ + if(type == Twrite) + error("write9p too long"); + n = MAXRPC-32; + } + r->request.count = n; + } else r->request.count = limit(n, m->blocksize); mountrpc(m, r); nr = r->reply.count; @@ -641,7 +634,7 @@ mountio(Mnt *m, Mntrpc *r) } else { if(devchar[m->c->type] == L'M'){ - if(mntwrite9p(m->c, r->rpc, n, 0) != n) + if(mntrdwr(Twrite, m->c, r->rpc, n, 0, 1) != n) error(Emountrpc); }else{ if((*devtab[m->c->type].write)(m->c, r->rpc, n, 0) != n) @@ -696,7 +689,10 @@ mntrpcread(Mnt *m, Mntrpc *r) } r->reply.type = 0; r->reply.tag = 0; - n = devtab[m->c->type].read(m->c, r->rpc, MAXRPC, 0); + if(devchar[m->c->type] == L'M') + n = mntrdwr(Tread, m->c, r->rpc, MAXRPC, 0, 1); + else + n = devtab[m->c->type].read(m->c, r->rpc, MAXRPC, 0); poperror(); if(n == 0) continue; diff --git a/port/portfns.h b/port/portfns.h index 16d959c996ea2791c0f9dcd010dc7ae5dac44285..0adf42e6705970bed43994c40a56116a04fb2cee 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -135,7 +135,9 @@ void mfreeseg(Segment*, ulong, int); void mmurelease(Proc*); void mmuswitch(Proc*); void mntdump(void); +long mntread9p(Chan*, void*, long, ulong); void mntrepl(char*); +long mntwrite9p(Chan*, void*, long, ulong); int mount(Chan*, Chan*, int, char*); void mountfree(Mount*); void mousebuttons(int); @@ -262,7 +264,6 @@ void* vmemchr(void*, int, int); void wakeup(Rendez*); Chan* walk(Chan*, char*, int); void wlock(RWlock*); -long mntwrite9p(Chan*, void*, long, ulong); void wunlock(RWlock*); #define xalloc(s) xallocz(s, 1) void* xallocz(ulong, int); diff --git a/port/sysfile.c b/port/sysfile.c index 3333f5f245b4c8f77b687b118cff1dc8f6d49778..f79b525b21663b4734f408e3ff40ab8d6d31dc4d 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -287,6 +287,47 @@ unionread(Chan *c, void *va, long n) return 0; } +long +sysread9p(ulong *arg) +{ + int dir; + long n; + Chan *c; + + validaddr(arg[1], arg[2], 1); + c = fdtochan(arg[0], OREAD, 1, 1); + if(waserror()) { + close(c); + nexterror(); + } + + n = arg[2]; + dir = c->qid.path&CHDIR; + + if(dir) { + n -= n%DIRLEN; + if(c->offset%DIRLEN || n==0) + error(Etoosmall); + } + + if(dir && c->mnt) + n = unionread(c, (void*)arg[1], n); + else if(devchar[c->type] != L'M') + n = (*devtab[c->type].read)(c, (void*)arg[1], n, c->offset); + else + n = mntread9p(c, (void*)arg[1], n, c->offset); + + + lock(c); + c->offset += n; + unlock(c); + + poperror(); + close(c); + + return n; +} + long sysread(ulong *arg) { @@ -345,7 +386,6 @@ syswrite9p(ulong *arg) n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2], c->offset); else n = mntwrite9p(c, (void*)arg[1], arg[2], c->offset); - lock(c); c->offset += n; unlock(c); diff --git a/port/systab.h b/port/systab.h index a8c967f1ef503e50ccb8cf5722637d7d067538ae..2df1a8c90f0b944efa4f9af5df7ec37e5e66be61 100644 --- a/port/systab.h +++ b/port/systab.h @@ -41,7 +41,7 @@ Syscall sysrendezvous; Syscall sysunmount; Syscall syswait; Syscall syswrite9p; -Syscall ; +Syscall sysread9p; Syscall ; Syscall sysdeath; @@ -84,7 +84,7 @@ Syscall *systab[]={ [UNMOUNT] sysunmount, [WAIT] syswait, [WRITE9P] syswrite9p, - + [READ9P] sysread9p, }; @@ -127,6 +127,6 @@ char *sysctab[]={ [UNMOUNT] "Unmount", [WAIT] "Wait", [WRITE9P] "Write9p", - + [READ9P] "Read9p", }; diff --git a/power/conf.h b/power/conf.h index 6153f757ada7064914fbbcde5bc951dcd55ed379..9d4c3f161ceef9382317dc5ec18d9a0f6a10aa09 100644 --- a/power/conf.h +++ b/power/conf.h @@ -15,6 +15,7 @@ Conftab conftab[] = { {"arp", &conf.arp }, {"frag", &conf.frag }, {"debugger", &conf.debugger }, + {"ialloc", &conf.ialloc }, { 0, 0 }, }; diff --git a/power/dat.h b/power/dat.h index c74219763d64787e3aa6e9e1fb6c1d1200722ada..5493811a69bf6305b2096da442a5852b7cc0a7a0 100644 --- a/power/dat.h +++ b/power/dat.h @@ -25,6 +25,7 @@ struct Lock { int val; ulong pc; + ulong sr; }; struct Label @@ -51,6 +52,7 @@ struct Conf ulong arp; /* Arp table size */ ulong frag; /* Ip fragment assemble queue size */ ulong debugger; /* use processor 1 as a kernel debugger */ + ulong ialloc; /* bytes available for interrupt time allocation */ }; /* @@ -134,6 +136,11 @@ struct Mach Schedq hiq; Schedq loq; + Callbk* cbin; + Callbk* cbout; + Callbk* cbend; + Callbk calls[NCALLBACK]; + int stack[1]; }; diff --git a/power/lock.c b/power/lock.c index 67e3b596736d12118eb8551f0834388e753f687d..dc304a032c135c2f2827caa94cc6855e6bb6efcd 100644 --- a/power/lock.c +++ b/power/lock.c @@ -114,6 +114,29 @@ lock(Lock *lk) dumpstack(); } +void +ilock(Lock *lk) +{ + int *hwsem, hash; + ulong x; + + x = splhi(); + hash = lhash(lk); + hwsem = (int*)SBSEM+hash; + + for(;;) { + if(muxlock(hwsem, &lk->val)){ + lk->sr = x; + return; + } + while(lk->val) + ; + } + splx(x); + print("lock loop %lux pc %lux held by pc %lux\n", lk, getcallerpc(lk), lk->pc); + dumpstack(); +} + int canlock(Lock *lk) { @@ -129,3 +152,14 @@ unlock(Lock *l) l->pc = 0; l->val = 0; } + +void +iunlock(Lock *l) +{ + ulong sr; + + sr = l->sr; + l->pc = 0; + l->val = 0; + splx(sr); +} diff --git a/power/mem.h b/power/mem.h index c6251e4f5d7bfc87e3cec30d862f8dffa3232eb3..43bbf782c6045dbd8507cb41936f25cdb47d92a5 100644 --- a/power/mem.h +++ b/power/mem.h @@ -9,10 +9,12 @@ #define BI2BY 8 /* bits per byte */ #define BI2WD 32 /* bits per word */ #define BY2WD 4 /* bytes per word */ +#define BY2V 8 /* bytes per very long word */ #define BY2PG 4096 /* bytes per page */ #define WD2PG (BY2PG/BY2WD) /* words per page */ #define PGSHIFT 12 /* log(BY2PG) */ -#define PGROUND(s) (((s)+(BY2PG-1))&~(BY2PG-1)) +#define ROUND(s, sz) (((s)+(sz-1))&~(sz-1)) +#define PGROUND(s) ROUND(s, BY2PG) #define ICACHESIZE (64*1024) /* Power series */ #define MAXMACH 4 /* max # cpus system can run */