From bbc3d65f8205ef050ae616eb5e0f89cf9337f98f Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 24 Dec 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-12-24 --- gnot/lib.h | 7 +++++ gnot/u.h | 1 + port/devcons.c | 73 ++++++++++++++++++++++++++++++----------------- power/devhotrod.c | 4 +-- ss/io.h | 3 +- 5 files changed, 59 insertions(+), 29 deletions(-) diff --git a/gnot/lib.h b/gnot/lib.h index 35d88be2f290788b264bf97254511e04096abf41..84db7ca9550a177c9a01cc88818fa2da909b9d4e 100644 --- a/gnot/lib.h +++ b/gnot/lib.h @@ -24,6 +24,13 @@ extern int strncmp(char*, char*, long); extern long strlen(char*); extern int atoi(char*); +/* + * rune routines + */ +extern int runetochar(char*, Rune*); +extern int chartorune(Rune*, char*); +extern int countrune(char*); + /* * print routines */ diff --git a/gnot/u.h b/gnot/u.h index 81dfccf482a2af1e3a96426b21223e1c14af86d6..c6367e3fd7f95de2125bbd3732eed57e8a5d14ae 100644 --- a/gnot/u.h +++ b/gnot/u.h @@ -3,6 +3,7 @@ typedef unsigned char uchar; typedef unsigned long ulong; typedef long vlong; typedef union Length Length; +typedef ushort Rune; union Length { diff --git a/port/devcons.c b/port/devcons.c index b18595703f7be27297e69a866701a5fe9d8d9b50..ea1a5f11ee6616ab0cd2cc5cdd8039ff586ad0bd 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -18,7 +18,8 @@ IOQ printq; IOQ mouseq; KIOQ kbdq; -Ref raw; /* whether kbd i/o is raw (rcons is open) */ +static Ref ctl; /* number of opens to the control file */ +static int raw; /* true if raw has been requested on a ctl file */ char eve[NAMELEN] = "bootes"; char evekey[DESKEYLEN]; @@ -119,7 +120,7 @@ isbrkc(KIOQ *q) uchar *p; for(p=q->out; p!=q->in; ){ - if(raw.ref) + if(raw) return 1; if(*p==0x04 || *p=='\n') return 1; @@ -245,7 +246,7 @@ echo(Rune r, char *buf, int n) return; } ctrlt = 0; - if(raw.ref) + if(raw) return; if(r == 0x15) putstrn("^U\n", 3); @@ -287,7 +288,7 @@ kbdputc(IOQ *q, int ch) if(kbdq.in == kbdq.buf+sizeof(kbdq.buf)) kbdq.in = kbdq.buf; } - if(raw.ref || r=='\n' || r==0x04) + if(raw || r=='\n' || r==0x04) wakeup(&kbdq.r); return 0; } @@ -322,6 +323,7 @@ consactive(void) enum{ Qdir, Qcons, + Qconsctl, Qcputime, Qlights, Qnoise, @@ -329,7 +331,6 @@ enum{ Qpgrpid, Qpid, Qppid, - Qrcons, Qtime, Quser, Qklog, @@ -344,6 +345,7 @@ enum{ Dirtab consdir[]={ "cons", {Qcons}, 0, 0660, + "consctl", {Qconsctl}, 0, 0220, "cputime", {Qcputime}, 6*NUMSIZE, 0444, "time", {Qtime}, NUMSIZE, 0664, "clock", {Qclock}, 2*NUMSIZE, 0444, @@ -354,7 +356,6 @@ Dirtab consdir[]={ "pgrpid", {Qpgrpid}, NUMSIZE, 0444, "pid", {Qpid}, NUMSIZE, 0444, "ppid", {Qppid}, NUMSIZE, 0444, - "rcons", {Qrcons}, 0, 0660, "user", {Quser}, 0, 0666, "chal", {Qchal}, 8, 0666, "crypt", {Qcrypt}, 0, 0666, @@ -441,21 +442,11 @@ consstat(Chan *c, char *dp) Chan* consopen(Chan *c, int omode) { - int ch; - switch(c->qid.path){ - case Qrcons: + case Qconsctl: if(strcmp(u->p->user, eve) != 0) error(Eperm); - if(incref(&raw) == 1){ - lock(&lineq); - while((ch=getc(&kbdq)) != -1){ - *lineq.in++ = ch; - if(lineq.in == lineq.buf+sizeof(lineq.buf)) - lineq.in = lineq.buf; - } - unlock(&lineq); - } + incref(&ctl); break; case Qswap: kickpager(); /* start a pager if not already started */ @@ -475,8 +466,13 @@ conscreate(Chan *c, char *name, int omode, ulong perm) void consclose(Chan *c) { - if(c->qid.path==Qrcons && (c->flag&COPEN)) - decref(&raw); + /* last close of control file turns off raw */ + if(c->qid.path==Qconsctl && (c->flag&COPEN)){ + lock(&ctl); + if(--ctl.ref == 0) + raw = 0; + unlock(&ctl); + } if(c->qid.path == Qcrypt && c->aux) freeb(c->aux); c->aux = 0; @@ -501,7 +497,6 @@ consread(Chan *c, void *buf, long n, ulong offset) case Qdir: return devdirread(c, buf, n, consdir, NCONS, devgen); - case Qrcons: case Qcons: qlock(&kbdq); if(waserror()){ @@ -513,7 +508,7 @@ consread(Chan *c, void *buf, long n, ulong offset) do{ lock(&lineq); ch = getc(&kbdq); - if(raw.ref){ + if(raw){ unlock(&lineq); goto Default; } @@ -537,12 +532,12 @@ consread(Chan *c, void *buf, long n, ulong offset) lineq.in++; } unlock(&lineq); - }while(raw.ref==0 && ch!='\n' && ch!=0x04); + }while(raw==0 && ch!='\n' && ch!=0x04); } i = 0; while(n > 0){ ch = getc(&lineq); - if(ch==-1 || (raw.ref==0 && ch==0x04)) + if(ch==-1 || (raw==0 && ch==0x04)) break; i++; *cbuf++ = ch; @@ -715,11 +710,10 @@ conswrite(Chan *c, void *va, long n, ulong offset) char *a = va; Block *cb; Mach *mp; - int id, fd; + int id, fd, ch; Chan *swc; switch(c->qid.path){ - case Qrcons: case Qcons: /* * Can't page fault in putstrn, so copy the data locally. @@ -736,6 +730,33 @@ conswrite(Chan *c, void *va, long n, ulong offset) } break; + case Qconsctl: + if(n >= sizeof(buf)) + n = sizeof(buf)-1; + strncpy(buf, a, n); + buf[n] = 0; + for(a = buf; a;){ + if(strncmp(a, "rawon", 5) == 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); + lock(&ctl); + raw = 1; + unlock(&ctl); + } else if(strncmp(a, "rawoff", 6) == 0){ + lock(&ctl); + raw = 0; + unlock(&ctl); + } + if(a = strchr(a, ' ')) + a++; + } + break; + case Qtime: if(n<=0 || boottime!=0) /* write once file */ return 0; diff --git a/power/devhotrod.c b/power/devhotrod.c index 689bbd31cf79ae6869a1721753e2ea8260543e1b..93c735f22f2d2f6890ccb09c0dd88ec911ab3446 100644 --- a/power/devhotrod.c +++ b/power/devhotrod.c @@ -26,7 +26,7 @@ ulong testbuf[NTESTBUF]; /* * If 1, ENABCKSUM causes data transfers to have checksums */ -#define ENABCKSUM 0 +#define ENABCKSUM 1 typedef struct Hotrod Hotrod; @@ -335,7 +335,7 @@ hotrodread(Chan *c, void *buf, long n, ulong offset) error(Egreg); } if(mp->param[2] != hotsum(buf, m, mp->param[2])){ - hp->addr->error++; + hp->addr->lcsr7 = 0xBEEF; print("hotrod cksum err is %lux sb %lux\n", hotsum(buf, m, 1), mp->param[2]); /* diff --git a/ss/io.h b/ss/io.h index 5f7abd2d27f9e74e15f54645e54896311e9cfe46..9156578f206c89ccb4c25ac405a0c8e8dc240858 100644 --- a/ss/io.h +++ b/ss/io.h @@ -2,7 +2,8 @@ #define EPROM 0xF6000000 #define CLOCK 0xF3000000 #define CLOCKFREQ 1000000 /* one microsecond increments */ -#define KMDUART 0xF0000000 /* keyboard A, mouse B */ +#define KMDUART0 0xF0000000 /* keyboard A, mouse B */ +#define KMDUART1 0xF1000000 /* serial ports */ #define ETHER 0xF8C00000 /* RDP, RAP */ #define EEPROM 0xF2000000 #define INTRREG 0xF5000000 /* interrupt register, IO space */