Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZDzVt-0007f3-RI for mharc-grub-devel@gnu.org; Sat, 11 Jul 2015 14:28:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDzVr-0007cF-0y for grub-devel@gnu.org; Sat, 11 Jul 2015 14:28:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZDzVn-0008De-EU for grub-devel@gnu.org; Sat, 11 Jul 2015 14:28:34 -0400 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:36991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDzVn-0008DI-4E for grub-devel@gnu.org; Sat, 11 Jul 2015 14:28:31 -0400 Received: by wicmz13 with SMTP id mz13so34050373wic.0 for ; Sat, 11 Jul 2015 11:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=JT0wC8QDYxhhJ31zpWe14kNAetNMCqczVumv3GceEr0=; b=ZhVrB1wO8330btZUDsmICdIKAXgNg+KrnGzp3Q9eg2hFlem1J2lz2vDN6PPJMBH2nJ NbQ4ZDctyrR5uOgN9F6bTvH749axsslX0xeZkuoIkOOv+xVcqHpkHEdbHXvza8EICWp/ f/5EAQEsJF0x5XfzcNZvTkwUbXFu8UDo2YCN+mgNhA8rkMlh8stSaOCRMPsPZeK3JG+r ekyYpthL3zbMNaP3MdLkff6uLKlTK8n+0tOf5HBSsDyF5NId3FPk1RtU2pLD7cIlVqAH ooBRd9qxDEDJROiZrMGN8EwSB2Ec1wuy+4bf4TfHUy/zFHkWgzIdwthd4b8ESFbUkjvf QqpQ== X-Received: by 10.180.76.193 with SMTP id m1mr8315058wiw.11.1436639310524; Sat, 11 Jul 2015 11:28:30 -0700 (PDT) Received: from w970suw1.lan ([91.176.149.207]) by smtp.gmail.com with ESMTPSA id lq9sm19152863wjb.35.2015.07.11.11.28.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Jul 2015 11:28:29 -0700 (PDT) From: Luc Van Rompaey To: The development of GNU GRUB Subject: [PATCH 3/4] implement the nuconsole input terminal Date: Sat, 11 Jul 2015 20:28:23 +0200 Message-Id: <1436639304-5365-4-git-send-email-luc.vanrompaey@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436639304-5365-1-git-send-email-luc.vanrompaey@gmail.com> References: <1436639304-5365-1-git-send-email-luc.vanrompaey@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::234 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jul 2015 18:28:36 -0000 The nuconsole input terminal works in conjunction with the nusetkey module to support changing the keyboard keymap. --- grub-core/Makefile.core.def | 6 ++ grub-core/term/i386/pc/nuconsole.c | 111 +++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 grub-core/term/i386/pc/nuconsole.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 6f9e1f0..31d43f2 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -2319,3 +2319,9 @@ module = { i386_pc = commands/i386/pc/nusetkey.c; enable = i386_pc; }; + +module = { + name = nuconsole; + i386_pc = term/i386/pc/nuconsole.c; + enable = i386_pc; +}; diff --git a/grub-core/term/i386/pc/nuconsole.c b/grub-core/term/i386/pc/nuconsole.c new file mode 100644 index 0000000..ede33ea --- /dev/null +++ b/grub-core/term/i386/pc/nuconsole.c @@ -0,0 +1,111 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2003,2005,2007,2008,2009 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 . + */ + +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +/* + * grub_nuconsole_getkey - If a character is pending, then return it. + * Otherwise, return GRUB_TERM_NO_KEY (i.e., -1). + * + * BIOS call 'INT 16H Function 11H' checks whether + * a character is pending, supporting so-called + * 'extended' key codes. + * Call this function with: + * - %ah = 0x11. + * When the function returns: + * - If a character is pending, then: + * - Zero flag is clear. + * - %ah = keyboard scan code. + * - %al = ASCII character. + * - If there is no character pending, then: + * - Zero flag is set. + * + * BIOS call 'INT 16H Function 10H' reads a + * character from the keyboard, again supporting + * 'extended' key codes. + * Call this function with: + * - %ah = 0x10. + * When the function returns: + * - %ah = keyboard scan code. + * - %al = ASCII character. + */ +static int +grub_nuconsole_getkey (struct grub_term_input *term __attribute__ ((unused))) +{ + struct grub_bios_int_registers regs; + + /* + * Check if a character is pending. + */ + regs.eax = 0x1100; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x16, ®s); + if (regs.flags & GRUB_CPU_INT_FLAGS_ZERO) + return GRUB_TERM_NO_KEY; + + /* + * Read the character that is pending. + */ + regs.eax = 0x1000; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x16, ®s); + + /* + * Process the key code that was read from the keyboard, and return the + * corresponding GRUB key code. + */ + return grub_nusetkey_xlat (regs.eax); +} + +static const struct grub_machine_bios_data_area *bios_data_area = + (struct grub_machine_bios_data_area *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR; + +/* + * grub_nuconsole_getkeystatus - Return the Shift, Ctrl, and Alt modifier + * states. + */ +static int +grub_nuconsole_getkeystatus (struct grub_term_input *term __attribute__ ((unused))) +{ + /* conveniently GRUB keystatus is modelled after BIOS one. */ + return bios_data_area->keyboard_flag_lower & ~0x80; +} + +static struct grub_term_input grub_nuconsole_term_input = + { + .name = "nuconsole", + .getkey = grub_nuconsole_getkey, + .getkeystatus = grub_nuconsole_getkeystatus + }; + +GRUB_MOD_INIT(nuconsole) +{ + grub_term_register_input ("nuconsole", &grub_nuconsole_term_input); +} + +GRUB_MOD_FINI(nuconsole) +{ + grub_term_unregister_input (&grub_nuconsole_term_input); +} -- 2.1.4