From 170d92cabb9c33af04d0200e02822e8ecff98ee6 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 12 Sep 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-09-12 --- gnot/screen.c | 21 ++++++++-------- port/devbit.c | 65 +++++++++++++++++++++++++------------------------ port/devcons.c | 55 +++++++++++++++++++++++++++++------------ port/devlance.c | 3 +++ power/dat.h | 12 --------- power/main.c | 23 ++++++++++++----- 6 files changed, 104 insertions(+), 75 deletions(-) diff --git a/gnot/screen.c b/gnot/screen.c index c20646fb98f41a09eba16b7b5e31f84d2de216ad..7dc6b133fa42c3e9239a5cf7ca0ff4a0e673acfc 100644 --- a/gnot/screen.c +++ b/gnot/screen.c @@ -7,6 +7,7 @@ #include "ureg.h" #include "errno.h" +#include #include #define MINX 8 @@ -24,7 +25,7 @@ void duartinit(void); int duartacr; int duartimr; -GBitmap screen = +GBitmap gscreen = { (ulong*)((4*1024*1024-256*1024)|KZERO), /* BUG */ 0, @@ -42,11 +43,11 @@ screeninit(void) * Read HEX switch to set ldepth */ if(*(uchar*)MOUSE & (1<<4)){ - screen.ldepth = 1; + gscreen.ldepth = 1; defont = &defont1; }else defont = &defont0; - gbitblt(&screen, Pt(0, 0), &screen, screen.r, 0); + gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0); out.pos.x = MINX; out.pos.y = 0; out.bwid = defont0.info[' '].width; @@ -61,13 +62,13 @@ screenputc(int c) if(c == '\n'){ out.pos.x = MINX; out.pos.y += defont0.height; - if(out.pos.y > screen.r.max.y-defont0.height) - out.pos.y = screen.r.min.y; - gbitblt(&screen, Pt(0, out.pos.y), &screen, - Rect(0, out.pos.y, screen.r.max.x, out.pos.y+2*defont0.height), 0); + if(out.pos.y > gscreen.r.max.y-defont0.height) + out.pos.y = gscreen.r.min.y; + gbitblt(&gscreen, Pt(0, out.pos.y), &gscreen, + Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height), 0); }else if(c == '\t'){ out.pos.x += (8-((out.pos.x-MINX)/out.bwid&7))*out.bwid; - if(out.pos.x >= screen.r.max.x) + if(out.pos.x >= gscreen.r.max.x) screenputc('\n'); }else if(c == '\b'){ if(out.pos.x >= out.bwid+MINX){ @@ -76,11 +77,11 @@ screenputc(int c) out.pos.x -= out.bwid; } }else{ - if(out.pos.x >= screen.r.max.x-out.bwid) + if(out.pos.x >= gscreen.r.max.x-out.bwid) screenputc('\n'); buf[0] = c&0x7F; buf[1] = 0; - out.pos = gstring(&screen, out.pos, defont, buf, S); + out.pos = gstring(&gscreen, out.pos, defont, buf, S); } } diff --git a/port/devbit.c b/port/devbit.c index e75cba3e1cb11fcf8624944c5fc252377c4d0576..aff714bcb7302c3155288f3f8cefa8284c02a992 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -7,6 +7,7 @@ #include "devtab.h" +#include #include extern GFont *defont; @@ -44,7 +45,7 @@ struct #define FREE 0x80000000 void bitcompact(void); void bitfree(GBitmap*); -extern GBitmap screen; +extern GBitmap gscreen; struct{ /* @@ -145,7 +146,7 @@ bitreset(void) } bp--; bp->base = 0; - bit.map[0] = screen; /* bitmap 0 is screen */ + bit.map[0] = gscreen; /* bitmap 0 is screen */ bit.free = bit.map+1; bit.lastid = -1; bit.lastfid = -1; @@ -164,9 +165,9 @@ bitinit(void) { lock(&bit); unlock(&bit); - if(screen.ldepth > 1) + if(gscreen.ldepth > 1) panic("bitinit ldepth>1"); - cursorback.ldepth = screen.ldepth; + cursorback.ldepth = gscreen.ldepth; cursoron(1); } @@ -332,11 +333,11 @@ bitread(Chan *c, void *va, long n) if(n < 18) error(0, Ebadblt); p[0] = 'I'; - p[1] = screen.ldepth; - PLONG(p+2, screen.r.min.x); - PLONG(p+6, screen.r.min.y); - PLONG(p+10, screen.r.max.x); - PLONG(p+14, screen.r.max.y); + p[1] = gscreen.ldepth; + PLONG(p+2, gscreen.r.min.x); + PLONG(p+6, gscreen.r.min.y); + PLONG(p+10, gscreen.r.max.x); + PLONG(p+14, gscreen.r.max.y); if(n >= 18+3*12+6*(defont->n+1)){ p += 18; sprint((char*)p, "%11d %11d %11d ", defont->n, @@ -414,7 +415,7 @@ bitread(Chan *c, void *va, long n) n = 0; p = va; for(y=miny; yr.min.x, y)); + q = (uchar*)gaddr(src, Pt(src->r.min.x, y)); q += (src->r.min.x&((sizeof(ulong))*ws-1))/ws; for(x=0; xoffset-5*12; miny = t/l; maxy = (t+n)/l; - if(miny >= screen.r.max.y) + if(miny >= gscreen.r.max.y) return 0; - if(maxy >= screen.r.max.y) - maxy = screen.r.max.y; + if(maxy >= gscreen.r.max.y) + maxy = gscreen.r.max.y; n = 0; p = va; for(y=miny; yr.min.x, y)); + q = (uchar*)gaddr(dst, Pt(dst->r.min.x, y)); q += (dst->r.min.x&((sizeof(ulong))*ws-1))/ws; for(x=0; x= screen.r.max.x) - x = screen.r.max.x; + if(x < gscreen.r.min.x) + x = gscreen.r.min.x; + if(x >= gscreen.r.max.x) + x = gscreen.r.max.x; y = mouse.xy.y + mouse.dy; - if(y < screen.r.min.y) - y = screen.r.min.y; - if(y >= screen.r.max.y) - y = screen.r.max.y; + if(y < gscreen.r.min.y) + y = gscreen.r.min.y; + if(y >= gscreen.r.max.y) + y = gscreen.r.max.y; cursoroff(0); mouse.xy = Pt(x, y); cursoron(0); diff --git a/port/devcons.c b/port/devcons.c index d37f190e65718a58ad274dc1aab341c832a4a6c3..2e0f6391a5df0239eca7f9f45ecd8724693e768c 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -303,7 +303,7 @@ enum{ Dirtab consdir[]={ "cons", Qcons, 0, 0600, "cputime", Qcputime, 72, 0600, - "log", Qlog, sizeof(SYSLOG->buf), 0600, + "log", Qlog, BY2PG-8, 0600, "null", Qnull, 0, 0600, "pgrpid", Qpgrpid, 12, 0600, "pid", Qpid, 12, 0600, @@ -596,8 +596,19 @@ consuserstr(Error *e, char *buf) } /* - * crash info + * kernel based system log, passed between crashes */ +#define SYSLOGMAGIC 0x23456789 +#define SYSLOG ((Syslog *)(UNCACHED | KZERO | 0x1B00)) +typedef struct Syslog Syslog; +struct Syslog +{ + ulong magic; + char *start; + char *next; + char buf[BY2PG - 3*BY2WD]; +}; + void sysloginit(void) { @@ -606,7 +617,8 @@ sysloginit(void) s = SYSLOG; if(s->magic!=SYSLOGMAGIC || s->next>=&s->buf[sizeof(s->buf)] - || s->nextbuf){ + || s->start>=&s->buf[sizeof(s->buf)] || s->nextbuf){ + s->start = s->buf; s->next = s->buf; s->magic = SYSLOGMAGIC; } @@ -615,26 +627,35 @@ sysloginit(void) void syslog(char *p, int n) { - int i; + int restart; Syslog *s; char *end; s = SYSLOG; end = &s->buf[sizeof(s->buf)]; + restart = 0; while(n-- > 0){ *s->next++ = *p++; if(s->next >= end) s->next = s->buf; + if(s->next == s->start) + restart = 1; + } + if(restart){ + s->start = s->next + 1; + if(s->start >= end) + s->start = s->buf; } + wbflush(); } long readlog(ulong off, char *buf, ulong n) { Syslog *s; - int i; char *p; char *end; + char *a = buf; s = SYSLOG; @@ -642,20 +663,24 @@ readlog(ulong off, char *buf, ulong n) if(off >= sizeof(s->buf)) return 0; - /* trim length */ - if(off + n >= sizeof(s->buf)) - n = sizeof(s->buf) - off; - /* point to start of area to be read */ end = &s->buf[sizeof(s->buf)]; - p = s->next + off; - if(p > end) - p -= sizeof(s->buf); + p = s->start; + + /* skip offset */ + while(off-- > 0){ + if(p == s->next) + return 0; + p++; + } - for(i = 0; i < n; i++){ - *buf++ = *p++; + /* copy out */ + while(n-- > 0){ + if(p == s->next) + break; + *a++ = *p++; if(p >= end) p = s->buf; } - return n; + return a-buf; } diff --git a/port/devlance.c b/port/devlance.c index c899ede4386e2839d2eebcd55e39112a2bfdd44a..767f8c2e78ec8edac35ae071e2aac42a1aca3059 100644 --- a/port/devlance.c +++ b/port/devlance.c @@ -467,6 +467,9 @@ lancereset(void) l.rpa[i] = (uchar *)&l.lm->rp[i]; for(i = 0; i < Ntrb; i++) l.tpa[i] = (uchar *)&l.lm->tp[i]; + + l.rp = ((Lancemem *)LANCERAM)->rp; + l.tp = ((Lancemem *)LANCERAM)->tp; } else { /* * toggle lance's reset line diff --git a/power/dat.h b/power/dat.h index e0945f634d7b88e82047dfa659fde9b7c625f547..68900cfee81a6a06a8539c4b82f52bbd42faa156 100644 --- a/power/dat.h +++ b/power/dat.h @@ -37,7 +37,6 @@ typedef struct Seg Seg; typedef struct Stream Stream; typedef struct Ureg Ureg; typedef struct User User; -typedef struct Syslog Syslog; typedef int Devgen(Chan*, Dirtab*, int, int, Dir*); @@ -697,14 +696,3 @@ extern Dev devtab[]; extern char devchar[]; extern FPsave initfp; -/* - * kernel based system log, passed between crashes - */ -#define SYSLOG ((Syslog *)(0xa0001B00)) -#define SYSLOGMAGIC 0x87654321 -struct Syslog -{ - ulong magic; - char *next; - char buf[8*1024]; -}; diff --git a/power/main.c b/power/main.c index f1eeff01293e5752199cb606595bc89c365688ab..de8510a21a073b10a5749feb7adc367e7a4a230d 100644 --- a/power/main.c +++ b/power/main.c @@ -47,6 +47,7 @@ main(void) active.machs = 1; confinit(); arginit(); + sysloginit(); lockinit(); printinit(); tlbinit(); @@ -59,7 +60,6 @@ main(void) ioboardinit(); chandevreset(); streaminit(); - sysloginit(); pageinit(); userinit(); launchinit(); @@ -112,12 +112,16 @@ ioboardinit(void) { long i; int noforce; + int maxlevel; ioid = *IOID; - if(ioid >= IO3R1) + if(ioid >= IO3R1){ + maxlevel = 11; noforce = 1; - else + } else { + maxlevel = 8; noforce = 0; + } /* @@ -138,7 +142,7 @@ ioboardinit(void) /* * tell IO2 to sent all interrupts to CPU 0's SBCC */ - for(i=0; i<8; i++) + for(i=0; ii[i].vec = 0<<8; /* @@ -302,11 +306,18 @@ void launch(int n) { Beef *p; - long i; + long i, s; + ulong *ptr; p = (Beef*) 0xb0000500 + n; p->launch = newstart; - p->sum -= (long)newstart; + p->sum = 0; + s = 0; + ptr = (ulong*)p; + for (i = 0; i < sizeof(Beef)/sizeof(ulong); i++) + s += *ptr++; + p->sum = -(s+1); + for(i=0; i<3000000; i++) if(p->launch == 0) break;