From 8b731e319e30a54190452e866c4152dc5a21f859 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 15 May 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-05-15 --- gnot/devcons.c | 43 +++++++++++++++++++++++++++++++++++++------ gnot/trap.c | 4 ++-- port/chan.c | 4 +--- port/devbit.c | 7 ++----- power/trap.c | 2 +- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/gnot/devcons.c b/gnot/devcons.c index b09a8f747561721636b64fd2806f6937f82fde7c..65f05b8e09b8ca9d05e3c3c857b3dbbf518a7a46 100644 --- a/gnot/devcons.c +++ b/gnot/devcons.c @@ -30,7 +30,7 @@ struct IOQ{ Rendez r; }; -IOQ lineq; /* lock to getc; interrupt putc's */ +IOQ lineq; struct{ IOQ; /* qlock to getc; interrupt putc's */ @@ -39,6 +39,8 @@ struct{ int count; }kbdq; +Ref raw; /* whether kbd i/o is raw (rcons is open) */ + void printinit(void) { @@ -88,6 +90,8 @@ isbrkc(IOQ *q) uchar *p; for(p=q->out; p!=q->in; ){ + if(raw.ref) + return 1; if(*p==0x04 || *p=='\n') return 1; p++; @@ -180,6 +184,8 @@ echo(int c) */ if(c == 0x14) DEBUG(); + if(raw.ref) + return; if(c == 0x15) putstrn("^U\n", 3); else{ @@ -207,7 +213,7 @@ kbdchar(int c) *kbdq.in++ = c; if(kbdq.in == kbdq.buf+sizeof(kbdq.buf)) kbdq.in = kbdq.buf; - if(c=='\n' || c==0x04) + if(raw.ref || c=='\n' || c==0x04) wakeup(&kbdq.r); } @@ -244,6 +250,7 @@ enum{ Qpgrpid, Qpid, Qppid, + Qrcons, Qtime, Quser, }; @@ -255,6 +262,7 @@ Dirtab consdir[]={ "pgrpid", Qpgrpid, 12, 0600, "pid", Qpid, 12, 0600, "ppid", Qppid, 12, 0600, + "rcons", Qrcons, 0, 0600, "time", Qtime, 12, 0600, "user", Quser, 0, 0600, }; @@ -336,6 +344,8 @@ consstat(Chan *c, char *dp) Chan* consopen(Chan *c, int omode) { + int ch; + if(c->qid==Quser && omode==(OWRITE|OTRUNC)){ /* truncate? */ if(strcmp(u->p->pgrp->user, "bootes") == 0) /* BUG */ @@ -343,6 +353,16 @@ consopen(Chan *c, int omode) else error(0, Eperm); } + if(c->qid == Qrcons) + if(incref(&raw) == 0){ + lock(&lineq); + while((ch=getc(&kbdq)) != -1){ + *lineq.in++ = ch; + if(lineq.in == lineq.buf+sizeof(lineq.buf)) + lineq.in = lineq.buf; + } + unlock(&lineq); + } return devopen(c, omode, consdir, NCONS, devgen); } @@ -355,6 +375,8 @@ conscreate(Chan *c, char *name, int omode, ulong perm) void consclose(Chan *c) { + if(c->qid == Qrcons) + decref(&raw); } long @@ -374,12 +396,18 @@ consread(Chan *c, void *buf, long n) case Qdir: return devdirread(c, buf, n, consdir, NCONS, devgen); + case Qrcons: case Qcons: qlock(&kbdq); while(!cangetc(&lineq)){ sleep(&kbdq.r, (int(*)(void*))isbrkc, &kbdq); do{ + lock(&lineq); ch = getc(&kbdq); + if(raw.ref){ + unlock(&lineq); + goto Default; + } switch(ch){ case '\b': if(lineq.in != lineq.out){ @@ -391,17 +419,19 @@ consread(Chan *c, void *buf, long n) case 0x15: lineq.in = lineq.out; break; + Default: default: *lineq.in++ = ch; if(lineq.in == lineq.buf+sizeof(lineq.buf)) - lineq.in = lineq.buf; + lineq.in = lineq.buf; } - }while(ch!='\n' && ch!=0x04); + unlock(&lineq); + }while(raw.ref==0 && ch!='\n' && ch!=0x04); } i = 0; - while(n>0){ + while(n > 0){ ch = getc(&lineq); - if(ch == 0x04 || ch == -1) + if(ch==-1 || (raw.ref==0 && ch==0x04)) break; i++; *cbuf++ = ch; @@ -461,6 +491,7 @@ conswrite(Chan *c, void *va, long n) switch(c->qid){ case Qcons: + case Qrcons: /* * Damn. Can't page fault in putstrn, so copy the data locally. */ diff --git a/gnot/trap.c b/gnot/trap.c index 9766f66c7400e288ad20196f4ee2d53b765251ce..47a1340c04ff6f0b24e881dc42107df6744bd9c2 100644 --- a/gnot/trap.c +++ b/gnot/trap.c @@ -278,8 +278,8 @@ syscall(Ureg *aur) goto Bad; } if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-4*BY2WD)) - validaddr(ur->sp, 4*BY2WD, 0); - ret = (*systab[r0])((ulong*)(sp+2*BY2WD)); + validaddr(sp, 4*BY2WD, 0); + ret = (*systab[r0])((ulong*)(sp+BY2WD)); } u->nerrlab = 0; u->p->insyscall = 0; diff --git a/port/chan.c b/port/chan.c index 0822cf250e4ec42aede3535030603af913905365..374bd4e1cb8c2b82f1ac78eca627093856bc8737 100644 --- a/port/chan.c +++ b/port/chan.c @@ -490,10 +490,8 @@ namec(char *name, int amode, int omode, ulong perm) switch(amode){ case Aaccess: - if((nc=walk(c, elem, mntok)) == 0){ - print("%d pc %lux\n", u->nerrlab, u->errlab[u->nerrlab-1].pc); + if((nc=walk(c, elem, mntok)) == 0) error(0, Enonexist); - } c = nc; break; diff --git a/port/devbit.c b/port/devbit.c index 69d180167cbb303534ef4c4eab2521e521cac369..7af2e66bd3785cf0963c613d2b8bd79a23880264 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -26,7 +26,6 @@ extern Font defont0; /* BUG */ struct{ Ref; - int bltuse; Bitmap *map; /* arena */ Bitmap *free; /* free list */ ulong *words; /* storage */ @@ -148,7 +147,6 @@ void bitinit(void) { lock(&bit); - bit.bltuse = 0; unlock(&bit); cursoron(1); } @@ -185,9 +183,9 @@ bitopen(Chan *c, int omode) if(c->qid == CHDIR){ if(omode != OREAD) error(0, Eperm); - }else{ + }else if(c->qid == Qbitblt){ lock(&bit); - if(bit.bltuse){ + if(bit.ref){ unlock(&bit); error(0, Einuse); } @@ -232,7 +230,6 @@ bitclose(Chan *c) for(i=1,bp=&bit.map[1]; ildepth >= 0) bitfree(bp); - bit.bltuse = 0; } unlock(&bit); } diff --git a/power/trap.c b/power/trap.c index 3a93435c57798f59ce4f0d77db8ef9c0df447185..ec39d29921e7534febfc7cf60821ccaee31f91d4 100644 --- a/power/trap.c +++ b/power/trap.c @@ -451,7 +451,7 @@ syscall(Ureg *aur) goto Bad; } if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-4*BY2WD)) - validaddr(ur->sp, 4*BY2WD, 0); + validaddr(sp, 4*BY2WD, 0); ret = (*systab[r1])((ulong*)(sp+2*BY2WD)); } ur->pc += 4;