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 <http://www.gnu.org/licenses/>. + */ + +#include <grub/dl.h> +#include <grub/machine/memory.h> +#include <grub/term.h> +#include <grub/types.h> +#include <grub/machine/int.h> +#include <grub/machine/nusetkey.h> + +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 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel