From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JF8d8-0003kf-UZ for mharc-grub-devel@gnu.org; Wed, 16 Jan 2008 08:48:34 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JF8d7-0003iM-Jt for grub-devel@gnu.org; Wed, 16 Jan 2008 08:48:33 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JF8d3-0003ar-Pj for grub-devel@gnu.org; Wed, 16 Jan 2008 08:48:33 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JF8d3-0003ai-Mg for grub-devel@gnu.org; Wed, 16 Jan 2008 08:48:29 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JF8d3-00010C-5b for grub-devel@gnu.org; Wed, 16 Jan 2008 08:48:29 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JF8cx-00074C-J7 for grub-devel@gnu.org; Wed, 16 Jan 2008 14:48:28 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1JF8bJ-0006wV-HF for grub-devel@gnu.org; Wed, 16 Jan 2008 14:46:41 +0100 Date: Wed, 16 Jan 2008 14:46:41 +0100 From: Robert Millan To: The development of GRUB 2 Message-ID: <20080116134641.GA26595@thorin> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="T4sUOijqQbZv57TR" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jan 2008 13:48:34 -0000 --T4sUOijqQbZv57TR Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit See attached patch. I don't like the way I had to hook initialisation in console.c, but solving this properly would require some redesign (converting at_keyboard to a module, and adding abstraction to handle input and output separately, etc). But for now I think it's a valid compromise. I'll wait a bit and see if nobody objects to it before committing. -- Robert Millan I know my rights; I want my phone call! What use is a phone call… if you are unable to speak? (as seen on /.) --T4sUOijqQbZv57TR Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="atkeyboard.diff" * include/grub/i386/linuxbios/console.h: Add header protection. (grub_keyboard_controller_init): New function prototype. * term/i386/pc/at_keyboard.c (KEYBOARD_COMMAND_ISREADY): New macro. (KEYBOARD_COMMAND_READ): Likewise. (KEYBOARD_COMMAND_WRITE): Likewise. (grub_keyboard_controller_write): New function. (grub_keyboard_controller_read): Likewise. (grub_keyboard_controller_init): Likewise. * term/i386/pc/console.c: Include `'. (grub_console_init): On CoreBoot/LinuxBIOS, call grub_keyboard_controller_init(). diff -ur ../grub2/include/grub/i386/linuxbios/console.h ./include/grub/i386/linuxbios/console.h --- ../grub2/include/grub/i386/linuxbios/console.h 2007-10-31 23:35:12.000000000 +0100 +++ ./include/grub/i386/linuxbios/console.h 2008-01-16 14:27:39.000000000 +0100 @@ -1 +1,25 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef _GRUB_CONSOLE_MACHINE_LB_HEADER +#define _GRUB_CONSOLE_MACHINE_LB_HEADER 1 #include + +void grub_keyboard_controller_init (void); + +#endif /* ! _GRUB_CONSOLE_MACHINE_LB_HEADER */ diff -ur ../grub2/term/i386/pc/at_keyboard.c ./term/i386/pc/at_keyboard.c --- ../grub2/term/i386/pc/at_keyboard.c 2008-01-03 23:43:46.000000000 +0100 +++ ./term/i386/pc/at_keyboard.c 2008-01-16 14:34:41.000000000 +0100 @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,11 @@ #define KEYBOARD_REG_DATA 0x60 #define KEYBOARD_REG_STATUS 0x64 +/* Used for sending commands to the controller. */ +#define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02) +#define KEYBOARD_COMMAND_READ 0x20 +#define KEYBOARD_COMMAND_WRITE 0x60 + #define KEYBOARD_ISMAKE(x) !((x) & 0x80) #define KEYBOARD_ISREADY(x) (((x) & 0x01) == 0) #define KEYBOARD_SCANCODE(x) ((x) & 0x7f) @@ -73,6 +78,28 @@ '2', '3', }; +static void +grub_keyboard_controller_write (grub_uint8_t c) +{ + while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS))); + grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS); + grub_outb (c, KEYBOARD_REG_DATA); +} + +static grub_uint8_t +grub_keyboard_controller_read (void) +{ + while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS))); + grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS); + return grub_inb (KEYBOARD_REG_DATA); +} + +void +grub_keyboard_controller_init (void) +{ + grub_keyboard_controller_write (grub_keyboard_controller_read () | 0x40); +} + /* FIXME: This should become an interrupt service routine. For now it's just used to catch events from control keys. */ static void diff -ur ../grub2/term/i386/pc/console.c ./term/i386/pc/console.c --- ../grub2/term/i386/pc/console.c 2007-12-25 12:10:46.000000000 +0100 +++ ./term/i386/pc/console.c 2008-01-16 14:28:02.000000000 +0100 @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ * along with GRUB. If not, see . */ +#include #include #include #include @@ -148,6 +149,10 @@ void grub_console_init (void) { +#ifdef GRUB_MACHINE_LINUXBIOS + grub_keyboard_controller_init (); +#endif + grub_term_register (&grub_console_term); grub_term_set_current (&grub_console_term); } --T4sUOijqQbZv57TR--