From e3917495f5a86ca61c288b0441537db93642043b Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 15 Oct 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-10-15 --- gnot/fns.h | 1 + pc/devether.c | 4 +-- pc/devincon.c | 30 ++-------------- pc/devrtc.c | 1 - pc/ether509.c | 9 ++--- pc/fns.h | 1 + pc/kbd.c | 98 +++++++++++++++++++++++++++++++++++++-------------- pc/screen.h | 1 - pc/vga.c | 10 +++--- port/devbit.c | 30 ++++++++++++++-- power/fns.h | 1 + ss/fns.h | 1 + 12 files changed, 117 insertions(+), 70 deletions(-) diff --git a/gnot/fns.h b/gnot/fns.h index 924b972bbe21c5e11ae5c973b321cd526320fcdf..f746e8fe7958c5c86734a3517978adf0847853e9 100644 --- a/gnot/fns.h +++ b/gnot/fns.h @@ -47,6 +47,7 @@ void spldone(void); int splduart(void); int tas(char*); void touser(void*); +#define screenupdate(a) #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) #define kmapperm(x) kmap(x) #define getcallerpc(x) (*(ulong*)(x)) diff --git a/pc/devether.c b/pc/devether.c index 7beef51a0e4cc1bb30894d5dcf7a153c28790af3..f5416ba2d541d68e45a5144403ae20ab9b119421 100644 --- a/pc/devether.c +++ b/pc/devether.c @@ -353,14 +353,14 @@ etherup(EtherCtlr *cp, void *data, int len) qunlock(tp); continue; } - if(waserror() == 0){ + if(!waserror()){ bp = allocb(len); memmove(bp->rptr, p, len); bp->wptr += len; bp->flags |= S_DELIM; PUTNEXT(tp->q, bp); + poperror(); } - poperror(); qunlock(tp); } } diff --git a/pc/devincon.c b/pc/devincon.c index e90262e79b0fc069cdc5cdee68cb1fb008b7b6c5..21afbea0c30c7cd3fffe68ed5f4bfd57943d7b76 100644 --- a/pc/devincon.c +++ b/pc/devincon.c @@ -183,46 +183,29 @@ Dirtab incondir[]={ }; #define NINCON (sizeof incondir/sizeof incondir[0]) -static void -Xdelay(int n) -{ - while(--n >= 0) ; -} -#define SDLY 1000 - -/*#define Xdelay(n)*/ - static void reset(int dev) /* hardware reset */ { outb(dev+Qpcr, Finitbar); - Xdelay(10000); outb(dev+Qpcr, 0); - Xdelay(10000); outb(dev+Qpcr, Finitbar); } static void wrctl(int dev, int data) /* write control character */ { - Xdelay(SDLY); outb(dev+Qpcr, Finitbar); /* no interrupts, please */ outb(dev+Qdlr, data); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Fstrobe); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Fie); } static void wrdata(int dev, int data) /* write data character */ { - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Fsi); outb(dev+Qdlr, data); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Fsi|Fstrobe); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Fsi|Fie); } @@ -231,9 +214,7 @@ wrcmd(int dev, int data) /* write command */ { outb(dev+Qpcr, Finitbar|Faf); outb(dev+Qdlr, data); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Faf|Fstrobe); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Faf|Fie); } @@ -267,9 +248,7 @@ static void iwrcmd(int dev, int data) /* write command at interrupt level */ { outb(dev+Qdlr, data); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Faf|Fstrobe); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Faf); } @@ -326,9 +305,7 @@ static void irdnop(int dev, int pcr) /* read nop (mux reset) */ { outb(dev+Qdlr, 0x03); - Xdelay(SDLY); outb(dev+Qpcr, Finitbar|Faf|Fsi|Fstrobe); - Xdelay(SDLY); outb(dev+Qpcr, pcr); } @@ -753,8 +730,7 @@ inconoput(Queue *q, Block *bp) int dev; Incon *ip; ulong end; - int chan; - int ctl; + int status, chan, ctl; int n, size; ip = (Incon *)q->ptr; @@ -819,10 +795,10 @@ inconoput(Queue *q, Block *bp) /* * spin till there is room */ - for(n=0, end = NOW+1000; (ctl=rdstatus(ip)) & TX_FULL; n++){ + for(n=0, end = NOW+1000; (status=rdstatus(ip)) & TX_FULL; n++){ nop(); /* make sure we don't optimize too much */ if(NOW > end){ - print("incon output stuck 0 %.2ux\n", ctl); + print("incon output stuck 0 %.2ux\n", status); freemsg(q, bp); qunlock(&ip->xmit); return; diff --git a/pc/devrtc.c b/pc/devrtc.c index 54c9964ce0c0e985ab2e09382fb230d8fd9b101e..d675532c11a5e5d1f697eaf74256d232898c89fd 100644 --- a/pc/devrtc.c +++ b/pc/devrtc.c @@ -60,7 +60,6 @@ rtcreset(void) void rtcinit(void) { - print("nvrm(0x2b) == 0x%lux\n", nvramread(0x2b)); } Chan* diff --git a/pc/ether509.c b/pc/ether509.c index 380145c4896db0e46a91b1d228eda1c524eb4e77..992518a6459fa17c11dae04f777a39d63e27dde2 100644 --- a/pc/ether509.c +++ b/pc/ether509.c @@ -295,7 +295,6 @@ receive(EtherCtlr *cp) * without updating the ring. */ if(status & RxError){ - print("error #%ux, #%ux\n", status, getdiag(hw)); switch(status & RxErrMask){ case RxErrOverrun: /* Overrrun */ @@ -392,7 +391,7 @@ interrupt(EtherCtlr *cp) { EtherHw *hw = cp->hw; ushort status; - uchar txstatus; + uchar txstatus, x; status = ins(hw->addr+Status); @@ -411,8 +410,10 @@ interrupt(EtherCtlr *cp) */ txstatus = 0; while(ins(hw->addr+Status) & TxComplete){ - txstatus |= inb(hw->addr+TxStatus); - outb(hw->addr+TxStatus, 0); + x = inb(hw->addr+TxStatus); + if(x) + outb(hw->addr+TxStatus, 0); + txstatus |= x; } if(txstatus & (TxJabber|TxUnderrun)) COMMAND(hw, TxReset, 0); diff --git a/pc/fns.h b/pc/fns.h index b94d903b19976fe7e4770807a98901e537e180de..55d78c82f982bbfcd2c93ffcbe4f04a093b3d986 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -70,6 +70,7 @@ void uartclock(void); void uartintr0(Ureg*); void uartspecial(int, IOQ*, IOQ*, int); void vgainit(void); +#define screenupdate(a) #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) #define kmapperm(x) kmap(x) #define getcallerpc(x) (*(ulong*)(x)) diff --git a/pc/kbd.c b/pc/kbd.c index 4f999c3bb0fb7098a954d50e3622dbfd812fbfb2..817106fd9784f3b9880cd81c7e44fac131ef8b14 100644 --- a/pc/kbd.c +++ b/pc/kbd.c @@ -106,6 +106,7 @@ KIOQ kbdq; static int mousebuttons; static int keybuttons; +static uchar ccc; /* * predeclared @@ -114,6 +115,14 @@ static void kbdintr(Ureg*); enum { + /* controller command byte */ + Cscs1= (1<<6), /* scan code set 1 */ + Cmousedis= (1<<5), /* mouse disable */ + Ckbddis= (1<<4), /* kbd disable */ + Csf= (1<<2), /* system flag */ + Cmouseint= (1<<1), /* mouse interrupt enable */ + Ckbdint= (1<<0), /* kbd interrupt enable */ + /* what kind of mouse */ Mouseother= 0, Mouseserial= 1, @@ -121,6 +130,8 @@ enum }; static int mousetype; +static int mymouseputc(IOQ*, int); + /* * wait for output no longer busy */ @@ -129,9 +140,11 @@ outready(void) { int tries; - for(tries = 0; (inb(Status) & Outbusy); tries++) - if(tries > 10000) + for(tries = 0; (inb(Status) & Outbusy); tries++){ + if(tries > 500) return -1; + delay(2); + } return 0; } @@ -143,9 +156,11 @@ inready(void) { int tries; - for(tries = 0; !(inb(Status) & Inready); tries++) - if(tries > 1000) + for(tries = 0; !(inb(Status) & Inready); tries++){ + if(tries > 500) return -1; + delay(2); + } return 0; } @@ -159,21 +174,26 @@ mousecmd(int cmd) int tries; c = 0; + tries = 0; do{ - for(tries=0; tries < 100; tries++){ - if(outready() < 0) - return -1; - outb(Cmd, 0xD4); - if(outready() < 0) - return -1; - outb(Data, cmd); - if(inready() < 0) - return -1; - c = inb(Data); - } + if(tries++ > 5) + break; + if(outready() < 0) + continue; + outb(Cmd, 0xD4); + if(outready() < 0) + continue; + outb(Data, cmd); + if(outready() < 0) + continue; + if(inready() < 0) + continue; + c = inb(Data); } while(c == 0xFE); - if(c != 0xFA) + if(c != 0xFA){ + print("mouse returns %2.2ux to the %2.2ux command\n", c, cmd); return -1; + } return 0; } @@ -183,6 +203,7 @@ mousecmd(int cmd) void i8042a20(void) { + outready(); outb(Cmd, 0xD1); outready(); outb(Data, 0xDF); @@ -223,11 +244,24 @@ kbdinit(void) if(c & Inready) inb(Data); + /* get current controller command byte */ + outb(Cmd, 0x20); + if(inready() < 0){ + print("kbdinit: can't read ccc\n"); + ccc = 0; + } else + ccc = inb(Data); + /* enable kbd xfers and interrupts */ + ccc &= ~Ckbddis; + ccc |= Csf | Ckbdint | Cscs1; + if(outready() < 0) + print("kbd init failed\n"); outb(Cmd, 0x60); if(outready() < 0) print("kbd init failed\n"); - outb(Data, 0x65); + outb(Data, ccc); + outready(); } /* @@ -236,7 +270,7 @@ kbdinit(void) void mouseserial(int port) { - if(mousetype) + if(mousetype == Mouseserial) return; /* set up /dev/eia0 as the mouse */ @@ -250,24 +284,32 @@ mouseserial(int port) void mouseps2(void) { - if(mousetype) - return; + int x; bigcursor(); setvec(Mousevec, kbdintr); /* enable kbd/mouse xfers and interrupts */ + x = splhi(); + ccc &= ~Cmousedis; + ccc |= Cmouseint; + if(outready() < 0) + print("mouse init failed\n"); outb(Cmd, 0x60); if(outready() < 0) - print("kbd init failed\n"); - outb(Data, 0x47); + print("mouse init failed\n"); + outb(Data, ccc); if(outready() < 0) - print("kbd init failed\n"); + print("mouse init failed\n"); outb(Cmd, 0xA8); + if(outready() < 0) + print("mouse init failed\n"); /* make mouse streaming, enabled */ mousecmd(0xEA); mousecmd(0xF4); + splx(x); + mousetype = MousePS2; } @@ -314,8 +356,8 @@ static int shift; * * shift & left button is the same as middle button */ -static void -mymouseputc(int c) +static int +mymouseputc(IOQ *q, int c) { static short msg[3]; static int nb; @@ -323,11 +365,12 @@ mymouseputc(int c) static lastdx, lastdy; extern Mouseinfo mouse; + USED(q); /* not */ /* * check byte 0 for consistency */ if(nb==0 && (c&0xc8)!=0x08) - return; + return 0; msg[nb] = c; if(++nb == 3){ @@ -345,6 +388,7 @@ mymouseputc(int c) spllo(); /* mouse tracking kills uart0 */ mouseclock(); } + return 0; } /* @@ -404,7 +448,7 @@ kbdintr0(void) * if it's the mouse... */ if(s & Minready){ - mymouseputc(c); + mymouseputc(&mouseq, c); return 0; } diff --git a/pc/screen.h b/pc/screen.h index 18eeecffdd0310be6a8293457df46d510a526680..311016a5a61d07c6f8bad67595b2d4482cabe2d9 100644 --- a/pc/screen.h +++ b/pc/screen.h @@ -30,5 +30,4 @@ extern void mouseupdate(int); #define hwscreenwrite(a, b) -#define screenupdate(z) int islcd; diff --git a/pc/vga.c b/pc/vga.c index 710ce2197a4c19fd85bd06d2a668dd0e1809fcdc..00a51b2e74d3d223db1052c610faf3db45798f33 100644 --- a/pc/vga.c +++ b/pc/vga.c @@ -49,18 +49,18 @@ struct VGAmode }; /* - * 640x480 display, 16 bit color. + * 640x480 display, 16 bit color. */ VGAmode mode12 = { /* general */ - 0xe3, 0x00, + 0xe7, 0x00, /* sequence */ 0x03, 0x01, 0x0f, 0x00, 0x06, /* crt */ - 0x63, 0x4f, 0x58, 0x81, 0x59, 0x81, 0x0b, 0x3e, + 0x65, 0x4f, 0x50, 0x88, 0x55, 0x9a, 0x09, 0x3e, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xea, 0x2c, 0xdf, 0x28, 0x00, 0xea, 0xeb, 0xe3, + 0xe8, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3, 0xff, /* graphics */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, @@ -68,7 +68,7 @@ VGAmode mode12 = /* attribute */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x3f, - 0x01, 0x00, 0x0f, 0x00, 0x00, + 0x01, 0x10, 0x0f, 0x00, 0x00, }; diff --git a/port/devbit.c b/port/devbit.c index e04dca4b83b553c364ade7b31d6d3283ade83292..7fbffe20e4b037601b482e6adbf28ea4e20302aa 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -107,6 +107,7 @@ extern islcd; Mouseinfo mouse; Cursorinfo cursor; +Rendez lcdmouse; Cursor arrow = { @@ -161,6 +162,8 @@ void cursoron(int); void cursoroff(int); int mousechanged(void*); +static Rectangle mbb = {10000, 10000, -10000, -10000}; + enum{ Qdir, Qbitblt, @@ -245,6 +248,26 @@ bitdebug(void) print("%d subfonts\n", l); } +/* + * need a process to do scsi transactions to update mouse on LCD + */ +void +lcdmousep(void *a) +{ + USED(a); + for(;;){ + sleep(&lcdmouse, return0, 0); + qlock(&bit); + if(waserror()){ + qunlock(&bit); + continue; + } + screenupdate(mbb); + qunlock(&bit); + poperror(); + } +} + void bitreset(void) { @@ -304,6 +327,8 @@ bitinit(void) cursorback.width = ((16 << gscreen.ldepth) + 31) >> 5; } cursoron(1); + if(islcd) + kproc("lcdmouse", lcdmousep, 0); } Chan* @@ -747,8 +772,6 @@ bitread(Chan *c, void *va, long n, ulong offset) return n; } -static Rectangle mbb = {10000, 10000, -10000, -10000}; - static void mbbrect(Rectangle r) { @@ -814,7 +837,6 @@ bitwrite(Chan *c, void *va, long n, ulong offset) BSubfont *f, *tf, **fp; GFont *ff, **ffp; GCacheinfo *gc; - extern void screenupdate(Rectangle); if(!conf.monitor) error(Egreg); @@ -1989,6 +2011,8 @@ mouseupdate(int dolock) cursoroff(0); mouse.xy = Pt(x, y); cursoron(0); + if(islcd) + wakeup(&lcdmouse); mouse.dx = 0; mouse.dy = 0; mouse.clock = 0; diff --git a/power/fns.h b/power/fns.h index bc7a1f36350698ed1ae2bd3c8dfcf222c7647aa2..d1d8a9eed468dac7cc9bcc8a9410c899e3924524 100644 --- a/power/fns.h +++ b/power/fns.h @@ -71,6 +71,7 @@ void vector0(void); void vector80(void); void vmereset(void); void wbflush(void); +#define screenupdate(a) #define waserror() setlabel(&u->errlab[u->nerrlab++]) #define kmapperm(x) kmap(x) #define KADDR(a) ((void*)((ulong)(a)|KZERO)) diff --git a/ss/fns.h b/ss/fns.h index c5454e52292b9fff756f66338270e4d44cfb8b8d..c3864ddcaf5c686eedcb30715aab1991eb3b1441 100644 --- a/ss/fns.h +++ b/ss/fns.h @@ -66,6 +66,7 @@ ulong tas(ulong*); void touser(ulong); void trap(Ureg*); void trapinit(void); +#define screenupdate(a) #define wbflush() /* mips compatibility */ #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) #define getcallerpc(x) _getcallerpc()