From owner-freebsd-hackers Fri Apr 25 02:49:17 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id CAA05309 for hackers-outgoing; Fri, 25 Apr 1997 02:49:17 -0700 (PDT) Received: from nasu.utsunomiya-u.ac.jp (nasu.utsunomiya-u.ac.jp [160.12.128.3]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id CAA05294 for ; Fri, 25 Apr 1997 02:48:55 -0700 (PDT) Received: from outmail.utsunomiya-u.ac.jp (outmail.utsunomiya-u.ac.jp [160.12.196.3]) by nasu.utsunomiya-u.ac.jp (8.8.4+2.7Wbeta4/3.5Wpl3) with ESMTP id SAA23164 for ; Fri, 25 Apr 1997 18:39:25 +0900 (JST) Received: from zodiac.mech.utsunomiya-u.ac.jp (lB6C0j5m7MSN8lvYytk2ZELiFKgMWf/0@zodiac.mech.utsunomiya-u.ac.jp [160.12.33.1]) by outmail.utsunomiya-u.ac.jp (8.8.4+2.7Wbeta4/3.5Wpl3) with ESMTP id SAA12984 for ; Fri, 25 Apr 1997 18:39:25 +0900 (JST) Received: from zodiac.mech.utsunomiya-u.ac.jp (zenith.mech.utsunomiya-u.ac.jp [160.12.33.60]) by zodiac.mech.utsunomiya-u.ac.jp (8.7.6+2.6Wbeta7/3.4W/zodiac-May96) with ESMTP id SAA20609; Fri, 25 Apr 1997 18:44:11 +0900 (JST) Message-Id: <199704250944.SAA20609@zodiac.mech.utsunomiya-u.ac.jp> To: hackers@freebsd.org cc: yokota@zodiac.mech.utsunomiya-u.ac.jp Subject: alternative probe_keyboard.c (was: Re: i386/3124: BOOT_PROBE_KEYBOARD hangs system in bootblocks) Date: Fri, 25 Apr 1997 18:44:09 +0900 From: Kazutaka YOKOTA Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Regarding the PR (i386/3124) that the BOOT_PROBE_KEYBOARD option fails to determine the presence of the keyboard and hangs the system, I just received the following report from the originator: nsayer>> I sent you two patches: the alternative probe_keyboard.c and the patch nsayer>> for syscons.c. I wonder how well/badly they performed in your system. nsayer>> I would be very interested to know. nsayer> nsayer>> I don't care much about the syscons.c patch. But, if the alternative nsayer>> probe_keyboard.c is found to work better than the original, I would nsayer>> ask other FreeBSD developers to consider to commit it to the source nsayer>> tree. nsayer> nsayer>> Thank you for your cooperation. nsayer> nsayer>> Kazu [...] nsayer>I just applied the boot block patch and it completely fixed the problem. nsayer>I did not apply the syscons patch. It did not seem necessary in my nsayer>case. The alternative sys/i386/boot/biosboot/probe_keyboard.c code I sent to him worked in his system. Would anybody kindly review and/or test the code too? If it is found to work in more systems than the existing code did, I would like to have it committed to the source tree. But, this is a part of the boot block. I need thorough testing, don't I? Replace the file with the following code, define BOOT_PROBE_KEYBOARD=true in /etc/make.conf, and rebuild the boot block. Keep a backup copy of the existing boot block, the `boot' and `fixit' floppies handy when you test the code. If my code doesn't work in your system, you are left with unbootable system; that's too bad... Kazu ----8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<--- /*- * $Id:$ */ #ifdef PROBE_KEYBOARD #include #include #include #include #include "boot.h" #define PROBE_MAXRETRY 5 #define PROBE_MAXWAIT 500 #define IO_DUMMY 0x84 /* 7 microsec delay necessary for some keyboard controllers */ static void delay7(void) { /* * I know this is broken, but no timer is avaiable yet at this stage... * See also comments in `delay1ms()' in `io.c'. */ inb(IO_DUMMY); inb(IO_DUMMY); inb(IO_DUMMY); inb(IO_DUMMY); inb(IO_DUMMY); inb(IO_DUMMY); } /* * Perform a simple test on the keyboard; issue the ECHO command and see * if the right answer is returned. We don't do anything as drastic as * full keyboard reset; it will be too troublesome and take too much time. */ int probe_keyboard(void) { int retry = PROBE_MAXRETRY; int wait; int i; while (--retry >= 0) { /* flush any noise */ while (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) { delay7(); inb(IO_KBD + KBD_DATA_PORT); delay1ms(); } /* wait until the controller can accept a command */ for (wait = PROBE_MAXWAIT; wait > 0; --wait) { if (((i = inb(IO_KBD + KBD_STATUS_PORT)) & (KBDS_INPUT_BUFFER_FULL | KBDS_ANY_BUFFER_FULL)) == 0) break; if (i & KBDS_ANY_BUFFER_FULL) { delay7(); inb(IO_KBD + KBD_DATA_PORT); } delay1ms(); } if (wait <= 0) continue; /* ECHO command */ outb(IO_KBD + KBD_DATA_PORT, KBDC_ECHO); /* wait for a response */ for (wait = PROBE_MAXWAIT; wait > 0; --wait) { if (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) break; delay1ms(); } if (wait <= 0) continue; delay7(); i = inb(IO_KBD + KBD_DATA_PORT); #ifdef PROBE_KBD_BEBUG printf("probe_keyboard: got 0x%x.\n", i); #endif if (i == KBD_ECHO) { /* got the right answer */ #ifdef PROBE_KBD_BEBUG printf("probe_keyboard: succeeded.\n"); #endif return (0); } } #ifdef PROBE_KBD_BEBUG printf("probe_keyboard: failed.\n"); #endif return (1); } #endif /* PROBE_KEYBOARD */