From 266f08c1e17c4ca3cf8de9ae9104bb6944b1d668 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 20 Aug 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-08-20 --- bitsy/fns.h | 1 + bitsy/l.s | 174 ++++++++++++++++++----------------------------- bitsy/power.c | 7 +- boot/boot.c | 27 ++------ boot/boot.h | 11 +-- boot/bootauth.c | 29 -------- boot/bootcache.c | 4 +- port/dev.c | 2 - port/devcons.c | 2 +- port/devdup.c | 2 +- port/devmnt.c | 55 ++++++++------- port/lib.h | 1 - port/portdat.h | 1 + port/sysfile.c | 1 - 14 files changed, 115 insertions(+), 202 deletions(-) diff --git a/bitsy/fns.h b/bitsy/fns.h index d754660afb88c433d56a8919352b71c8f94112b4..b60da056ab4ed5f95387040e79f1a070d4b636ba 100644 --- a/bitsy/fns.h +++ b/bitsy/fns.h @@ -7,6 +7,7 @@ void cacheflush(void); void cachewb(void); void cachewbaddr(void*); void cachewbregion(ulong, int); +void coma(ulong); void dcacheinvalidate(void); int cistrcmp(char*, char*); int cistrncmp(char*, char*, int); diff --git a/bitsy/l.s b/bitsy/l.s index 0dad65f8b89b7ff8fb7d96b716f8efe4a6fecdb6..63b014d68ae4d1f1fe8db28e10dc4096d0fd4293 100644 --- a/bitsy/l.s +++ b/bitsy/l.s @@ -672,121 +672,77 @@ loop: TEXT power_down(SB), $-4 - /* disable clock switching */ - MCR CpPWR, 0, R0, C(CpTest), C(0x2), 2 - - /* Adjust memory timing before lowering CPU clock - * Clock speed ajdustment without changing memory - * timing makes CPU hang in some cases - */ - MOVW $(MEMCONFREGS+0x1c),R0 - MOVW (R0),R1 /* mdrefr */ - ORR $(1<<22), R1 /* set K1DB2 */ - MOVW R1,(R0) - - /* delay 90us and set CPU PLL to lowest speed */ - /* fixes resume problem on high speed SA1110 */ + TEXT sa1100_power_off<>+0(SB),$8 + MOVW resetregs+0(SB),R7 + MOVW gpioregs+0(SB),R6 + MOVW memconfregs+0(SB),R5 + MOVW powerregs+0(SB),R3 + MOVW 0x1c(R5),R1 + ORR $0x30400000,R1 + MOVW R1,refr-4(SP) + MOVW $0x80000003,R2 + MOVW R2,0xc(R3) + MOVW $15,R2 + MOVW R2,0x4(R7) + MOVW $7,R2 + MOVW R2,0x10(R3) + MOVW $0,R2 + MOVW R2,0x18(R3) + MOVW $sa1100_power_resume+0(SB),R2 + MOVW R2,0x8(R3) + MOVW $0,R2 + MOVW R2,0x4(R6) + MOVW 0x1c(R5),R2 + ORR $0x400000,R2 + MOVW R2,0x1c(R5) MOVW $(90*206),R0 -d1: - SUB $1,R0 - BNE d1 - - MOVW $(POWERREGS+0x14),R0 - MOVW $0,R1 - MOVW R1,(R0) /* clear PPCR */ - +l13: SUB $1,R0 + BGT l13 + MOVW powerregs+0(SB),R3 + MOVW $0,R2 + MOVW R2,20(R3) MOVW $(90*206),R0 -d2: - SUB $1,R0 - BNE d2 - - -/* setup up register contents for jump to page containing SA1110 SDRAM controller bug fix suspend code - * - * r0 points to MSC0 register - * r1 points to MSC1 register - * r2 points to MSC2 register - * r3 is MSC0 value - * r4 is MSC1 value - * r5 is MSC2 value - * r6 points to MDREFR register - * r7 is first MDREFR value - * r8 is second MDREFR value - * r9 is pointer to MDCNFG register - * r10 is MDCNFG value - * r11 is third MDREFR value - * r12 is pointer to PMCR register - * r13 is PMCR value (1) - * - */ - - MOVW $(MEMCONFREGS+0x10),R0 - MOVW $(MEMCONFREGS+0x14),R1 - MOVW $(MEMCONFREGS+0x2c),R2 - - MOVW (R0),R3 - BIC $0x00030003,R3 /* MSC_RT fields */ - - MOVW (R1),R4 - BIC $0x00030003,R4 /* MSC_RT fields */ - - MOVW (R2),R5 - BIC $0x00030003,R5 /* MSC_RT fields */ - - MOVW $(MEMCONFREGS+0x1c),R6 - - MOVW (R6),R7 - BIC $0x0000FFF0,R7 /* DRI 0 .. 11 */ - ORR $(1<<31),R7,R8 /* prepare to set self refresh */ - - MOVW $(MEMCONFREGS+0x0),R9 - MOVW (R9),R10 - BIC $(0x00030003),R10 /* clear DE0 ⋯ DE3 */ - - BIC $(1<<31 | 1<<20),R8,R11 /* self-refresh and e1pin */ - - MOVW $(POWERREGS+0x0),R12 - MOVW $1,R13 /* sleep force bit */ - - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - /* Fall through */ - -/* .align 5 Needs to be on a cache line boundary? */ - TEXT sdram_controller_fix(SB),$0 - - /* Step 1 clear RT field of all MSCx registers */ - MOVW R3,(R0) - MOVW R4,(R1) - MOVW R5,(R2) - - /* Step 2 clear DRI field in MDREFR */ - MOVW R7,(R6) - - /* Step 3 set SLFRSH bit in MDREFR */ - MOVW R8,(R6) - - /* Step 4 clear DE bis in MDCNFG */ - MOVW R10,(R9) - - /* Step 5 clear DRAM refresh control register */ - MOVW R11,(R6) - - /* Wow, now the hardware suspend request pins can be used, that makes them functional for */ - /* about 7 ns out of the entire time that the CPU is running! */ - - /* Step 6 set force sleep bit in PMCR */ - - MOVW R13,(R12) +l14: SUB $1,R0 + BGT l14 + MOVW powerregs+0(SB),R5 + MOVW refr-4(SP),R4 + AND $(~0xfff0),R4 + ORR $0x80000000,R4,R6 + AND $(~0x80100000),R6,R11 + + MOVW memconfregs+0(SB),R3 + MOVW (R3),R12 + AND $(~0x30003),R12 + + MOVW 0x10(R3),R2 + AND $0xfffcfffc,R2 + MOVW R2,0x10(R3) + MOVW 0x14(R3),R2 + AND $0xfffcfffc,R2 + MOVW R2,0x14(R3) + MOVW 0x2c(R3),R2 + AND $0xfffcfffc,R2 + MOVW R2,0x2c(R3) + + MOVW $1,R2 + MOVW R4,0x1c(R3) +// MOVW R6,0x1c(R3) +// MOVW R12,(R3) +// MOVW R11,0x1c(R3) + MOVW R2,0(R5) slloop: B slloop /* loop waiting for sleep */ +TEXT coma(SB), $-4 + MOVW $1,R1 + MOVW $(MEMCONFREGS+0x1c),R2 + MOVW $(POWERREGS+0x0),R3 +// MOVW R0,(R2) + MOVW R1,(R3) +comaloop: + B comaloop + /* The first MCR instruction of this function needs to be on a cache-line * boundary; to make this happen, it will be copied (in trap.c). * diff --git a/bitsy/power.c b/bitsy/power.c index 232ee539591548895a09040a8c3b91cf58d05e1e..08ad4442444361bf55441e2b5a659ac6a779dfbe 100644 --- a/bitsy/power.c +++ b/bitsy/power.c @@ -178,9 +178,11 @@ sa1100_power_off(void) memconfregs->msc0 &= ~0x30003; memconfregs->msc1 &= ~0x30003; memconfregs->msc2 &= ~0x30003; + refr &= ~0xfff0; memconfregs->mdrefr = refr; /* Clear dri 0 ⋯ 11 */ refr |= 1<mdrefr = refr; /* Set selfrefresh */ + + memconfregs->mdrefr = refr; /* Set selfrefresh */ powerregs->pmcr = PCFR_suspend; for(;;); } @@ -259,7 +261,8 @@ deepsleep(void) { } cacheflush(); delay(100); - sa1100_power_off(); + power_down(); +// sa1100_power_off(); /* no return */ } diff --git a/boot/boot.c b/boot/boot.c index 674b039e513cb152ee73d088a4789f5f87a8acf9..0ee03331386bce85ac2295fab2ccb0fdd9806ad1 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -99,16 +99,15 @@ boot(int argc, char *argv[]) fatal("can't connect to file server"); if(getenv("srvold9p")) fd = old9p(fd); + if(!islocal && !ishybrid){ + if(cfs) + fd = (*cfs)(fd); + } print("version..."); buf[0] = '\0'; n = fversion(fd, 0, buf, sizeof buf); if(n < 0) fatal("can't init 9P"); - print("(%.*s)...", n, buf); - if(!islocal && !ishybrid){ - if(cfs) - fd = (*cfs)(fd); - } srvcreate("boot", fd); /* @@ -152,24 +151,6 @@ boot(int argc, char *argv[]) close(fd); setenv("rootdir", rp); - /* - * if a local file server exists and it's not - * running, start it and mount it onto /n/kfs - */ - if(0 && access("#s/kfs", 0) < 0){ /* BUG: DISABLED UNTIL KFS SUPPORTS 9P2000 */ - for(mp = method; mp->name; mp++){ - if(strcmp(mp->name, "local") != 0) - continue; - (*mp->config)(mp); - fd = (*mp->connect)(); - if(fd < 0) - break; - mount(fd, -1, "/n/kfs", MAFTER|MCREATE, "") ; - close(fd); - break; - } - } - settime(islocal, afd); swapproc(); diff --git a/boot/boot.h b/boot/boot.h index 7485c725f37ddd0df0a5d4c42af95fe1f2ca0767..b33956d259049f5e4b19ddcfc106e755e1ee30d3 100644 --- a/boot/boot.h +++ b/boot/boot.h @@ -6,6 +6,11 @@ struct Method int (*connect)(void); char *arg; }; +enum +{ + Statsz= 256, + Nbarg= 16, +}; extern void authentication(int); extern char* bootdisk; @@ -20,11 +25,7 @@ extern void (*pword)(int, Method*); extern char sys[]; extern uchar hostkey[]; extern char username[]; -extern uchar statbuf[STATMAX]; -enum -{ - Nbarg= 16, -}; +extern uchar statbuf[Statsz]; extern int bargc; extern char *bargv[Nbarg]; diff --git a/boot/bootauth.c b/boot/bootauth.c index 1e553b4654e415a2678bbfa6941c99cdbaa3e0bb..db5ba825f3091faa3bbf93ff9bd61224ac923821 100644 --- a/boot/bootauth.c +++ b/boot/bootauth.c @@ -11,7 +11,6 @@ authentication(int cpuflag) { char *argv[16], **av; int ac; - int factotumpid, pid; /* start agent */ ac = 0; @@ -43,32 +42,4 @@ authentication(int cpuflag) if(cpuflag) return; - /* ask for password */ -#ifdef quux - /* start agent */ - ac = 0; - av = argv; - av[ac++] = "factotum"; - av[ac++] = "-gd"; - av[ac++] = "p9sk1"; - av[ac++] = "cs.bell-labs.com"; - av[ac] = 0; - switch((factotumpid = fork())){ - case -1: - fatal("starting factotum: %r"); - case 0: - exec("/factotum", av); - fatal("execing /factotum"); - default: - break; - } - - for(;;){ - pid = waitpid(); - if(pid == factotumpid) - break; - if(pid == -1) - fatal("waiting for factotum"); - } -#endif quux } diff --git a/boot/bootcache.c b/boot/bootcache.c index fdcf06c80d993b820e1682b9d92d0dbe2e266194..ebe3a6c59d341425fadd8f333b0514fadfa1be6e 100644 --- a/boot/bootcache.c +++ b/boot/bootcache.c @@ -2,7 +2,7 @@ #include #include <../boot/boot.h> -uchar statbuf[STATMAX]; +uchar statbuf[Statsz]; int cache(int fd) @@ -65,7 +65,7 @@ cache(int fd) if(fflag) execl("/cfs", "bootcfs", "-rs", "-f", partition, 0); else - execl("/cfs", "bootcfs", "-ds", "-f", partition, 0); + execl("/cfs", "bootcfs", "-s", "-f", partition, 0); break; default: close(p[0]); diff --git a/port/dev.c b/port/dev.c index 628f522c93a5b3c5df71fe139b5d567a5057806b..730df47827778caa0b699f428dafce48fee43fc1 100644 --- a/port/dev.c +++ b/port/dev.c @@ -34,8 +34,6 @@ void devdir(Chan *c, Qid qid, char *n, vlong length, char *user, long perm, Dir *db) { db->name = n; - if(c->flag&CMSG) - qid.type |= QTMOUNT; db->qid = qid; db->type = devtab[c->type]->dc; db->dev = c->dev; diff --git a/port/devcons.c b/port/devcons.c index 36715b99c45b1cb7de9d5481a8492eced60b282a..949ce4808050f012b250c3b5283db3438cc22ab2 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -241,7 +241,7 @@ panic(char *fmt, ...) spllo(); prflush(); putstrn(buf, n+1); -// dumpstack(); + dumpstack(); exit(1); } diff --git a/port/devdup.c b/port/devdup.c index 7b0b601023051e03a0864dbaeb7a14cd8575671f..254a73c26e5f4786f95432f82a1353d53f2ecc6d 100644 --- a/port/devdup.c +++ b/port/devdup.c @@ -23,7 +23,7 @@ dupgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp) if(s == 0) return 0; s--; - if(s > 2*fgrp->maxfd) + if(s/2 > fgrp->maxfd) return -1; if((f=fgrp->fd[s/2]) == nil) return 0; diff --git a/port/devmnt.c b/port/devmnt.c index 7dc4f5bf596779a857c2d6f3cf9f1823403a8abe..cdfa2e7135b5f9eaced6174fddfba7f3ded149b1 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -110,7 +110,9 @@ mntversion(Chan *c, char *version, int msize, int returnlen) /* defaults */ if(msize == 0) - msize = MAXRPC-IOHDRSZ; + msize = MAXRPC; + if(msize > c->iounit && c->iounit != 0) + msize = c->iounit; v = version; if(v == nil || v[0] == '\0') v = VERSION9P; @@ -190,9 +192,6 @@ mntversion(Chan *c, char *version, int msize, int returnlen) error("nonsense value of msize in fversion"); if(strncmp(f.version, v, strlen(f.version)) != 0) error("bad 9P version returned from server"); - c->iounit = f.msize; - if(c->iounit == 0) - c->iounit = MAXRPC; /* now build Mnt associated with this connection */ lock(&mntalloc); @@ -208,9 +207,11 @@ mntversion(Chan *c, char *version, int msize, int returnlen) } m->list = mntalloc.list; mntalloc.list = m; + m->version = nil; kstrdup(&m->version, f.version); m->id = mntalloc.id++; m->q = qopen(10*MAXRPC, 0, nil, nil); + m->msize = f.msize; unlock(&mntalloc); poperror(); /* msg */ @@ -262,7 +263,7 @@ mntauth(Chan *c, char *spec) nexterror(); } - r = mntralloc(0, m->c->iounit); + r = mntralloc(0, m->msize); if(waserror()) { mntfree(r); @@ -324,7 +325,7 @@ mntattach(char *muxattach) nexterror(); } - r = mntralloc(0, m->c->iounit); + r = mntralloc(0, m->msize); if(waserror()) { mntfree(r); @@ -394,7 +395,7 @@ mntwalk(Chan *c, Chan *nc, char **name, int nname) alloc = 0; m = mntchk(c); - r = mntralloc(c, m->c->iounit); + r = mntralloc(c, m->msize); if(nc == nil){ nc = devclone(c); /* @@ -462,7 +463,7 @@ mntstat(Chan *c, uchar *dp, int n) if(n < BIT16SZ) error(Eshortstat); m = mntchk(c); - r = mntralloc(c, m->c->iounit); + r = mntralloc(c, m->msize); if(waserror()) { mntfree(r); nexterror(); @@ -496,7 +497,7 @@ mntopencreate(int type, Chan *c, char *name, int omode, ulong perm) Mntrpc *r; m = mntchk(c); - r = mntralloc(c, m->c->iounit); + r = mntralloc(c, m->msize); if(waserror()) { mntfree(r); nexterror(); @@ -514,6 +515,8 @@ mntopencreate(int type, Chan *c, char *name, int omode, ulong perm) c->offset = 0; c->mode = openmode(omode); c->iounit = r->reply.iounit; + if(c->iounit > m->msize-IOHDRSZ) + c->iounit = m->msize-IOHDRSZ; c->flag |= COPEN; poperror(); mntfree(r); @@ -543,7 +546,7 @@ mntclunk(Chan *c, int t) Mntrpc *r; m = mntchk(c); - r = mntralloc(c, m->c->iounit); + r = mntralloc(c, m->msize); if(waserror()){ mntfree(r); nexterror(); @@ -566,6 +569,8 @@ muxclose(Mnt *m) mntfree(q); } m->id = 0; + free(m->version); + m->version = nil; mntpntfree(m); } @@ -611,7 +616,7 @@ mntwstat(Chan *c, uchar *dp, int n) Mntrpc *r; m = mntchk(c); - r = mntralloc(c, m->c->iounit); + r = mntralloc(c, m->msize); if(waserror()) { mntfree(r); nexterror(); @@ -692,7 +697,7 @@ mntrdwr(int type, Chan *c, void *buf, long n, vlong off) if(c->qid.type & QTDIR) cache = 0; for(;;) { - r = mntralloc(c, m->c->iounit); + r = mntralloc(c, m->msize); if(waserror()) { mntfree(r); nexterror(); @@ -702,10 +707,8 @@ mntrdwr(int type, Chan *c, void *buf, long n, vlong off) r->request.offset = off; r->request.data = uba; nr = n; - if(nr > m->c->iounit-IOHDRSZ) - nr = m->c->iounit-IOHDRSZ; - if(c->iounit != 0 && nr > c->iounit) - nr = c->iounit; + if(nr > m->msize-IOHDRSZ) + nr = m->msize-IOHDRSZ; r->request.count = nr; mountrpc(m, r); nreq = r->request.count; @@ -776,7 +779,7 @@ mountio(Mnt *m, Mntrpc *r) mntflushfree(m, r); nexterror(); } - r = mntflushalloc(r, m->c->iounit); + r = mntflushalloc(r, m->msize); } lock(m); @@ -786,9 +789,9 @@ mountio(Mnt *m, Mntrpc *r) unlock(m); /* Transmit a file system rpc */ - if(m->c->iounit == 0) - panic("iounit"); - n = convS2M(&r->request, r->rpc, m->c->iounit); + if(m->msize == 0) + panic("msize"); + n = convS2M(&r->request, r->rpc, m->msize); if(n < 0) panic("bad message type in mountio"); if(devtab[m->c->type]->write(m->c, r->rpc, n, 0) != n) @@ -994,7 +997,7 @@ mntflushfree(Mnt *m, Mntrpc *r) } Mntrpc* -mntralloc(Chan *c, ulong iounit) +mntralloc(Chan *c, ulong msize) { Mntrpc *new; @@ -1010,28 +1013,28 @@ mntralloc(Chan *c, ulong iounit) * The header is split from the data buffer as * mountmux may swap the buffer with another header. */ - new->rpc = mallocz(iounit, 0); + new->rpc = mallocz(msize, 0); if(new->rpc == nil){ free(new); unlock(&mntalloc); exhausted("mount rpc buffer"); } - new->rpclen = iounit; + new->rpclen = msize; new->request.tag = mntalloc.rpctag++; } else { mntalloc.rpcfree = new->list; mntalloc.nrpcfree--; - if(new->rpclen < iounit){ + if(new->rpclen < msize){ free(new->rpc); - new->rpc = mallocz(iounit, 0); + new->rpc = mallocz(msize, 0); if(new->rpc == nil){ free(new); mntalloc.nrpcused--; unlock(&mntalloc); exhausted("mount rpc buffer"); } - new->rpclen = iounit; + new->rpclen = msize; } } mntalloc.nrpcused++; diff --git a/port/lib.h b/port/lib.h index c562769ff5b9394ddcaf1313a4529fd1eb529e2e..b88814c5bf6b4b7a180225967cfb5047c7315e02 100644 --- a/port/lib.h +++ b/port/lib.h @@ -122,7 +122,6 @@ typedef struct Waitmsg Waitmsg; #define QTDIR 0x80 /* type bit for directories */ #define QTAPPEND 0x40 /* type bit for append only files */ #define QTEXCL 0x20 /* type bit for exclusive use files */ -#define QTMOUNT 0x10 /* type bit for mounted channel */ #define QTAUTH 0x08 /* type bit for authentication file */ #define QTFILE 0x00 /* plain file */ diff --git a/port/portdat.h b/port/portdat.h index dcde3ce10a163897ffd084951efe2428a74ea9cf..8f1ad3310e40390e6aaef7c52354d0916e07baab 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -261,6 +261,7 @@ struct Mnt ulong id; /* Multiplexer id for channel check */ Mnt *list; /* Free list */ int flags; /* cache */ + int msize; /* data + IOHDRSZ */ char *version; /* 9P version */ Queue *q; /* input queue */ }; diff --git a/port/sysfile.c b/port/sysfile.c index aae4680a140f427925892636436788cdaf26341b..403d834093d5e9420589fb715906047d0e16ed8e 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -271,7 +271,6 @@ sysopen(ulong *arg) if(fd < 0) error(Enofd); poperror(); -if(strstr(up->text, "syscall")!=0) pprint("open %s ref count %d\n", c2name(c), c->ref); // BUG return fd; }