MAJOR PCCONS FIXES FOR HANG AFTER COPYRIGHT + TIMEOUT FIXES
authorBruce Evans <bde@runx.oz.au>
Sun, 14 Mar 1993 00:00:00 +0000 (00:00 +0000)
committerBruce Evans <bde@runx.oz.au>
Sun, 14 Mar 1993 00:00:00 +0000 (00:00 +0000)
A20 INFO (Frank MacLachlan):
The pc_probe code isn't reseting the a20. That is only done in
the bootstrap. The probe code is just trying to reset the keyboard
controller. Alas, the original code uses general purpose routines for
issuing the commands. These general purpose routines read the keyboard
controller and return the value.  According to Bruce this code does not
even touch the A20, so I'm not so sure this is true anymore, rwgrimes.

PCPROBE INFO (Bruce Evans):
On some systems, the boot process hangs after the copyright notice
is displayed.  This was caused by not waiting for commands to complete and
has been fixed by polling the controller until it is finished, or
a timeout count is reached (in which case an error message is printed).
Also, the color/mono test was beeing optimized out due to not
declaring certain values as volatile.  The attributes for the mono mode
were corrected now that the color/mono test works correctly, they were
were displaying black on black under certain conditions.  Removed
the control-alt-delete reboot code, this is a very bad thing to
do to unix anyway!!

COMCONSOLE INFO (Chris Demetriou):
There where several bad typos and other stuff in the file.
It was originally part of my comconsole package.  Also the moving
of pg() is done here, this routine has been moved to a more general
place (i386/i386/cons.c).  Fixed the tab problem in ddb/db_output.c.

[ Editor's note: ]:
This is now an actually fix, not a workaround!

AUTHOR: Scotty ? & Frank MacLachlan (fpm@crash.cts.com) - A20 fix
AUTHOR: Bruce Evans - PCPROBE fixes
AUTHOR: Chris G. Demetriou (cgd@berkeley.edu) - COMCONSOLE
386BSD-Patchkit: patch00083

usr/src/sys.386bsd/ddb/db_output.c
usr/src/sys.386bsd/i386/i386/cons.c
usr/src/sys.386bsd/i386/isa/pccons.c

index 5b1a986..fc8fca7 100644 (file)
  * 
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  * 
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
+ *
+ * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+ * --------------------         -----   ----------------------
+ * CURRENT PATCH LEVEL:         4       00083
+ * --------------------         -----   ----------------------
+ *
+ * 14 Mar 93   Chris G. Demetriou      Fixed so that tab is not output,
+ *                                     use spaces instead.
  */
 /*
  * HISTORY
  */
 /*
  * HISTORY
@@ -87,8 +95,10 @@ db_force_whitespace()
        while (last_print < db_output_position) {
            next_tab = NEXT_TAB(last_print);
            if (next_tab <= db_output_position) {
        while (last_print < db_output_position) {
            next_tab = NEXT_TAB(last_print);
            if (next_tab <= db_output_position) {
-               cnputc('\t');
-               last_print = next_tab;
+               while (last_print < next_tab) { /* DON'T send a tab!!! */
+                       cnputc(' ');
+                       last_print++;
+               }
            }
            else {
                cnputc(' ');
            }
            else {
                cnputc(' ');
index f28678c..6189d72 100644 (file)
  *
  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
  * --------------------         -----   ----------------------
  *
  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
  * --------------------         -----   ----------------------
- * CURRENT PATCH LEVEL:         1       00028
+ * CURRENT PATCH LEVEL:         1       00083
  * --------------------         -----   ----------------------
  *
  * --------------------         -----   ----------------------
  *
- * 16 Aug 92   Pace Willisson  /dev/console redirect (xterm -C, etc.)
+ * 16 Aug 92   Pace Willisson          /dev/console redirect (xterm -C, etc.)
+ * 14 Mar 93   Chris G. Demetriou      Moved pg() here from isa/pccons.c
  */
 
 
  */
 
 
@@ -202,3 +203,11 @@ cnputc(c)
                        (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
        }
 }
                        (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
        }
 }
+
+pg(p,q,r,s,t,u,v,w,x,y,z) char *p; {
+       printf(p,q,r,s,t,u,v,w,x,y,z);
+       printf("\n>");
+       return(cngetc());
+}
+
+
index 11c0896..062941f 100644 (file)
  *
  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
  * --------------------         -----   ----------------------
  *
  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
  * --------------------         -----   ----------------------
- * CURRENT PATCH LEVEL:         4       00078
+ * CURRENT PATCH LEVEL:         5       00083
  * --------------------         -----   ----------------------
  *
  * 15 Aug 92   Pace Willisson          Patches for X server
  * --------------------         -----   ----------------------
  *
  * 15 Aug 92   Pace Willisson          Patches for X server
- * 21 Aug 92    Frank Maclachlan        Fixed back-scroll system crash
- * 28 Nov 1992 Terry Lee               Fixed LED's in X mode
- * 09 Feb 1993 Rich Murphey            Added 'BELL' mode in X
+ * 21 Aug 92   Frank Maclachlan        Fixed back-scroll system crash
+ * 28 Nov 92   Terry Lee               Fixed LED's in X mode
+ * 09 Feb 93   Rich Murphey            Added 'BELL' mode in X
+ * 14 Mar 93   Bruce Evans             Added keyboard timeout in pcprobe
+ *                                     Fixed color/mono test and mono
+ *                                     kernel color.  Added check for
+ *                                     minor. 
+ * 14 Mar 93   Chris G. Demetriou      Moved pg() to i386/cons.c, code
+ *                                     cleanup, removed ctl-alt-del.
  */
 static char rcsid[] = "$Header: /usr/bill/working/sys/i386/isa/RCS/pccons.c,v 1.2 92/01/21 14:35:28 william Exp $";
 
  */
 static char rcsid[] = "$Header: /usr/bill/working/sys/i386/isa/RCS/pccons.c,v 1.2 92/01/21 14:35:28 william Exp $";
 
@@ -162,15 +168,50 @@ extern pcopen(dev_t, int, int, struct proc *);
        } \
 }
 
        } \
 }
 
+/*
+ * Pass command to keyboard controller (8042)
+ */
+static int kbc_8042cmd(val)
+int val;
+{
+       unsigned timeo;
+
+       timeo = 100000;         /* > 100 msec */
+       while (inb(KBSTATP) & KBS_IBF)
+               if (--timeo == 0)
+                       return (-1);
+       outb(KBCMDP, val);
+       return (0);
+}
+
 /*
  * Pass command to keyboard itself
  */
 /*
  * Pass command to keyboard itself
  */
-unsigned kbd_cmd(val) {
-       
-       while (inb(KBSTATP)&KBS_IBF);
-       if (val) outb(KBOUTP, val);
-       while (inb(KBSTATP)&KBS_IBF);
-       return (inb(KBDATAP));
+int kbd_cmd(val)
+int val;
+{
+       unsigned timeo;
+
+       timeo = 100000;         /* > 100 msec */
+       while (inb(KBSTATP) & KBS_IBF)
+               if (--timeo == 0)
+                       return (-1);
+       outb(KBOUTP, val);
+       return (0);
+}
+
+/*
+ * Read response from keyboard
+ */
+int kbd_response()
+{
+       unsigned timeo;
+
+       timeo = 500000;         /* > 500 msec (KBR_RSTDONE requires 87) */
+       while (!(inb(KBSTATP) & KBS_DIB))
+               if (--timeo == 0)
+                       return (-1);
+       return ((u_char) inb(KBDATAP));
 }
 
 /*
 }
 
 /*
@@ -179,26 +220,59 @@ unsigned kbd_cmd(val) {
 pcprobe(dev)
 struct isa_device *dev;
 {
 pcprobe(dev)
 struct isa_device *dev;
 {
-       u_char c;
        int again = 0;
        int again = 0;
+       int response;
+
+       /* Enable interrupts and keyboard, etc. */
+       if (kbc_8042cmd(K_LDCMDBYTE) != 0)
+               printf("Timeout specifying load of keyboard command byte\n");
+       if (kbd_cmd(CMDBYTE) != 0)
+               printf("Timeout writing keyboard command byte\n");
+       /*
+        * Discard any stale keyboard activity.  The 0.1 boot code isn't
+        * very careful and sometimes leaves a KBR_RESEND.
+        */
+       while (inb(KBSTATP) & KBS_DIB)
+               kbd_response();
+
+       /* Start keyboard reset */
+       if (kbd_cmd(KBC_RESET) != 0)
+               printf("Timeout for keyboard reset command\n");
+
+       /* Wait for the first response to reset and handle retries */
+       while ((response = kbd_response()) != KBR_ACK) {
+               if (response < 0) {
+                       printf("Timeout for keyboard reset ack byte #1\n");
+                       response = KBR_RESEND;
+               }
+               if (response == KBR_RESEND) {
+                       if (!again) {
+                               printf("KEYBOARD disconnected: RECONNECT\n");
+                               again = 1;
+                       }
+                       if (kbd_cmd(KBC_RESET) != 0)
+                               printf("Timeout for keyboard reset command\n");
+               }
+               /*
+                * Other responses are harmless.  They may occur for new
+                * keystrokes.
+                */
+       }
 
 
-       /* Enable interrupts and keyboard controller */
-       kbc_8042cmd(K_LDCMDBYTE);
-       outb(KBOUTP, CMDBYTE);
-
-       /* Start keyboard stuff RESET */
-       kbd_cmd(KBC_RESET);
-       while((c = inb(KBDATAP)) != KBR_ACK) {
-               if ((c == KBR_RESEND) ||  (c == KBR_OVERRUN)) {
-                       if(!again)printf("KEYBOARD disconnected: RECONNECT \n");
-                       kbd_cmd(KBC_RESET);
-                       again = 1;
+       /* Wait for the second response to reset */
+       while ((response = kbd_response()) != KBR_RSTDONE) {
+               if (response < 0) {
+                       printf("Timeout for keyboard reset ack byte #2\n");
+                       /*
+                        * If KBR_RSTDONE never arrives, the loop will
+                        * finish here unless the keyboard babbles or
+                        * KBS_DIB gets stuck.
+                        */
+                       break;
                }
        }
 
                }
        }
 
-       /* pick up keyboard reset return code */
-       while((c = inb(KBDATAP)) != KBR_RSTDONE);
-       return 1;
+       return (1);
 }
 
 pcattach(dev)
 }
 
 pcattach(dev)
@@ -225,6 +299,8 @@ pcopen(dev, flag, mode, p)
 {
        register struct tty *tp;
 
 {
        register struct tty *tp;
 
+       if (minor(dev) != 0)
+               return (ENXIO);
        tp = &pccons;
        tp->t_oproc = pcstart;
        tp->t_param = pcparam;
        tp = &pccons;
        tp->t_oproc = pcstart;
        tp->t_param = pcparam;
@@ -578,7 +654,8 @@ u_char ka;
 
        if (crtat == 0)
        {
 
        if (crtat == 0)
        {
-               u_short *cp = Crtat + (CGA_BUF-MONO_BUF)/CHR, was;
+               u_short volatile *cp = Crtat + (CGA_BUF-MONO_BUF)/CHR;
+               u_short was;
                unsigned cursorat;
 
                /*
                unsigned cursorat;
 
                /*
@@ -611,7 +688,7 @@ u_char ka;
                vs.bg_at = BG_BLACK;
 
                if (vs.color == 0) {
                vs.bg_at = BG_BLACK;
 
                if (vs.color == 0) {
-                       vs.kern_fg_at = FG_INTENSE;
+                       vs.kern_fg_at = FG_UNDERLINE;
                        vs.so_at = FG_BLACK | BG_LIGHTGREY;
                } else {
                        vs.kern_fg_at = FG_LIGHTGREY;
                        vs.so_at = FG_BLACK | BG_LIGHTGREY;
                } else {
                        vs.kern_fg_at = FG_LIGHTGREY;
@@ -860,7 +937,7 @@ u_char ka;
        }
        if (sc && crtat >= Crtat+vs.ncol*vs.nrow) { /* scroll check */
                if (openf) do (void)sgetc(1); while (scroll);
        }
        if (sc && crtat >= Crtat+vs.ncol*vs.nrow) { /* scroll check */
                if (openf) do (void)sgetc(1); while (scroll);
-               bcopyb(Crtat+vs.ncol, Crtat, vs.ncol*(vs.nrow-1)*CHR);
+               bcopy(Crtat+vs.ncol, Crtat, vs.ncol*(vs.nrow-1)*CHR);
                fillw ((at << 8) + ' ', Crtat + vs.ncol*(vs.nrow-1),
                        vs.ncol);
                crtat -= vs.ncol;
                fillw ((at << 8) + ' ', Crtat + vs.ncol*(vs.nrow-1),
                        vs.ncol);
                crtat -= vs.ncol;
@@ -870,8 +947,8 @@ u_char ka;
 }
 
 
 }
 
 
-unsigned       __debug = 0; /*0xffe */;
-static char scantokey[] {
+unsigned       __debug = 0; /*0xffe */
+static char scantokey[] {
 0,
 120,   /* F9 */
 0,
 0,
 120,   /* F9 */
 0,
@@ -969,7 +1046,7 @@ static char scantokey[] {
 0,
 0,
 0,
 0,
 0,
 0,
-45,    ?* na*/
+45,    /* na*/
 0,
 0,
 0,
 0,
 0,
 0,
@@ -1005,7 +1082,7 @@ static char scantokey[] {
 0,
 118,   /* F7 */
 };
 0,
 118,   /* F7 */
 };
-static char extscantokey[] {
+static char extscantokey[] {
 0,
 120,   /* F9 */
 0,
 0,
 120,   /* F9 */
 0,
@@ -1103,7 +1180,7 @@ static char extscantokey[] {
 0,
 0,
 0,
 0,
 0,
 0,
-45,    ?* na*/
+45,    /* na*/
 0,
 0,
 0,
 0,
 0,
 0,
@@ -1295,9 +1372,25 @@ static Scan_def  scan_codes[] =
 
 update_led()
 {
 
 update_led()
 {
-       kbd_cmd(KBC_STSIND);    /* LED Command */
-       outb(KBOUTP,scroll | 2*num | 4*caps);
-       /*kbd_cmd(scroll | 2*num | 4*caps);*/
+       int response;
+
+       if (kbd_cmd(KBC_STSIND) != 0)
+               printf("Timeout for keyboard LED command\n");
+       else if (kbd_cmd(scroll | (num << 1) | (caps << 2)) != 0)
+               printf("Timeout for keyboard LED data\n");
+#if 0
+       else if ((response = kbd_response()) < 0)
+               printf("Timeout for keyboard LED ack\n");
+       else if (response != KBR_ACK)
+               printf("Unexpected keyboard LED ack %d\n", response);
+#else
+       /*
+        * Skip waiting for and checking the response.  The waiting
+        * would be too long (about 3 msec) and the checking might eat
+        * fresh keystrokes.  The waiting should be done using timeout()
+        * and the checking should be done in the interrupt handler.
+        */
+#endif
 }
 
 /*
 }
 
 /*
@@ -1371,19 +1464,15 @@ loop:
 #endif /* !XSERVER*/
        }
 
 #endif /* !XSERVER*/
        }
 
-       /*
-        *   Check for cntl-alt-del
-        */
-       if ((dt == 83) && ctrl_down && alt_down)
-               cpu_reset();
-
 #include "ddb.h"
 #if NDDB > 0
        /*
         *   Check for cntl-alt-esc
         */
 #include "ddb.h"
 #if NDDB > 0
        /*
         *   Check for cntl-alt-esc
         */
-       if ((dt == 1) && ctrl_down && alt_down)
+       if ((dt == 1) && ctrl_down && alt_down) {
                Debugger();
                Debugger();
+               dt |= 0x80;     /* discard esc (ddb discarded ctrl-alt) */
+       }
 #endif
 
        /*
 #endif
 
        /*
@@ -1517,12 +1606,6 @@ loop:
 #endif /* !XSERVER*/
 }
 
 #endif /* !XSERVER*/
 }
 
-pg(p,q,r,s,t,u,v,w,x,y,z) char *p; {
-       printf(p,q,r,s,t,u,v,w,x,y,z);
-       printf("\n");
-       return(getchar());
-}
-
 /* special characters */
 #define bs     8
 #define lf     10      
 /* special characters */
 #define bs     8
 #define lf     10