From 9b1a63e9a19f340d7b97a96ca77963e602327f92 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 24 Jul 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-07-24 --- gnot/errno.h | 2 +- pc/cga.c | 58 ++++++++++++++++++++++ pc/trap.c | 4 +- pc/vga.c | 36 +++++++++++--- port/devproc.c | 2 +- port/portdat.h | 127 ++++++++++++++++++++++++------------------------- port/segment.c | 10 +++- port/sysproc.c | 3 ++ power/errno.h | 2 +- ss/trap.c | 3 +- 10 files changed, 166 insertions(+), 81 deletions(-) create mode 100644 pc/cga.c diff --git a/gnot/errno.h b/gnot/errno.h index 77dba6e66fe0e343de6a731260f4aab29321d431..94593202b5cc1e67e38307ab054bea9620c647bb 100644 --- a/gnot/errno.h +++ b/gnot/errno.h @@ -1,5 +1,5 @@ enum{ - Enevermind, /* never mind */ + Enoerror, /* no error */ Enofd, /* no free file descriptors */ Ebadfd, /* fd out of range or not open */ Ebadusefd, /* inappropriate use of fd */ diff --git a/pc/cga.c b/pc/cga.c new file mode 100644 index 0000000000000000000000000000000000000000..cdea7ed446290ac0c709a16132309d86eb4e7cd6 --- /dev/null +++ b/pc/cga.c @@ -0,0 +1,58 @@ +#include "u.h" +#include "lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" + +#define WIDTH 160 +#define HEIGHT 24 +#define SCREEN ((char *)(0xB8000|KZERO)) +int pos; + +void +screeninit(void) +{ + memset(SCREEN+pos, 0, WIDTH*HEIGHT-pos); +} + +void +screenputc(int c) +{ + int i; + static int color; + + if(c == '\n'){ + pos = pos/WIDTH; + pos = (pos+1)*WIDTH; + } else if(c == '\t'){ + i = 8 - ((pos/2)&7); + while(i-->0) + screenputc(' '); + } else if(c == '\b'){ + if(pos >= 2) + pos -= 2; + screenputc(' '); + pos -= 2; + } else { + SCREEN[pos++] = c; + SCREEN[pos++] = 0x1d; + } + if(pos >= WIDTH*HEIGHT){ + memmove(SCREEN, &SCREEN[WIDTH], WIDTH*(HEIGHT-1)); + memset(&SCREEN[WIDTH*(HEIGHT-1)], 0, WIDTH); + pos = WIDTH*(HEIGHT-1); + } +} + +void +screenputs(char *s, int n) +{ + while(n-- > 0) + screenputc(*s++); +} + +int +screenbits(void) +{ + return 4; +} diff --git a/pc/trap.c b/pc/trap.c index 1b0fe2bd42dae6c019366f7bc8d478a348429295..7ff17ba6731366fd0d78489185c5db4569863fd2 100644 --- a/pc/trap.c +++ b/pc/trap.c @@ -259,7 +259,7 @@ syscall(Ureg *ur) if(ax == NOTED){ noted(ur, *(ulong*)(sp+BY2WD)); ret = -1; - } else if(u->nnote){ + } else if(u->nnote && ax!=FORK){ ur->ax = ret; notify(ur); } @@ -346,7 +346,7 @@ noted(Ureg *ur, ulong arg0) u->notified = 0; nur->flags = (u->svflags&0xffffff00) | (ur->flags&0xff); memmove(ur, u->ureg, sizeof(Ureg)); - ur->ax = -1; /* return error from the interrupted call */ + ur->ax = -1; /* return error from the interrupted syscall */ switch(arg0){ case NCONT: splhi(); diff --git a/pc/vga.c b/pc/vga.c index 38fb39d44810f2cee6f8540ea7ef6c916e99496f..1bd90cda1169c3154bad1a9c964aa69b17539558 100644 --- a/pc/vga.c +++ b/pc/vga.c @@ -9,21 +9,43 @@ enum { GRX= 0x3CE, /* index to graphics registers */ GR= 0x3CF, /* graphics registers 0-8 */ + SRX= 0x3C4, /* index to sequence registers */ + SR= 0x3C5, /* sequence registers 0-7 */ }; +void +srout(int reg, int val) +{ + outb(SRX, reg); + outb(SR, val); +} + +void +grout(int reg, int val) +{ + outb(GRX, reg); + outb(GR, val); +} + /* * look at VGA registers */ void vgainit(void) { + uchar *display; int i; - uchar x; - for(i = 0; i < 9; i++){ - outb(GRX, i); - x = inb(GR); - print("GR%d == %ux\n", i, x); - } - panic("for the hell of it"); + srout(2, 0x0f); /* enable all 4 color planes */ + srout(4, 0x08); /* quad mode */ + grout(5, 0x40); /* pixel bits are sequential */ + grout(6, 0x01); /* graphics mode - display starts at 0xA0000 */ + + for(;;); + display = (uchar*)(0xA0000 | KZERO); + for(i = 0; i < 128*1024; i++) + display[i] = 0x00; + + for(i = 0; i < 4*640; i++) + display[i] = 0xff; } diff --git a/port/devproc.c b/port/devproc.c index 76cb003b6202245551b04d8d2b257116104d49a5..ecdcae346f84018cb06daaed6abfc1ab67929190 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -273,7 +273,7 @@ procread(Chan *c, void *va, long n, ulong offset) s->steal++; qunlock(&s->lk); if(pagedout(pg)){ - pprint("nonresident page addr %lux (complain to rob)\n", offset); + pprint("nonresident page addr %lux (complain to philw)\n", offset); memset(a, 0, n); }else{ k = kmap(pg); diff --git a/port/portdat.h b/port/portdat.h index ac6229753a46ae4abd38c2c8230c79c9f2f65a93..3d45eb1815a83ca7339c591a2ad5c568de165a4b 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -63,7 +63,7 @@ struct Alarm List; Lock; int busy; - long dt; /* may underflow in clock(); must be signed */ + long dt; /* may underflow in clock(); must be signed */ void (*f)(void*); void *arg; }; @@ -86,20 +86,20 @@ struct Alarms struct Block { Block *next; - uchar *rptr; /* first unconsumed byte */ - uchar *wptr; /* first empty byte */ - uchar *lim; /* 1 past the end of the buffer */ - uchar *base; /* start of the buffer */ + uchar *rptr; /* first unconsumed byte */ + uchar *wptr; /* first empty byte */ + uchar *lim; /* 1 past the end of the buffer */ + uchar *base; /* start of the buffer */ uchar flags; uchar type; }; struct Blist { Lock; - Block *first; /* first data block */ - Block *last; /* last data block */ - long len; /* length of list in bytes */ - int nb; /* number of blocks in list */ + Block *first; /* first data block */ + Block *last; /* last data block */ + long len; /* length of list in bytes */ + int nb; /* number of blocks in list */ }; /* @@ -107,21 +107,21 @@ struct Blist { */ enum { - Aaccess, /* as in access, stat */ - Atodir, /* as in chdir */ - Aopen, /* for i/o */ - Amount, /* to be mounted upon */ - Acreate, /* file is to be created */ + Aaccess, /* as in access, stat */ + Atodir, /* as in chdir */ + Aopen, /* for i/o */ + Amount, /* to be mounted upon */ + Acreate, /* file is to be created */ }; /* * Chan.flags */ -#define COPEN 1 /* for i/o */ -#define CMOUNT 2 /* is result of a mount/bind */ -#define CCREATE 4 /* permits creation if CMOUNT */ -#define CCEXEC 8 /* close on exec */ -#define CFREE 16 /* not in use */ +#define COPEN 1 /* for i/o */ +#define CMOUNT 2 /* is result of a mount/bind */ +#define CCREATE 4 /* permits creation if CMOUNT */ +#define CCEXEC 8 /* close on exec */ +#define CFREE 16 /* not in use */ struct Chan { @@ -200,9 +200,9 @@ struct Etherpkt { uchar data[1500]; uchar crc[4]; }; -#define ETHERMINTU 60 /* minimum transmit size */ -#define ETHERMAXTU 1514 /* maximum transmit size */ -#define ETHERHDRSIZE 14 /* size of an ethernet header */ +#define ETHERMINTU 60 /* minimum transmit size */ +#define ETHERMAXTU 1514 /* maximum transmit size */ +#define ETHERHDRSIZE 14 /* size of an ethernet header */ /* * character based IO (mouse, keyboard, console screen) @@ -287,12 +287,12 @@ struct Page struct Swapalloc { - Lock; /* Free map lock */ - int free; /* Number of currently free swap pages */ - char *swmap; /* Base of swap map in memory */ - char *alloc; /* Round robin allocator */ - char *top; /* Top of swap map */ - Rendez r; /* Pager kproc idle sleep */ + Lock; /* Free map lock */ + int free; /* Number of currently free swap pages */ + char *swmap; /* Base of swap map in memory */ + char *alloc; /* Round robin allocator */ + char *top; /* Top of swap map */ + Rendez r; /* Pager kproc idle sleep */ }swapalloc; struct Image @@ -390,17 +390,17 @@ struct Palloc Lock; ulong addr; int active; - Page *page; /* base of Page structures, indexed by phys page number */ - ulong minppn; /* index of first usable page */ - Page *head; /* most recently used */ - Page *tail; /* least recently used */ - ulong freecount; /* how many pages on free list now */ - ulong user; /* how many user pages */ + Page *page; /* base of Page structures */ + ulong minppn; /* index of first usable page */ + Page *head; /* most recently used */ + Page *tail; /* least recently used */ + ulong freecount; /* how many pages on free list now */ + ulong user; /* how many user pages */ Page *hash[PGHSIZE]; Lock hashlock; - Rendez r; /* Sleep for free mem */ - QLock pwait; /* Queue of procs waiting for memory */ - int wanted; /* Do the wakeup at free */ + Rendez r; /* Sleep for free mem */ + QLock pwait; /* Queue of procs waiting for memory */ + int wanted; /* Do the wakeup at free */ }; enum /* Argument to forkpgrp call */ @@ -523,37 +523,37 @@ struct Qinfo /* * Queue.flag */ -#define QHUNGUP 0x1 /* flag bit meaning the stream has been hung up */ +#define QHUNGUP 0x1 /* flag bit meaning the stream has been hung up */ #define QINUSE 0x2 -#define QHIWAT 0x4 /* queue has gone past the high water mark */ +#define QHIWAT 0x4 /* queue has gone past the high water mark */ #define QDEBUG 0x8 struct Queue { Blist; int flag; - Qinfo *info; /* line discipline definition */ - Queue *other; /* opposite direction, same line discipline */ - Queue *next; /* next queue in the stream */ + Qinfo *info; /* line discipline definition */ + Queue *other; /* opposite direction, same line discipline */ + Queue *next; /* next queue in the stream */ void (*put)(Queue*, Block*); - QLock rlock; /* mutex for processes sleeping at r */ - Rendez r; /* standard place to wait for flow control */ - Rendez *rp; /* where flow control wakeups go to */ - void *ptr; /* private info for the queue */ + QLock rlock; /* mutex for processes sleeping at r */ + Rendez r; /* standard place to wait for flow control */ + Rendez *rp; /* where flow control wakeups go to */ + void *ptr; /* private info for the queue */ }; struct Stream { - QLock; /* structure lock */ - short inuse; /* number of processes in stream */ - short opens; /* number of processes with stream open */ - ushort hread; /* number of reads after hangup */ - ushort type; /* correlation with Chan */ - ushort dev; /* ... */ - ushort id; /* ... */ - QLock rdlock; /* read lock */ - Queue *procq; /* write queue at process end */ - Queue *devq; /* read queue at device end */ - Block *err; /* error message from down stream */ - int forcedelim; /* force a delimiter before the next message */ + QLock; /* structure lock */ + short inuse; /* number of processes in stream */ + short opens; /* number of processes with stream open */ + ushort hread; /* number of reads after hangup */ + ushort type; /* correlation with Chan */ + ushort dev; /* ... */ + ushort id; /* ... */ + QLock rdlock; /* read lock */ + Queue *procq; /* write queue at process end */ + Queue *devq; /* read queue at device end */ + Block *err; /* error message from down stream */ + int forcedelim; /* force a delimiter before the next message */ }; /* @@ -578,13 +578,13 @@ enum { Sdataqid = Shighqid, Sctlqid = Sdataqid-1, Slowqid = Sctlqid, - Streamhi= (9*1024), /* byte count high water mark */ - Streambhi= 32, /* block count high water mark */ + Streamhi= (9*1024), /* byte count high water mark */ + Streambhi= 32, /* block count high water mark */ }; -#define MAXSYSARG 6 /* for mount(fd, mpt, flag, arg, srv, authfd) */ +#define MAXSYSARG 6 /* for mount(fd, mpt, flag, arg, srv, authfd) */ #define PRINTSIZE 256 -#define NUMSIZE 12 /* size of formatted number */ +#define NUMSIZE 12 /* size of formatted number */ extern FPsave initfp; extern Conf conf; @@ -600,6 +600,3 @@ extern Image swapimage; #define CHDIR 0x80000000L #define CHAPPEND 0x40000000L #define CHEXCL 0x20000000L - - - diff --git a/port/segment.c b/port/segment.c index 178adb301186e6a465e032940ee93f5cdf6a2966..d3821698de89b87601f0d19692de60959cc9a812 100644 --- a/port/segment.c +++ b/port/segment.c @@ -196,7 +196,10 @@ attachimage(int type, Chan *c, ulong base, ulong len) lock(&imagealloc); - /* Search the image cache for remains of the text from a previous incarnation */ + /* + * Search the image cache for remains of the text from a previous + * or currently running incarnation + */ for(i = ihash(c->qid.path); i; i = i->hash) { if(c->qid.path == i->qid.path) { lock(i); @@ -211,6 +214,10 @@ attachimage(int type, Chan *c, ulong base, ulong len) } } + /* + * imagereclaim dumps pages from the free list which are cached by image + * structures. This should free some image structures. + */ while(!(i = imagealloc.free)) { unlock(&imagealloc); imagereclaim(); @@ -241,7 +248,6 @@ found: else incref(i->s); - unlock(i); return i; } diff --git a/port/sysproc.c b/port/sysproc.c index 55edf1fb7051d7c47f181c35d4f8e67d8e27d3cf..e1be1c56bcd6ca74fdd632a66c0716fac30a6239 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -264,12 +264,14 @@ sysexec(ulong *arg) fdclose(i, CCEXEC); /* Text. Shared. Attaches to cache image if possible */ + /* attachimage returns a locked cache image */ img = attachimage(SG_TEXT|SG_RONLY, tc, UTZERO, (t-UTZERO)>>PGSHIFT); ts = img->s; p->seg[TSEG] = ts; ts->flushme = 1; ts->fstart = 0; ts->flen = sizeof(Exec)+text; + unlock(img); /* Data. Shared. */ s = newseg(SG_DATA, t, (d-t)>>PGSHIFT); @@ -408,6 +410,7 @@ syserrstr(ulong *arg) validaddr(arg[0], ERRLEN, 1); memmove((char*)arg[0], u->error, ERRLEN); + strncpy(u->error, errstrtab[0], ERRLEN); return 0; } diff --git a/power/errno.h b/power/errno.h index e42273972351e0d4b423c6b6922491ca511cb170..0ae0c2267cc7d3f07c0626df5955a3caba1e819d 100644 --- a/power/errno.h +++ b/power/errno.h @@ -1,5 +1,5 @@ enum{ - Enevermind, /* never mind */ + Enoerror, /* no error */ Enofd, /* no free file descriptors */ Ebadfd, /* fd out of range or not open */ Ebadusefd, /* inappropriate use of fd */ diff --git a/ss/trap.c b/ss/trap.c index 6c1963f336c38a2fce18eb692bd8d1fec9faead8..4cbbaa350ccb25c22819bf173a5348977432066c 100644 --- a/ss/trap.c +++ b/ss/trap.c @@ -284,7 +284,6 @@ noted(Ureg **urp, ulong arg0) } u->notified = 0; memmove(*urp, u->ureg, sizeof(Ureg)); - (*urp)->r7 = -1; /* return error from the interrupted call */ switch(arg0){ case NCONT: splhi(); @@ -412,7 +411,7 @@ syscall(Ureg *aur) u->p->insyscall = 0; if(r7 == NOTED) /* ugly hack */ noted(&aur, *(ulong*)(sp+1*BY2WD)); /* doesn't return */ - if(u->nnote){ + if(u->nnote && r7!=FORK){ ur->r7 = ret; notify(ur); }