From 83744fafb874d5bbc56e7894036cd724ac706efb Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 7 Sep 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-09-07 --- carrera/io.h | 18 ++- carrera/kbd.c | 382 +++++++++++++++++++++++++++++++++++++++++++++++ carrera/l.s | 32 +++- carrera/main.c | 21 ++- carrera/mem.h | 1 + carrera/screen.c | 90 ++++++++--- carrera/trap.c | 35 +++-- port/devbit.c | 18 --- port/devmnt.c | 8 +- port/fault.c | 5 + 10 files changed, 531 insertions(+), 79 deletions(-) create mode 100644 carrera/kbd.c diff --git a/carrera/io.h b/carrera/io.h index 86f5387d1ae45ce6ff92cf96543cc9de63295999..0c39d1ce0c9549dbc724798e7a8ffbf02bf75746 100644 --- a/carrera/io.h +++ b/carrera/io.h @@ -4,7 +4,7 @@ enum { Devicephys = 0x80000000, - Eisaphys = 0x90000000, + Eisaphys = 0x90000000, /* IO port physical */ Devicevirt = 0xE0000000, Dmabase = 0xE0000000, Sonicbase = 0xE0001000, @@ -19,17 +19,21 @@ enum NvramRW = 0xE000A000, NvramRO = 0xE000B000, Enetoffset = 0, - KeyboardIO = 0xE0005000, + KeyboardIO = 0xE0005000, + Keyctl = 6, + Keydat = 7, MouseIO = 0xE0005000, SoundIO = 0xE000C000, EisaLatch = 0xE000E000, Diag = 0xE000F000, - EisaControl = 0xE0010000, /* Second 64K Page from Devicevirt */ VideoCTL = 0x60000000, VideoMEM = 0x40000000, I386ack = 0xE000023f, + EisaControl = 0xE0010000, /* Second 64K Page from Devicevirt */ + Eisamphys = 0x91000000, + Eisamvirt = 0xE0300000, /* Second 1M page entry from Intctl */ Intctlphys = 0xF0000000, - Intctlvirt = 0xE0040000, + Intctlvirt = 0xE0200000, Uart1int = (1<<9), Uart0int = (1<<8), Mouseint = (1<<7), @@ -40,8 +44,8 @@ enum Soundint = (1<<2), Floppyint = (1<<1), Parallelint = (1<<0), - Intenareg = 0xE0040004, /* Device interrupt enable */ - Intcause = 0xE0040007, /* Decice interrupt cause register */ + Intenareg = 0xE0200004, /* Device interrupt enable */ + Intcause = 0xE0200007, /* Decice interrupt cause register */ Ttbr = 0x8000001C, /* Translation table base address */ Tlrb = 0x80000024, /* Translation table limit address */ @@ -61,6 +65,6 @@ struct Tte #define CACHELINE(type, v) (type*)(((ulong)(v)+127)&~127) #define UNCACHED(type, v) (type*)((ulong)(v)|0xA0000000) -#define EISAUNCACHED(v) (0xA0000000|0x10000000|(v)) +#define EISA(v) (Eisamvirt+(v)) #define EISAOUTB(port, v) *(uchar*)((EisaControl+(port))^7) = v #define EISAINB(port) (*(uchar*)((EisaControl+(port))^7)) diff --git a/carrera/kbd.c b/carrera/kbd.c new file mode 100644 index 0000000000000000000000000000000000000000..e5f54ea3387849a0a0fd3b7836af93fc801c1609 --- /dev/null +++ b/carrera/kbd.c @@ -0,0 +1,382 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "io.h" +#include "../port/error.h" + +#include "devtab.h" + +enum +{ + /* + * commands + */ + Krdcmd= 0x20, /* read command byte */ + Kwrcmd= 0x60, /* write command byte */ + Kselftest= 0xAA, /* self test */ + Ktest= 0xAB, /* keyboard test */ + Kdisable= 0xAD, /* disable keyboard */ + Kenable= 0xAE, /* enable keyboard */ + Krdin= 0xC0, /* read input port */ + Krdout= 0xD0, /* read output port */ + Kwrout= 0xD1, /* write output port */ + Krdtest= 0xE0, /* read test inputs */ + Kwrlights= 0xED, /* set lights */ + Kreset= 0xF0, /* soft reset */ + /* + * magic characters + */ + Msetscan= 0xF0, /* set scan type (0 == unix) */ + Menable= 0xF4, /* enable the keyboard */ + Mdisable= 0xF5, /* disable the keyboard */ + Mdefault= 0xF6, /* set defaults */ + Mreset= 0xFF, /* reset the keyboard */ + /* + * responses from keyboard + */ + Rok= 0xAA, /* self test OK */ + Recho= 0xEE, /* ??? */ + Rack= 0xFA, /* command acknowledged */ + Rfail= 0xFC, /* self test failed */ + Rresend= 0xFE, /* ??? */ + Rovfl= 0xFF, /* input overflow */ + /* + * command register bits + */ + Cintena= 1<<0, /* enable output interrupt */ + Csystem= 1<<2, /* set system */ + Cinhibit= 1<<3, /* inhibit override */ + Cdisable= 1<<4, /* disable keyboard */ + /* + * output port bits + */ + Osoft= 1<<0, /* soft reset bit (must be 1?) */ + Oparity= 1<<1, /* force bad parity */ + Omemtype= 1<<2, /* simm type (1 = 4Mb, 0 = 1Mb) */ + Obigendian= 1<<3, /* big endian */ + Ointena= 1<<4, /* enable interrupt */ + Oclear= 1<<5, /* clear expansion slot interrupt */ + /* + * status bits + */ + Sobf= 1<<0, /* output buffer full */ + Sibf= 1<<1, /* input buffer full */ + Ssys= 1<<2, /* set by self-test */ + Slast= 1<<3, /* last access was to data */ + Senabled= 1<<4, /* keyboard is enabled */ + Stxtimeout= 1<<5, /* transmit to kybd has timed out */ + Srxtimeout= 1<<6, /* receive from kybd has timed out */ + Sparity= 1<<7, /* parity on byte was even */ + /* + * light bits + */ + L1= 1<<0, /* light 1, network activity */ + L2= 1<<2, /* light 2, caps lock */ + L3= 1<<1, /* light 3, no label */ +}; + +#define KBDCTL (*(uchar*)(KeyboardIO+Keyctl)) +#define KBDDAT (*(uchar*)(KeyboardIO+Keydat)) +#define OUTWAIT while(KBDCTL & Sibf); kdbdly(1) +#define INWAIT while(!(KBDCTL & Sobf)); kdbdly(1) +#define ACKWAIT INWAIT ; if(KBDDAT != Rack) print("bad response\n"); kdbdly(1) + +enum +{ + Spec= 0x80, + + PF= Spec|0x20, /* num pad function key */ + View= Spec|0x00, /* view (shift window up) */ + F= Spec|0x40, /* function key */ + Shift= Spec|0x60, + Break= Spec|0x61, + Ctrl= Spec|0x62, + Latin= Spec|0x63, + Up= Spec|0x70, /* key has come up */ + No= Spec|0x7F, /* no mapping */ + + Tmask= Spec|0x60, +}; + +uchar keymap[] = { +[0] No, No, No, No, No, No, No, F|1, + '\033', No, No, No, No, '\t', '`', F|2, +[0x10] No, Ctrl, Shift, Shift, Shift, 'q', '1', F|3, + No, Shift, 'z', 's', 'a', 'w', '2', F|4, +[0x20] No, 'c', 'x', 'd', 'e', '4', '3', F|5, + No, ' ', 'v', 'f', 't', 'r', '5', F|6, +[0x30] No, 'n', 'b', 'h', 'g', 'y', '6', F|7, + No, View, 'm', 'j', 'u', '7', '8', F|8, +[0x40] No, ',', 'k', 'i', 'o', '0', '9', F|9, + No, '.', '/', 'l', ';', 'p', '-', F|10, +[0x50] No, No, '\'', No, '[', '=', F|11, '\r', + Latin, Shift, '\n', ']', '\\', No, F|12, Break, +[0x60] View, View, Break, Shift, '\177', No, '\b', No, + No, '1', View, '4', '7', ',', No, No, +[0x70] '0', '.', '2', '5', '6', '8', PF|1, PF|2, + No, '\n', '3', No, PF|4, '9', PF|3, No, +[0x80] No, No, No, No, '-', No, No, No, +}; + +uchar skeymap[] = { +[0] No, No, No, No, No, No, No, F|1, + '\033', No, No, No, No, '\t', '~', F|2, +[0x10] No, Ctrl, Shift, Shift, Shift, 'Q', '!', F|3, + No, Shift, 'Z', 'S', 'A', 'W', '@', F|4, +[0x20] No, 'C', 'X', 'D', 'E', '$', '#', F|5, + No, ' ', 'V', 'F', 'T', 'R', '%', F|6, +[0x30] No, 'N', 'B', 'H', 'G', 'Y', '^', F|7, + No, View, 'M', 'J', 'U', '&', '*', F|8, +[0x40] No, '<', 'K', 'I', 'O', ')', '(', F|9, + No, '>', '?', 'L', ':', 'P', '_', F|10, +[0x50] No, No, '"', No, '{', '+', F|11, '\r', + Latin, Shift, '\n', '}', '|', No, F|12, Break, +[0x60] View, View, Break, Shift, '\177', No, '\b', No, + No, '1', View, '4', '7', ',', No, No, +[0x70] '0', '.', '2', '5', '6', '8', PF|1, PF|2, + No, '\n', '3', No, PF|4, '9', PF|3, No, +[0x80] No, No, No, No, '-', No, No, No, +}; + + +struct Kbd +{ + Lock; + int l; +} kbd; + +void +kdbdly(int l) +{ + int i; + + l *= 21; + for(i=0; i 0x87) + return 1; + + /* + * convert + */ + if(shifted) + ch = skeymap[code]; + else + ch = keymap[code]; +iprint("code %d %d\n", code, ch); + /* + * normal character + */ + if(!(ch & Spec)){ + if(ctrled) + ch &= 0x1f; + switch(lstate){ + case 1: + kc[0] = ch; + lstate = 2; + if(ch == 'X') + lstate = 3; + break; + case 2: + kc[1] = ch; + c = latin1(kc); + nk = 2; + putit: + lstate = 0; + if(c != -1) + kbdputc(kbdq, c); + else { + for(i=0; igeneral); i++) genout(i, v->general[i]); @@ -423,7 +456,8 @@ setmode(VGAmode *v) else srout(i, v->sequencer[i]); - crout(Cvre, 0); /* allow writes to CRT registers 0-7 */ + /* allow writes to CRT registers 0-7 */ + crout(Cvre, 0); for(i = 0; i < sizeof(v->crt); i++) crout(i, v->crt[i]); @@ -433,6 +467,26 @@ setmode(VGAmode *v) for(i = 0; i < sizeof(v->attribute); i++) arout(i, v->attribute[i]); + EISAOUTB(0x3C6, 0xFF); /* pel mask */ + EISAOUTB(0x3C8, 0x00); /* pel write address */ + EISAOUTB(0x3bf, 0x03); /* hercules compatibility reg */ + EISAOUTB(0x3d8, 0xa0); /* display mode control register */ + + srout(0x06, v->tseng.sr6); + srout(0x07, v->tseng.sr7); + i = EISAINB(0x3da); /* reset flip-flop. inp stat 1*/ + USED(i); + arout(0x16, v->tseng.ar16); /* misc */ + arout(0x17, v->tseng.ar17); /* misc 1*/ + crout(0x31, v->tseng.crt31); /* extended start. */ + crout(0x32, v->tseng.crt32); /* extended start. */ + crout(0x33, v->tseng.crt33); /* extended start. */ + crout(0x34, v->tseng.crt34); /* stub: 46ee + other bits */ + crout(0x35, v->tseng.crt35); /* overflow bits */ + crout(0x36, v->tseng.crt36); /* overflow bits */ + crout(0x37, v->tseng.crt37); /* overflow bits */ + EISAOUTB(0x3c3, v->tseng.viden);/* video enable */ + /* turn screen on */ srout(1, v->sequencer[1]); } diff --git a/carrera/trap.c b/carrera/trap.c index 925d3c2d5ebf2c6b866eb4be2054a7e9ac9fc05f..bc12854e0f0dab91b1dca4c3619911c06d356131 100644 --- a/carrera/trap.c +++ b/carrera/trap.c @@ -244,7 +244,7 @@ trap(Ureg *ur) postnote(up, 1, buf, NDebug); break; } - print("kernel%d %s pc=%lux\n", m->machno, excname[ecode], ur->pc); + print("kernel %s pc=%lux\n", excname[ecode], ur->pc); dumpregs(ur); dumpstack(); if(m->machno == 0) @@ -285,20 +285,27 @@ intr(Ureg *ur) cause &= INTR7|INTR6|INTR5|INTR4|INTR3|INTR2|INTR1|INTR0; if(cause & INTR3) { - devint = IO(uchar, Intcause); - switch(devint) { - default: - panic("unknown devint=#%lux", devint); + for(;;) { + devint = IO(uchar, Intcause); + if(devint == 0) + break; + switch(devint) { + default: + panic("unknown devint=#%lux", devint); - case 0x28: /* Serial 1 */ - NS16552intr(0); - break; - case 0x24: /* Serial 2 */ - NS16552intr(1); - break; - case 0x14: - etherintr(); - break; + case 0x28: /* Serial 1 */ + NS16552intr(0); + break; + case 0x24: /* Serial 2 */ + NS16552intr(1); + break; + case 0x14: + etherintr(); + break; + case 0x1C: + kbdintr(); + break; + } } cause &= ~INTR3; } diff --git a/port/devbit.c b/port/devbit.c index d6121e327f7d3ee21c70019bf5a49222e84617a6..f6301364e80bf5f0a9ef9c469c2d3ea874857bfe 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -374,8 +374,6 @@ bitattach(char *spec) Chan* bitclone(Chan *c, Chan *nc) { - if(!conf.monitor) - error(Egreg); nc = devclone(c, nc); if(c->qid.path != CHDIR) incref(&bit); @@ -385,16 +383,12 @@ bitclone(Chan *c, Chan *nc) int bitwalk(Chan *c, char *name) { - if(!conf.monitor) - error(Egreg); return devwalk(c, name, bitdir, NBIT, devgen); } void bitstat(Chan *c, char *db) { - if(!conf.monitor) - error(Egreg); devstat(c, db, bitdir, NBIT, devgen); } @@ -403,8 +397,6 @@ bitopen(Chan *c, int omode) { GBitmap *b; - if(!conf.monitor) - error(Egreg); switch(c->qid.path){ case CHDIR: if(omode != OREAD) @@ -465,8 +457,6 @@ bitcreate(Chan *c, char *name, int omode, ulong perm) void bitremove(Chan *c) { - if(!conf.monitor) - error(Egreg); USED(c); error(Eperm); } @@ -474,8 +464,6 @@ bitremove(Chan *c) void bitwstat(Chan *c, char *db) { - if(!conf.monitor) - error(Egreg); USED(c, db); error(Eperm); } @@ -487,8 +475,6 @@ bitclose(Chan *c) BSubfont *s, **sp, **esp; GFont *f, **fp, **efp; - if(!conf.monitor) - error(Egreg); if(c->qid.path!=CHDIR && (c->flag&COPEN)){ lock(&bit); if(c->qid.path == Qmouse) @@ -535,8 +521,6 @@ bitread(Chan *c, void *va, long n, ulong offset) GBitmap *src; BSubfont *s; - if(!conf.monitor) - error(Egreg); if(c->qid.path & CHDIR) return devdirread(c, va, n, bitdir, NBIT, devgen); @@ -842,8 +826,6 @@ bitwrite(Chan *c, void *va, long n, ulong offset) GCacheinfo *gc; char buf[64]; - if(!conf.monitor) - error(Egreg); USED(offset); if(c->qid.path == CHDIR) diff --git a/port/devmnt.c b/port/devmnt.c index 1ac57e8880f548ce6380526548f2552697a0656b..1860824e9f66872d84bed344941ef123d904dc9a 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -516,7 +516,8 @@ mntrdwr(int type, Chan *c, void *buf, long n, ulong offset) m = mntchk(c); uba = buf; - for(cnt = 0; n; n -= nr) { + cnt = 0; + for(;;) { r = mntralloc(c); if(waserror()) { mntfree(r); @@ -529,6 +530,8 @@ mntrdwr(int type, Chan *c, void *buf, long n, ulong offset) r->request.count = limit(n, m->blocksize); mountrpc(m, r); nr = r->reply.count; + if(nr > r->request.count) + nr = r->request.count; if(type == Tread) memmove(uba, r->reply.data, nr); poperror(); @@ -536,7 +539,8 @@ mntrdwr(int type, Chan *c, void *buf, long n, ulong offset) offset += nr; uba += nr; cnt += nr; - if(nr != r->request.count) + n -= nr; + if(nr != r->request.count || n == 0) break; } return cnt; diff --git a/port/fault.c b/port/fault.c index 3ada537df679a66cbfc4378c42f28ce6f30065ba..084abfe974e825ea738c04ece61ebff51229260c 100644 --- a/port/fault.c +++ b/port/fault.c @@ -80,6 +80,11 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) if(pagedout(*pg)) pio(s, addr, soff, pg); + lkp = *pg; + lock(lkp); + if(lkp->image) + duppage(lkp); + unlock(lkp); goto done; case SG_BSS: