All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map
@ 2015-07-11 18:28 Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 1/4] update URL to bios_data_area.html on comment line Luc Van Rompaey
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-11 18:28 UTC (permalink / raw
  To: The development of GNU GRUB

Legacy GRUB had a 'setkey' command to remap the keyboard keys.
GRUB2 no longer has this command.  Instead, it provides an 'at_keyboard'
input terminal module, which can load a GRUB keymap.
Unfortunately, at least on the i386-pc platform, 'at_keyboard' is problematic,
in that it easily causes hangups.

For now, I'm unsure what needs to be done to fix 'at_keyboard', which is why
I decided to look for a different solution.  Whether I can fix the 'at_keyboard'
input terminal, and in what time frame, remains to be seen.

This patch set reintroduces a 'setkey' command, to support changing the keyboard
map, similarly to what was possible under Legacy GRUB.

The first patch just makes a simple edit to a comment line in the 'memory.h'
header file.  It updates the URL for the 'bios_data_area.html' web page, which
contains helpful information about BIOS, and specifically, the keyboard
interface.

The second patch implements the 'nusetkey' module, which provides the 'setkey'
command. In addition, it provides a 'setnumpad' command, to change the
behavior of the numeric keypad.

The third patch implements the 'nuconsole' input terminal, which works in
conjunction with the 'nusetkey' module to support keyboard map changes.

Finally, the fourth patch provides updates to the GRUB manual.
It documents the 'keymap' command (which loads a keyboard map for use by
the 'at_keyboard' or 'usb_keyboard' input terminals), plus the 'setkey' and
'setnumpad' commands implemented by the 'nusetkey' module.

Luc Van Rompaey (4):
  update URL to bios_data_area.html on comment line
  implement the nusetkey module
  implement the nuconsole input terminal
  add documentation for keymap, setkey, and setnumpad commands

 docs/grub.texi                        | 150 +++++++++
 grub-core/Makefile.core.def           |  12 +
 grub-core/commands/i386/pc/nusetkey.c | 583 ++++++++++++++++++++++++++++++++++
 grub-core/term/i386/pc/nuconsole.c    | 111 +++++++
 include/grub/i386/pc/memory.h         |   2 +-
 include/grub/i386/pc/nusetkey.h       |  25 ++
 6 files changed, 882 insertions(+), 1 deletion(-)
 create mode 100644 grub-core/commands/i386/pc/nusetkey.c
 create mode 100644 grub-core/term/i386/pc/nuconsole.c
 create mode 100644 include/grub/i386/pc/nusetkey.h

-- 
2.1.4



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] update URL to bios_data_area.html on comment line
  2015-07-11 18:28 [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Luc Van Rompaey
@ 2015-07-11 18:28 ` Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 2/4] implement the nusetkey module Luc Van Rompaey
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-11 18:28 UTC (permalink / raw
  To: The development of GNU GRUB

The URL to the bios_data_area.html web page, as given on a comment line
in the i386/pc/memory.h header file,  is dead.  Replace it with the new
location of the page.
---
 include/grub/i386/pc/memory.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/grub/i386/pc/memory.h b/include/grub/i386/pc/memory.h
index d0c5c20..4ca947d 100644
--- a/include/grub/i386/pc/memory.h
+++ b/include/grub/i386/pc/memory.h
@@ -45,7 +45,7 @@
 
 #ifndef ASM_FILE
 
-/* See http://heim.ifi.uio.no/~stanisls/helppc/bios_data_area.html for a
+/* See http://stanislavs.org/helppc/bios_data_area.html for a
    description of the BIOS Data Area layout.  */
 struct grub_machine_bios_data_area
 {
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] implement the nusetkey module
  2015-07-11 18:28 [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 1/4] update URL to bios_data_area.html on comment line Luc Van Rompaey
@ 2015-07-11 18:28 ` Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 3/4] implement the nuconsole input terminal Luc Van Rompaey
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-11 18:28 UTC (permalink / raw
  To: The development of GNU GRUB

The nusetkey module implements the setkey command,  which  will  change
the keyboard keymap,  in much the same way as the setkey command did in
GRUB legacy.
Restrictions:  This version of the setkey command  does not support the
modifier keys  (shift, control, alt).  In addition,  the keymap changes
will not become active until the terminal_input is set to nuconsole.
The module also implements the setnumpad command,  which allows you  to
change the behavior of the numeric keypad,  to make it  output  numeric
ASCII characters, irrespective of the numlock and shift key states.
---
 grub-core/Makefile.core.def           |   6 +
 grub-core/commands/i386/pc/nusetkey.c | 583 ++++++++++++++++++++++++++++++++++
 include/grub/i386/pc/nusetkey.h       |  25 ++
 3 files changed, 614 insertions(+)
 create mode 100644 grub-core/commands/i386/pc/nusetkey.c
 create mode 100644 include/grub/i386/pc/nusetkey.h

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index a6101de..6f9e1f0 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -2313,3 +2313,9 @@ module = {
   common = loader/i386/xen_file64.c;
   extra_dist = loader/i386/xen_fileXX.c;
 };
+
+module = {
+  name = nusetkey;
+  i386_pc = commands/i386/pc/nusetkey.c;
+  enable = i386_pc;
+};
diff --git a/grub-core/commands/i386/pc/nusetkey.c b/grub-core/commands/i386/pc/nusetkey.c
new file mode 100644
index 0000000..3a28a39
--- /dev/null
+++ b/grub-core/commands/i386/pc/nusetkey.c
@@ -0,0 +1,583 @@
+/* nusetkey.c - modify nuconsole keyboard map */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2015  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/term.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/machine/nusetkey.h>
+
+#define  GRUB_SETKEY_KEYMAP_TABLE_SIZE   128
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static const struct grub_arg_option options_setkey[] =
+  {
+    /********************************************************************************************************/
+    /*                                                                                                      */
+    /* The 'setkey' command does not provide any specific options.                                          */
+    /* This entry is required, however, to make the '--help' and '--usage' options work.                    */
+    /*                                                                                                      */
+    /********************************************************************************************************/
+    { 0                                                                 ,     /* const char       *longarg  */
+      0                                                                 ,     /* int               shortarg */
+      0                                                                 ,     /* int               flags    */
+      0                                                                 ,     /* const char       *doc      */
+      0                                                                 ,     /* const char       *arg      */
+      0                                                                       /* grub_arg_type_t  type      */
+    }                                                                         /******************************/
+  } ;
+
+static const struct grub_arg_option options_setnumpad[] =
+  {
+    /********************************************************************************************************/
+    /*                                                                                                      */
+    /* The '--force' option.                                                                                */
+    /*                                                                                                      */
+    /********************************************************************************************************/
+    { "force"                                                           ,     /* const char       *longarg  */
+      'f'                                                               ,     /* int               shortarg */
+      0                                                                 ,     /* int               flags    */
+      N_("Force the keys on the numeric keypad "                              /* const char       *doc      */
+         "to emit the numeric characters on their keycaps, "                  /*                            */
+         "irrespective of the NumLock and the Shift key states.")       ,     /*                            */
+      0                                                                 ,     /* const char       *arg      */
+      ARG_TYPE_NONE                                                           /* grub_arg_type_t  type      */
+    } ,                                                                       /******************************/
+    /********************************************************************************************************/
+    /*                                                                                                      */
+    /* The '--noforce' option.                                                                              */
+    /*                                                                                                      */
+    /********************************************************************************************************/
+    { "noforce"                                                         ,     /* const char       *longarg  */
+      'n'                                                               ,     /* int               shortarg */
+      0                                                                 ,     /* int               flags    */
+      N_("(Default) "                                                         /* const char       *doc      */
+         "Restore default behavior of the keys on the numeric keypad, "       /*                            */
+         "which depends on the NumLock and the Shift key states.")      ,     /*                            */
+      0                                                                 ,     /* const char       *arg      */
+      ARG_TYPE_NONE                                                           /* grub_arg_type_t  type      */
+    } ,                                                                       /******************************/
+    /********************************************************************************************************/
+    /*                                                                                                      */
+    /* End of option definitions.                                                                           */
+    /*                                                                                                      */
+    /********************************************************************************************************/
+    { 0                                                                 ,     /* const char       *longarg  */
+      0                                                                 ,     /* int               shortarg */
+      0                                                                 ,     /* int               flags    */
+      0                                                                 ,     /* const char       *doc      */
+      0                                                                 ,     /* const char       *arg      */
+      0                                                                       /* grub_arg_type_t  type      */
+    }                                                                         /******************************/
+  } ;
+
+static const struct grub_setkey_numpad_entry
+  {
+    grub_uint16_t keycode;
+    grub_uint16_t keycode_shifted;
+    int           grubkey;
+    int           grubkey_shifted;
+  }
+    numpad_table[] =
+  {
+    { 0x4f00 , 0x4f31 , 0x0080004f , 0x00000031 } ,   /* Numeric Keypad '1'.     */
+    { 0x5000 , 0x5032 , 0x00800050 , 0x00000032 } ,   /* Numeric Keypad '2'.     */
+    { 0x5100 , 0x5133 , 0x00800051 , 0x00000033 } ,   /* Numeric Keypad '3'.     */
+    { 0x4b00 , 0x4b34 , 0x0080004b , 0x00000034 } ,   /* Numeric Keypad '4'.     */
+    { 0x4c00 , 0x4c35 , 0x0080004c , 0x00000035 } ,   /* Numeric Keypad '5'.     */
+    { 0x4d00 , 0x4d36 , 0x0080004d , 0x00000036 } ,   /* Numeric Keypad '6'.     */
+    { 0x4700 , 0x4737 , 0x00800047 , 0x00000037 } ,   /* Numeric Keypad '7'.     */
+    { 0x4800 , 0x4838 , 0x00800048 , 0x00000038 } ,   /* Numeric Keypad '8'.     */
+    { 0x4900 , 0x4939 , 0x00800049 , 0x00000039 } ,   /* Numeric Keypad '9'.     */
+    { 0x5200 , 0x5230 , 0x00800052 , 0x00000030 } ,   /* Numeric Keypad '0'.     */
+    { 0x5300 , 0x532e , 0x00800053 , 0x0000002e } ,   /* Numeric Keypad '.'.     */
+    { 0xe02f , 0xe02f , 0x0000002f , 0x0000002f } ,   /* Numeric Keypad '/'.     */
+    { 0x372a , 0x372a , 0x0000002a , 0x0000002a } ,   /* Numeric Keypad '*'.     */
+    { 0x4a2d , 0x4a2d , 0x0000002d , 0x0000002d } ,   /* Numeric Keypad '-'.     */
+    { 0x4e2b , 0x4e2b , 0x0000002b , 0x0000002b } ,   /* Numeric Keypad '+'.     */
+    { 0xe00d , 0xe00d , 0x0000000d , 0x0000000d }     /* Numeric Keypad 'Enter'. */
+  } ;
+
+static const struct grub_setkey_keysym_entry
+  {
+    const char    *name;
+    grub_uint16_t keycode;
+  }
+    keysym_table[] =
+  {
+    { "a"            , 0x1e61 } ,
+    { "b"            , 0x3062 } ,
+    { "c"            , 0x2e63 } ,
+    { "d"            , 0x2064 } ,
+    { "e"            , 0x1265 } ,
+    { "f"            , 0x2166 } ,
+    { "g"            , 0x2267 } ,
+    { "h"            , 0x2368 } ,
+    { "i"            , 0x1769 } ,
+    { "j"            , 0x246a } ,
+    { "k"            , 0x256b } ,
+    { "l"            , 0x266c } ,
+    { "m"            , 0x326d } ,
+    { "n"            , 0x316e } ,
+    { "o"            , 0x186f } ,
+    { "p"            , 0x1970 } ,
+    { "q"            , 0x1071 } ,
+    { "r"            , 0x1372 } ,
+    { "s"            , 0x1f73 } ,
+    { "t"            , 0x1474 } ,
+    { "u"            , 0x1675 } ,
+    { "v"            , 0x2f76 } ,
+    { "w"            , 0x1177 } ,
+    { "x"            , 0x2d78 } ,
+    { "y"            , 0x1579 } ,
+    { "z"            , 0x2c7a } ,
+    { "A"            , 0x1e41 } ,
+    { "B"            , 0x3042 } ,
+    { "C"            , 0x2e43 } ,
+    { "D"            , 0x2044 } ,
+    { "E"            , 0x1245 } ,
+    { "F"            , 0x2146 } ,
+    { "G"            , 0x2247 } ,
+    { "H"            , 0x2348 } ,
+    { "I"            , 0x1749 } ,
+    { "J"            , 0x244a } ,
+    { "K"            , 0x254b } ,
+    { "L"            , 0x264c } ,
+    { "M"            , 0x324d } ,
+    { "N"            , 0x314e } ,
+    { "O"            , 0x184f } ,
+    { "P"            , 0x1950 } ,
+    { "Q"            , 0x1051 } ,
+    { "R"            , 0x1352 } ,
+    { "S"            , 0x1f53 } ,
+    { "T"            , 0x1454 } ,
+    { "U"            , 0x1655 } ,
+    { "V"            , 0x2f56 } ,
+    { "W"            , 0x1157 } ,
+    { "X"            , 0x2d58 } ,
+    { "Y"            , 0x1559 } ,
+    { "Z"            , 0x2c5a } ,
+    { "0"            , 0x0b30 } ,
+    { "1"            , 0x0231 } ,
+    { "2"            , 0x0332 } ,
+    { "3"            , 0x0433 } ,
+    { "4"            , 0x0534 } ,
+    { "5"            , 0x0635 } ,
+    { "6"            , 0x0736 } ,
+    { "7"            , 0x0837 } ,
+    { "8"            , 0x0938 } ,
+    { "9"            , 0x0a39 } ,
+    { "ampersand"    , 0x0826 } ,
+    { "asterisk"     , 0x092a } ,
+    { "at"           , 0x0340 } ,
+    { "backslash"    , 0x2b5c } ,
+    { "backslashx"   , 0x565c } ,
+    { "backquote"    , 0x2960 } ,
+    { "backspace"    , 0x0e08 } ,
+    { "bar"          , 0x2b7c } ,
+    { "barx"         , 0x567c } ,
+    { "braceleft"    , 0x1a7b } ,
+    { "braceright"   , 0x1b7d } ,
+    { "bracketleft"  , 0x1a5b } ,
+    { "bracketright" , 0x1b5d } ,
+    { "caret"        , 0x075e } ,
+    { "colon"        , 0x273a } ,
+    { "comma"        , 0x332c } ,
+    { "delete"       , 0x53e0 } ,
+    { "dollar"       , 0x0524 } ,
+    { "doublequote"  , 0x2822 } ,
+    { "enter"        , 0x1c0d } ,
+    { "equal"        , 0x0d3d } ,
+    { "escape"       , 0x011b } ,
+    { "exclam"       , 0x0221 } ,
+    { "greater"      , 0x343e } ,
+    { "less"         , 0x333c } ,
+    { "minus"        , 0x0c2d } ,
+    { "numbersign"   , 0x0423 } ,
+    { "parenleft"    , 0x0a28 } ,
+    { "parenright"   , 0x0b29 } ,
+    { "percent"      , 0x0625 } ,
+    { "period"       , 0x342e } ,
+    { "plus"         , 0x0d2b } ,
+    { "question"     , 0x353f } ,
+    { "quote"        , 0x2827 } ,
+    { "semicolon"    , 0x273b } ,
+    { "slash"        , 0x352f } ,
+    { "space"        , 0x3920 } ,
+    { "tab"          , 0x0f09 } ,
+    { "tilde"        , 0x297e } ,
+    { "underscore"   , 0x0c5f } ,
+    { "F1"           , 0x3b00 } ,
+    { "F2"           , 0x3c00 } ,
+    { "F3"           , 0x3d00 } ,
+    { "F4"           , 0x3e00 } ,
+    { "F5"           , 0x3f00 } ,
+    { "F6"           , 0x4000 } ,
+    { "F7"           , 0x4100 } ,
+    { "F8"           , 0x4200 } ,
+    { "F9"           , 0x4300 } ,
+    { "F10"          , 0x4400 } ,
+    { "F11"          , 0x8500 } ,
+    { "F12"          , 0x8600 }
+  } ;
+
+static const grub_uint16_t bypass_table[] =
+  {
+    0x0e00 | '\b' ,   /* Backspace.       */
+    0x0100 | '\e' ,   /* Escape.          */
+    0x1c00 | '\n' ,   /* Line Feed.       */
+    0x1c00 | '\r' ,   /* Carriage Return. */
+    0x0f00 | '\t'     /* Tab.             */
+  } ;
+
+static int numpad_force = 0;
+
+static struct grub_setkey_keymap_entry
+  {
+    grub_uint16_t keycode_from;
+    grub_uint16_t keycode_to;
+  }
+    keymap_table[GRUB_SETKEY_KEYMAP_TABLE_SIZE];
+
+/*
+ * grubkey_numpad - For a key code  that  corresponds  to  a  key  on  the
+ *                  numeric keypad,  return the  GRUB  key value.  If  the
+ *                  'setnumpad --force'  option is in effect,  then return
+ *                  the printable  ASCII character,  irrespective  of  the
+ *                  NumLock and the Shift key states;  otherwise,  do  not
+ *                  remap the key code.
+ *                  For a  key  code  that  does not belong to the numeric
+ *                  keypad, return 0.
+ */
+static int
+grubkey_numpad (grub_uint16_t key)
+{
+  unsigned int i;
+
+  for (i = 0; i < ARRAY_SIZE (numpad_table); i++)
+    if (key == numpad_table[i].keycode)
+      if (numpad_force)
+        return numpad_table[i].grubkey_shifted;
+      else
+        return numpad_table[i].grubkey;
+    else if (key == numpad_table[i].keycode_shifted)
+      return numpad_table[i].grubkey_shifted;
+  return 0;
+}
+
+/*
+ * grubkey_mapkey - If a mapping entry was set up  for the given key code,
+ *                  then return the remapped key code.
+ *                  Otherwise, return the given key code unchanged.
+ */
+static grub_uint16_t
+grubkey_mapkey (grub_uint16_t key)
+{
+  unsigned int i;
+
+  for (i = 0; i < GRUB_SETKEY_KEYMAP_TABLE_SIZE; i++)
+    if (!keymap_table[i].keycode_from)
+      break;
+    else if (key == keymap_table[i].keycode_from)
+      return keymap_table[i].keycode_to;
+  return (key);
+}
+
+/*
+ * grubkey_bypass - For a key code  that  produces  a  'well-known'  ASCII
+ *                  control character (cfr. 'bypass_table', above), return
+ *                  the ASCII character value.
+ *                  For any other key code, return 0.
+ */
+static int
+grubkey_bypass (grub_uint16_t key)
+{
+  unsigned int i;
+
+  for (i = 0; i < ARRAY_SIZE (bypass_table); i++)
+    if (key == bypass_table[i])
+      return key & 0xff;
+  return 0;
+}
+
+/*
+ * grub_nusetkey_xlat - Convert a key code to  a  GRUB  key  value,  while
+ *                      taking  into account any key mapping entries  that
+ *                      were requested by the 'setkey' and the 'setnumpad'
+ *                      commands.
+ *                      If  the  key  code  corresponds  to  a key  on the
+ *                      numeric keypad, then:
+ *                         -  If  the  'setnumpad --force'  option  is  in
+ *                            effect,  then  return  the  printable  ASCII
+ *                            character,  irrespective of the NumLock  and
+ *                            the Shift key states.
+ *                         -  Otherwise, return either the printable ASCII
+ *                            character,  or  the extended GRUB key value,
+ *                            depending on the NumLock  and  the Shift key
+ *                            states.
+ *                      Any other key will first be remapped  according to
+ *                      the mapping entries set up  through  the  'setkey'
+ *                      command.  Then:
+ *                         -  If the key code does not  produce  an  ASCII
+ *                            character, then return its extended GRUB key
+ *                            value.
+ *                         -  If the key code produces a  printable  ASCII
+ *                            character (including DEL), then return that.
+ *                         -  Otherwise,  the  key code  will  produce  an
+ *                            ASCII control character.
+ *                            For a 'well-known'  ASCII control character,
+ *                            return its  ASCII character value;  for  any
+ *                            other  ASCII control character,  return  the
+ *                            GRUB contol key value.
+ *
+ *                      This function will be called  by  the  'nuconsole'
+ *                      input terminal  whenever it reads a keystroke from
+ *                      the keyboard.
+ */
+int
+grub_nusetkey_xlat (grub_uint16_t key)
+{
+  int grubkey;
+
+  /*
+   * Handle the keys on the numeric keypad.  These should not be remapped,
+   * except according to the 'numpad_force' setting.
+   */
+  if ((grubkey = grubkey_numpad (key)))
+    return grubkey;
+
+  /*
+   * Remap the key according to the keymap table.
+   */
+  key = grubkey_mapkey (key);
+
+  /*
+   * Handle extended keys,  i.e.,  those  for which the ASCII character is
+   * either null (0x00) or the extended key indicator (0xe0).
+   * Note that, instead of testing for the extact value of 0xe0,  the code
+   * here simply tests  if the high-order bit of the  ASCII  character  is
+   * set.  (No other value with the high-order bit set  should ever appear
+   * for a correctly functioning keyboard.)
+   */
+  if ((!(key & 0xff)) || (key & 0x80))
+    return (key >> 8) | GRUB_TERM_EXTENDED;
+
+
+  /*
+   * Handle printable ASCII characters (including DEL).
+   */
+  if ((key & 0xff) >= ' ')
+    return key & 0xff;
+
+  /*
+   * Handle well-known control characters.
+   */
+  if ((grubkey = grubkey_bypass (key)))
+    return grubkey;
+
+  /*
+   * Handle the less common control characters.
+   */
+  return (key & 0xff) + (('a' - 1) | GRUB_TERM_CTRL);
+}
+
+/*
+ * grub_keysym_code - Return  the key code that corresponds to  the  given
+ *                    name (cfr. 'keysym_table', above).
+ *                    If an invalid name is given, then return 0.
+ */
+static grub_uint16_t
+grub_keysym_code (char *name)
+{
+  unsigned int i;
+
+  for (i = 0; i < ARRAY_SIZE (keysym_table); i++)
+    if (!grub_strcmp (name, keysym_table[i].name))
+      return keysym_table[i].keycode;
+  return 0;
+}
+
+/*
+ * grubkey_map_entry - Return the subscript of the keymap entry  for which
+ *                     the keycode_from value is  equal  to  the given key
+ *                     code.
+ *                     If no keymap entry  exists  for the given key code,
+ *                     then return the subscript of the first empty entry.
+ *
+ *                     Since the keymap table  should  be  large enough to
+ *                     hold  an  entry  for  all supported keycode values,
+ *                     plus  at least  one  terminating  null  entry,  the
+ *                     subscript  returned  by  this  function  should not
+ *                     go out of range.
+ */
+static unsigned int
+grubkey_map_entry (grub_uint16_t key)
+{
+  unsigned int i;
+
+  for (i = 0; i < GRUB_SETKEY_KEYMAP_TABLE_SIZE; i++)
+    if (!keymap_table[i].keycode_from)
+      break;
+    else if (key == keymap_table[i].keycode_from)
+      break;
+  return i;
+}
+
+/*
+ * grub_cmd_setkey - Implement the 'setkey' command.
+ *                   If no arguments are given, then clear any key mapping
+ *                   entries that were set up.
+ *                   With one argument  (or  with  two  equal  arguments),
+ *                   delete the mapping entry for the given key.
+ *                   With two  (unequal)  arguments,  set up a key mapping
+ *                   entry for the key  that  corresponds  to  the  second
+ *                   argument string  (i.e., FROM_KEY), and make it output
+ *                   the key code  that  corresponds to the first argument
+ *                   string instead (i.e., TO_KEY).
+ */
+static grub_err_t
+grub_cmd_setkey (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc, char *args[])
+{
+  if (argc > 2)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("too many parameters"));
+  if (!argc)
+    /*
+     * Clear the keymap table.
+     */
+    grub_memset (keymap_table, 0, GRUB_SETKEY_KEYMAP_TABLE_SIZE * sizeof (keymap_table[0]));
+  else
+    {
+      grub_uint16_t keycode_from;
+      grub_uint16_t keycode_to;
+      unsigned int  i_keymap;
+
+      /*
+       * CAUTION: The argc value is decremented here.
+       *          Consequently,  if  two arguments were given,  then  argc
+       *          will be set to 1 from this point on.
+       *          Otherwise, only one argument was present,  and argc will
+       *          be 0.
+       *          All other cases were excluded by the code above.
+       *          Note  also  that  args[argc]  will  reference  the  last
+       *          argument string.
+       */
+      argc--;
+      /*
+       * The last argument string is FROM_KEY.
+       */
+      keycode_from = grub_keysym_code (args[argc]);
+      keycode_to   = 0;
+      if (argc && grub_strcmp (args[0], args[1]))
+        /*
+         * The first argument string is TO_KEY.
+         */
+        if (!(keycode_to = grub_keysym_code (args[0])))
+          return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid parameter `%s'"), args[0]);
+      if (!keycode_from)
+        return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid parameter `%s'"), args[argc]);
+      if ((i_keymap = grubkey_map_entry (keycode_from)) >= GRUB_SETKEY_KEYMAP_TABLE_SIZE)
+        /*
+         * This should not happen,  since the keymap table should be large
+         * enough to hold a keymap entry for all supported keycode values,
+         * plus at least one terminating null entry.
+         */
+        {
+          if (keycode_to)
+            return grub_error (GRUB_ERR_BUG, N_("keymap table full"));
+        }
+      else if (keycode_to)
+        {
+          keymap_table[i_keymap].keycode_from = keycode_from;
+          keymap_table[i_keymap].keycode_to   = keycode_to;
+        }
+      else if (keymap_table[i_keymap].keycode_from)
+        grub_memmove (keymap_table + i_keymap, keymap_table + (i_keymap + 1),
+                      (GRUB_SETKEY_KEYMAP_TABLE_SIZE - i_keymap - 1) * sizeof (keymap_table[0]));
+    }
+  return GRUB_ERR_NONE;
+}
+
+/*
+ * grub_cmd_setnumpad - Implement the 'setnumpad' command.
+ *                      When  the  '--force'  option  is  given,  make the
+ *                      numeric keypad output  printable ASCII characters,
+ *                      irrespective of the  NumLock  and  the  Shift  key
+ *                      states.
+ *                      With the '--noforce' option,  or when no option is
+ *                      specified,  the default behavior  of  the  numeric
+ *                      keypad (depending on the NumLock and the Shift key
+ *                      key states) will be restored.
+ */
+static grub_err_t
+grub_cmd_setnumpad (grub_extcmd_context_t ctxt, int argc, char *args[] __attribute__ ((unused)))
+{
+  if (argc)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("too many parameters"));
+  if ((ctxt->state[0].set) && (ctxt->state[1].set))
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("conflicting options"));
+  numpad_force = ctxt->state[0].set;
+  return GRUB_ERR_NONE;
+}
+
+static grub_extcmd_t cmd_setkey;
+static grub_extcmd_t  cmd_setnumpad;
+
+
+GRUB_MOD_INIT(nusetkey)
+{
+  cmd_setkey    = grub_register_extcmd (   /* const char                   *name        */   "setkey"
+                                       ,   /* grub_extcmd_func_t            func        */    grub_cmd_setkey
+                                       ,   /* grub_command_flags_t          flags       */   0
+                                       ,   /* const char                   *summary     */   N_("[[TO_KEY] FROM_KEY]")
+                                       ,   /* const char                   *description */   N_("Change the keyboard map.\n"
+                                                                                                "The key FROM_KEY is mapped to the key TO_KEY.\n"
+                                                                                                "If TO_KEY is missing, or if it is equal to FROM_KEY, "
+                                                                                                "then remove the mapping entry.\n"
+                                                                                                "If no parameters are specified, then remove all key mappings.\n\n"
+                                                                                                "A key must be:\n"
+                                                                                                "  - a  lowercase letter;\n"
+                                                                                                "  - an uppercase letter;\n"
+                                                                                                "  - a  decimal digit;\n"
+                                                                                                "  - a  function key, F1 through F12;\n"
+                                                                                                "or one of the following:\n"
+                                                                                                "  ampersand    barx         delete       less         question\n"
+                                                                                                "  asterisk     braceleft    dollar       minus        quote\n"
+                                                                                                "  at           braceright   doublequote  numbersign   semicolon\n"
+                                                                                                "  backslash    bracketleft  enter        parenleft    slash\n"
+                                                                                                "  backslashx   bracketright equal        parenright   space\n"
+                                                                                                "  backquote    caret        escape       percent      tab\n"
+                                                                                                "  backspace    colon        exclam       period       tilde\n"
+                                                                                                "  bar          comma        greater      plus         underscore")
+                                       ,   /* const struct grub_arg_option *parser      */   options_setkey
+                                       ) ;
+  cmd_setnumpad = grub_register_extcmd (   /* const char                   *name        */   "setnumpad"
+                                       ,   /* grub_extcmd_func_t            func        */   grub_cmd_setnumpad
+                                       ,   /* grub_command_flags_t          flags       */   0
+                                       ,   /* const char                   *summary     */   N_("[--force|--noforce]")
+                                       ,   /* const char                   *description */   N_("Change the behavior of the numeric keypad.\n")
+                                       ,   /* const struct grub_arg_option *parser      */   options_setnumpad
+                                       ) ;
+}
+
+GRUB_MOD_FINI(setkey)
+{
+  grub_unregister_extcmd (cmd_setnumpad);
+  grub_unregister_extcmd (cmd_setkey);
+}
diff --git a/include/grub/i386/pc/nusetkey.h b/include/grub/i386/pc/nusetkey.h
new file mode 100644
index 0000000..22b6f36
--- /dev/null
+++ b/include/grub/i386/pc/nusetkey.h
@@ -0,0 +1,25 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2006,2007  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/>.
+ */
+
+#ifndef GRUB_SETKEY_HEADER
+#define GRUB_SETKEY_HEADER	1
+
+extern int
+grub_nusetkey_xlat (grub_uint16_t key);
+
+#endif /* ! GRUB_SETKEY_HEADER */
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] implement the nuconsole input terminal
  2015-07-11 18:28 [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 1/4] update URL to bios_data_area.html on comment line Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 2/4] implement the nusetkey module Luc Van Rompaey
@ 2015-07-11 18:28 ` Luc Van Rompaey
  2015-07-11 18:28 ` [PATCH 4/4] add documentation for keymap, setkey, and setnumpad commands Luc Van Rompaey
  2015-07-12 10:03 ` [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Andrei Borzenkov
  4 siblings, 0 replies; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-11 18:28 UTC (permalink / raw
  To: The development of GNU GRUB

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, &regs);
+  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, &regs);
+
+  /*
+   * 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



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] add documentation for keymap, setkey, and setnumpad commands
  2015-07-11 18:28 [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Luc Van Rompaey
                   ` (2 preceding siblings ...)
  2015-07-11 18:28 ` [PATCH 3/4] implement the nuconsole input terminal Luc Van Rompaey
@ 2015-07-11 18:28 ` Luc Van Rompaey
  2015-07-12 10:03 ` [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Andrei Borzenkov
  4 siblings, 0 replies; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-11 18:28 UTC (permalink / raw
  To: The development of GNU GRUB

Update the GNU GRUB manual  with  entries  that  document  the  keymap,
setkey, and setnumpad commands, under the list of general commands.
---
 docs/grub.texi | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 150 insertions(+)

diff --git a/docs/grub.texi b/docs/grub.texi
index b9f41a7..8bd5efe 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -3660,13 +3660,57 @@ All options are the same as in the @command{menuentry} command
 Commands usable anywhere in the menu and in the command-line.
 
 @menu
+* keymap::                      Load a keyboard layout
 * serial::                      Set up a serial device
+* setkey::                      Change the keyboard map
+* setnumpad::                   Change the numeric keypad behavior
 * terminal_input::              Manage input terminals
 * terminal_output::             Manage output terminals
 * terminfo::                    Define terminal type
 @end menu
 
 
+@node keymap
+@subsection keymap
+
+@deffn Command keymap LAYOUT
+Load a keyboard layout.
+
+If @var{LAYOUT} is just the identifier of a keyboard layout, then GRUB will
+look for file @file{$prefix/layouts/@var{LAYOUT}.gkb}.
+Alternatively, @var{LAYOUT} may be the full path to a GRUB keyboard layout file.
+
+This command will have no effect unless and until you use the
+@command{terminal_input} command to activate either the @samp{at_keyboard}
+input terminal:
+
+@example
+terminal_input at_keyboard
+@end example
+
+or the @samp{usb_keyboard} input terminal:
+
+@example
+terminal_input usb_keyboard
+@end example
+
+@table @asis
+@item Creating a GRUB keyboard layout file:
+
+To generate a GRUB keyboard layout file, you can use the @command{grub-mklayout}
+command-line utility, which takes a Linux console keyboard layout description
+as input, and converts it to a format that GRUB can understand.
+
+For instance, if you use the @samp{dvorak} keyboard layout, then the following
+command will create the @file{dvorak.gkb} file for use with GRUB:
+
+@example
+ckbcomp dvorak | grub-mklayout -o dvorak.gkb
+@end example
+@end table
+@end deffn
+
+
 @node serial
 @subsection serial
 
@@ -3689,6 +3733,112 @@ See also @ref{Serial terminal}.
 @end deffn
 
 
+@node setkey
+@subsection setkey
+
+@deffn Command setkey [[TO_KEY] FROM_KEY]
+Change the keyboard map.
+
+With no arguments, reset the keyboard map to its default U.S. layout.
+
+When only the @var{FROM_KEY} argument is given, or when @var{TO_KEY} is equal to
+@var{FROM_KEY}, the mapping entry for the specified key will be cleared.
+Keep in mind that @var{FROM_KEY} identifies the position of the key under the default
+U.S. layout.
+
+With two unequal arguments, the key @var{FROM_KEY} will be mapped to @var{TO_KEY}.
+In effect, the @var{FROM_KEY} argument identifies the position of the key under the
+default U.S. layout, and @var{TO_KEY} specifies how the key should behave under your
+local keyboard layout.
+
+A key must be:
+@itemize @bullet
+@item
+a lowercase letter;
+@item
+an uppercase letter;
+@item
+a decimal digit;
+@item
+a function key---i.e., @kbd{F1} through @kbd{F12};
+@end itemize
+
+or one of the following:
+
+@verbatim
+  ampersand    barx         delete       less         question
+  asterisk     braceleft    dollar       minus        quote
+  at           braceright   doublequote  numbersign   semicolon
+  backslash    bracketleft  enter        parenleft    slash
+  backslashx   bracketright equal        parenright   space
+  backquote    caret        escape       percent      tab
+  backspace    colon        exclam       period       tilde
+  bar          comma        greater      plus         underscore
+@end verbatim
+
+This command is only available on PC BIOS systems. It will have no effect unless
+and until you use the @command{terminal_input} command to activate the @samp{nuconsole}
+input terminal:
+
+@example
+terminal_input nuconsole
+@end example
+
+Differences with the @command{setkey} command under GRUB Legacy:
+
+@itemize @bullet
+@item
+This @command{setkey} command does not support the modifier keys---i.e., @kbd{shift},
+@kbd{control}, @kbd{alt}, @kbd{capslock}.
+
+@item
+This @command{setkey} command supports all twelve function keys.
+
+@item
+Depending on your keyboard layout, there may be an extra key between the @key{Left Shift}
+key and the row of letter keys to its right. This extra key will output a backslash (i.e.,
+@kbd{\}) or, when shifted, a vertical bar (i.e., @kbd{|}), by default.
+
+This @command{setkey} command will not affect this extra key when you remap the
+@kbd{backslash} or @kbd{bar} keys. You can instead remap the key separately, using the
+@kbd{backslashx} or @kbd{barx} values for the @var{FROM_KEY} argument.
+
+For instance, under the Belgian keyboard layout, this key will output a @kbd{<} or, when
+shifted, a @kbd{>} character. The following GRUB commands will, then, appropriately remap
+the key:
+
+@example
+setkey less    backslashx
+setkey greater barx
+@end example
+@end itemize
+@end deffn
+
+
+@node setnumpad
+@subsection setnumpad
+
+@deffn Command setnumpad [@option{--force}|@option{--noforce}]
+Change the behavior of the numeric keypad.
+
+With @option{--force}, make the keys on the numeric keypad emit the numeric
+characters on their keycaps, irrespective of the @key{NumLock} and @key{Shift}
+key states.
+
+With @option{--noforce}, or if no option is given, restore default behavior
+of the keys on the numeric keypad, which depends on the @key{NumLock} and
+@key{Shift} states.
+
+This command is only available on PC BIOS systems. It will have no effect unless
+and until you use the @command{terminal_input} command to activate the @samp{nuconsole}
+input terminal:
+
+@example
+terminal_input nuconsole
+@end example
+@end deffn
+
+
 @node terminal_input
 @subsection terminal_input
 
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map
  2015-07-11 18:28 [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Luc Van Rompaey
                   ` (3 preceding siblings ...)
  2015-07-11 18:28 ` [PATCH 4/4] add documentation for keymap, setkey, and setnumpad commands Luc Van Rompaey
@ 2015-07-12 10:03 ` Andrei Borzenkov
  2015-07-12 12:25   ` Luc Van Rompaey
  4 siblings, 1 reply; 9+ messages in thread
From: Andrei Borzenkov @ 2015-07-12 10:03 UTC (permalink / raw
  To: Luc Van Rompaey; +Cc: The development of GNU GRUB

В Sat, 11 Jul 2015 20:28:20 +0200
Luc Van Rompaey <luc.vanrompaey@gmail.com> пишет:

> Legacy GRUB had a 'setkey' command to remap the keyboard keys.
> GRUB2 no longer has this command.  Instead, it provides an 'at_keyboard'
> input terminal module, which can load a GRUB keymap.
> Unfortunately, at least on the i386-pc platform, 'at_keyboard' is problematic,
> in that it easily causes hangups.
> 

Do you have some more data? Fixing it would be preferable.

> For now, I'm unsure what needs to be done to fix 'at_keyboard', which is why
> I decided to look for a different solution.  Whether I can fix the 'at_keyboard'
> input terminal, and in what time frame, remains to be seen.
> 
> This patch set reintroduces a 'setkey' command, to support changing the keyboard
> map, similarly to what was possible under Legacy GRUB.
> 

GRUB2 already has framework for custom keyboard layouts. Why not reuse
grub_term_map_key() from keylayouts same as at_keyboard and
usb_keyboard do? Map scan code to GRUB_KEYBOARD_* and let
grub_term_map_key() to care about keyboard mapping. This has additional
advantage of supporting localized keyboard tables (your approach does
not, it only changes ASCII layouts).

> The first patch just makes a simple edit to a comment line in the 'memory.h'
> header file.  It updates the URL for the 'bios_data_area.html' web page, which
> contains helpful information about BIOS, and specifically, the keyboard
> interface.
> 

You already sent this one, it hardly belongs to this patch series.

> The second patch implements the 'nusetkey' module, which provides the 'setkey'
> command. In addition, it provides a 'setnumpad' command, to change the
> behavior of the numeric keypad.
>

Why NumLock is not sufficient? 
 
> The third patch implements the 'nuconsole' input terminal, which works in
> conjunction with the 'nusetkey' module to support keyboard map changes.
> 

Making them two different modules in your case is pointless; nuconsole
cannot work without nusetkey and nusetkey is used only by nuconsole.
Also, something like ext_keyboard would probably be more appropriate.

> Finally, the fourth patch provides updates to the GRUB manual.
> It documents the 'keymap' command (which loads a keyboard map for use by
> the 'at_keyboard' or 'usb_keyboard' input terminals), plus the 'setkey' and
> 'setnumpad' commands implemented by the 'nusetkey' module.
> 
> Luc Van Rompaey (4):
>   update URL to bios_data_area.html on comment line
>   implement the nusetkey module
>   implement the nuconsole input terminal
>   add documentation for keymap, setkey, and setnumpad commands
> 
>  docs/grub.texi                        | 150 +++++++++
>  grub-core/Makefile.core.def           |  12 +
>  grub-core/commands/i386/pc/nusetkey.c | 583 ++++++++++++++++++++++++++++++++++
>  grub-core/term/i386/pc/nuconsole.c    | 111 +++++++
>  include/grub/i386/pc/memory.h         |   2 +-
>  include/grub/i386/pc/nusetkey.h       |  25 ++
>  6 files changed, 882 insertions(+), 1 deletion(-)
>  create mode 100644 grub-core/commands/i386/pc/nusetkey.c
>  create mode 100644 grub-core/term/i386/pc/nuconsole.c
>  create mode 100644 include/grub/i386/pc/nusetkey.h
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map
  2015-07-12 10:03 ` [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Andrei Borzenkov
@ 2015-07-12 12:25   ` Luc Van Rompaey
  2015-07-14 17:25     ` Luc Van Rompaey
  0 siblings, 1 reply; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-12 12:25 UTC (permalink / raw
  To: Andrei Borzenkov; +Cc: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 5729 bytes --]

2015-07-12 12:03 GMT+02:00 Andrei Borzenkov <arvidjaar@gmail.com>:

> В Sat, 11 Jul 2015 20:28:20 +0200
> Luc Van Rompaey <luc.vanrompaey@gmail.com> пишет:
>
> > Legacy GRUB had a 'setkey' command to remap the keyboard keys.
> > GRUB2 no longer has this command.  Instead, it provides an 'at_keyboard'
> > input terminal module, which can load a GRUB keymap.
> > Unfortunately, at least on the i386-pc platform, 'at_keyboard' is
> problematic,
> > in that it easily causes hangups.
> >
>
> Do you have some more data? Fixing it would be preferable.
>
> For starters, the first keystroke after I activate 'at_keyboard', will not
get processed, even though the countdown until automatic boot will get
stopped.
Further keystrokes are something of a hit-and-miss, until the system no
longer responds to keyboard input.
At that point, either some kind of crash will happen, after which the
computer reboots, or I need to perform a hard reset (power cycle).

If I do get to the point where I can chainload another GRUB copy (with a
default config as automatically generated under, e.g., Debian or Ubuntu),
then apparently, the keystrokes that didn't get processed earlier on,
suddenly seem to be run, ... after which the system locks up, and a hard
reset is, again, required.

I would love to fix the 'at_keyboard' issue, and I will if I can. I cannot
at this point promise anything, though. Plus, something less convoluted is
a great exercise to get a feel for the GRUB code.

> For now, I'm unsure what needs to be done to fix 'at_keyboard', which is
> why
> > I decided to look for a different solution.  Whether I can fix the
> 'at_keyboard'
> > input terminal, and in what time frame, remains to be seen.
> >
> > This patch set reintroduces a 'setkey' command, to support changing the
> keyboard
> > map, similarly to what was possible under Legacy GRUB.
> >
>
> GRUB2 already has framework for custom keyboard layouts. Why not reuse
> grub_term_map_key() from keylayouts same as at_keyboard and
> usb_keyboard do? Map scan code to GRUB_KEYBOARD_* and let
> grub_term_map_key() to care about keyboard mapping. This has additional
> advantage of supporting localized keyboard tables (your approach does
> not, it only changes ASCII layouts).


Hmm... good idea. I'll look into this. Thanks for the pointer.


> > The first patch just makes a simple edit to a comment line in the
> 'memory.h'
> > header file.  It updates the URL for the 'bios_data_area.html' web page,
> which
> > contains helpful information about BIOS, and specifically, the keyboard
> > interface.
> >
>
> You already sent this one, it hardly belongs to this patch series.
>

Sorry about that.

>
> > The second patch implements the 'nusetkey' module, which provides the
> 'setkey'
> > command. In addition, it provides a 'setnumpad' command, to change the
> > behavior of the numeric keypad.
> >
>
> Why NumLock is not sufficient?
>

NumLock is 'sufficient' in that it works.
I implemented the 'always output numeric character' feature because I find
it annoying that the numeric keypad doesn't produce numeric characters by
default.
The BIOS of my laptop doesn't offer me the option of automatically turning
NumLock on, which is an added annoyance.
And, last but not least, my laptop doesn't have a NumLock LED, so I cannot
even visually verify if NumLock is on or off.

I use the numeric keypad only ever to get numeric characters anyway (which
is what it should be there for in the first place, in my not so humble
opinion), and since the feature was pretty easy to implement, I decided to
go for it.

>
> > The third patch implements the 'nuconsole' input terminal, which works in
> > conjunction with the 'nusetkey' module to support keyboard map changes.
> >
>
> Making them two different modules in your case is pointless; nuconsole
> cannot work without nusetkey and nusetkey is used only by nuconsole.
>

I won't disagree that it seems pointless.
In fact, I initially wanted to integrate all of my code in one module, but
that didn't work.
I got some kind of error about some out-of-memory or table-full condition,
or some such (don't remember exactly; failed to take notes).
It seemed to me that terminal input and/or output modules couldn't provide
their own commands.
I may be wrong, though, in which case I must have done something awfully
stupid.


> Also, something like ext_keyboard would probably be more appropriate.
>

Agreed.. will go for the 'ext_keyboard' name.

>
> > Finally, the fourth patch provides updates to the GRUB manual.
> > It documents the 'keymap' command (which loads a keyboard map for use by
> > the 'at_keyboard' or 'usb_keyboard' input terminals), plus the 'setkey'
> and
> > 'setnumpad' commands implemented by the 'nusetkey' module.
> >
> > Luc Van Rompaey (4):
> >   update URL to bios_data_area.html on comment line
> >   implement the nusetkey module
> >   implement the nuconsole input terminal
> >   add documentation for keymap, setkey, and setnumpad commands
> >
> >  docs/grub.texi                        | 150 +++++++++
> >  grub-core/Makefile.core.def           |  12 +
> >  grub-core/commands/i386/pc/nusetkey.c | 583
> ++++++++++++++++++++++++++++++++++
> >  grub-core/term/i386/pc/nuconsole.c    | 111 +++++++
> >  include/grub/i386/pc/memory.h         |   2 +-
> >  include/grub/i386/pc/nusetkey.h       |  25 ++
> >  6 files changed, 882 insertions(+), 1 deletion(-)
> >  create mode 100644 grub-core/commands/i386/pc/nusetkey.c
> >  create mode 100644 grub-core/term/i386/pc/nuconsole.c
> >  create mode 100644 include/grub/i386/pc/nusetkey.h
> >
>
>

[-- Attachment #2: Type: text/html, Size: 7882 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map
  2015-07-12 12:25   ` Luc Van Rompaey
@ 2015-07-14 17:25     ` Luc Van Rompaey
  2015-07-14 19:00       ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 9+ messages in thread
From: Luc Van Rompaey @ 2015-07-14 17:25 UTC (permalink / raw
  To: Andrei Borzenkov; +Cc: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 7352 bytes --]

Just a few quick notes:

   - I have just retried to integrate my 'setkey' and 'setnumpad' commands
   into my input terminal module, and it works.
   I have no idea what I did wrong when I tried it earlier on, but it
   obviously must have been something silly.
   - The INT16H/10H extended keyboard input call, used by my input terminal
   module, is not powerful enough to fully support a keymap.
   For instance, the Belgian keyboard layout uses quite a few <AltGr> (or
   <RightAlt>) key combinations for various characters, and the call doesn't
   distinguish between <LeftAlt> and <RightAlt>.
   Furthermore, not all keys report their <Alt> combination. As a result,
   under the Belgian keyboard layout, there would be no way to input, for
   example, a backslash character.
   Of course, my 'setkey' command runs into similar problems, so that is
   not a perfect solution either.
   - Since it's a bit silly to replace one not entirely satisfying solution
   with another, I will not further pursue a solution that is based upon my
   input terminal modules; that really seems somewhat like a waste of time.
   Instead, I'll try and find out what is going wrong with 'at_keyboard', and
   see if I can fix it.
   - In any case, I can continue to use my input terminal for now, until I
   can work out a better option.


2015-07-12 14:25 GMT+02:00 Luc Van Rompaey <luc.vanrompaey@gmail.com>:

>
> 2015-07-12 12:03 GMT+02:00 Andrei Borzenkov <arvidjaar@gmail.com>:
>
>> В Sat, 11 Jul 2015 20:28:20 +0200
>> Luc Van Rompaey <luc.vanrompaey@gmail.com> пишет:
>>
>> > Legacy GRUB had a 'setkey' command to remap the keyboard keys.
>> > GRUB2 no longer has this command.  Instead, it provides an 'at_keyboard'
>> > input terminal module, which can load a GRUB keymap.
>> > Unfortunately, at least on the i386-pc platform, 'at_keyboard' is
>> problematic,
>> > in that it easily causes hangups.
>> >
>>
>> Do you have some more data? Fixing it would be preferable.
>>
>> For starters, the first keystroke after I activate 'at_keyboard', will
> not get processed, even though the countdown until automatic boot will get
> stopped.
> Further keystrokes are something of a hit-and-miss, until the system no
> longer responds to keyboard input.
> At that point, either some kind of crash will happen, after which the
> computer reboots, or I need to perform a hard reset (power cycle).
>
> If I do get to the point where I can chainload another GRUB copy (with a
> default config as automatically generated under, e.g., Debian or Ubuntu),
> then apparently, the keystrokes that didn't get processed earlier on,
> suddenly seem to be run, ... after which the system locks up, and a hard
> reset is, again, required.
>
> I would love to fix the 'at_keyboard' issue, and I will if I can. I cannot
> at this point promise anything, though. Plus, something less convoluted is
> a great exercise to get a feel for the GRUB code.
>
> > For now, I'm unsure what needs to be done to fix 'at_keyboard', which is
>> why
>> > I decided to look for a different solution.  Whether I can fix the
>> 'at_keyboard'
>> > input terminal, and in what time frame, remains to be seen.
>> >
>> > This patch set reintroduces a 'setkey' command, to support changing the
>> keyboard
>> > map, similarly to what was possible under Legacy GRUB.
>> >
>>
>> GRUB2 already has framework for custom keyboard layouts. Why not reuse
>> grub_term_map_key() from keylayouts same as at_keyboard and
>> usb_keyboard do? Map scan code to GRUB_KEYBOARD_* and let
>> grub_term_map_key() to care about keyboard mapping. This has additional
>> advantage of supporting localized keyboard tables (your approach does
>> not, it only changes ASCII layouts).
>
>
> Hmm... good idea. I'll look into this. Thanks for the pointer.
>
>
>> > The first patch just makes a simple edit to a comment line in the
>> 'memory.h'
>> > header file.  It updates the URL for the 'bios_data_area.html' web
>> page, which
>> > contains helpful information about BIOS, and specifically, the keyboard
>> > interface.
>> >
>>
>> You already sent this one, it hardly belongs to this patch series.
>>
>
> Sorry about that.
>
>>
>> > The second patch implements the 'nusetkey' module, which provides the
>> 'setkey'
>> > command. In addition, it provides a 'setnumpad' command, to change the
>> > behavior of the numeric keypad.
>> >
>>
>> Why NumLock is not sufficient?
>>
>
> NumLock is 'sufficient' in that it works.
> I implemented the 'always output numeric character' feature because I find
> it annoying that the numeric keypad doesn't produce numeric characters by
> default.
> The BIOS of my laptop doesn't offer me the option of automatically turning
> NumLock on, which is an added annoyance.
> And, last but not least, my laptop doesn't have a NumLock LED, so I cannot
> even visually verify if NumLock is on or off.
>
> I use the numeric keypad only ever to get numeric characters anyway (which
> is what it should be there for in the first place, in my not so humble
> opinion), and since the feature was pretty easy to implement, I decided to
> go for it.
>
>>
>> > The third patch implements the 'nuconsole' input terminal, which works
>> in
>> > conjunction with the 'nusetkey' module to support keyboard map changes.
>> >
>>
>> Making them two different modules in your case is pointless; nuconsole
>> cannot work without nusetkey and nusetkey is used only by nuconsole.
>>
>
> I won't disagree that it seems pointless.
> In fact, I initially wanted to integrate all of my code in one module, but
> that didn't work.
> I got some kind of error about some out-of-memory or table-full condition,
> or some such (don't remember exactly; failed to take notes).
> It seemed to me that terminal input and/or output modules couldn't provide
> their own commands.
> I may be wrong, though, in which case I must have done something awfully
> stupid.
>
>
>> Also, something like ext_keyboard would probably be more appropriate.
>>
>
> Agreed.. will go for the 'ext_keyboard' name.
>
>>
>> > Finally, the fourth patch provides updates to the GRUB manual.
>> > It documents the 'keymap' command (which loads a keyboard map for use by
>> > the 'at_keyboard' or 'usb_keyboard' input terminals), plus the 'setkey'
>> and
>> > 'setnumpad' commands implemented by the 'nusetkey' module.
>> >
>> > Luc Van Rompaey (4):
>> >   update URL to bios_data_area.html on comment line
>> >   implement the nusetkey module
>> >   implement the nuconsole input terminal
>> >   add documentation for keymap, setkey, and setnumpad commands
>> >
>> >  docs/grub.texi                        | 150 +++++++++
>> >  grub-core/Makefile.core.def           |  12 +
>> >  grub-core/commands/i386/pc/nusetkey.c | 583
>> ++++++++++++++++++++++++++++++++++
>> >  grub-core/term/i386/pc/nuconsole.c    | 111 +++++++
>> >  include/grub/i386/pc/memory.h         |   2 +-
>> >  include/grub/i386/pc/nusetkey.h       |  25 ++
>> >  6 files changed, 882 insertions(+), 1 deletion(-)
>> >  create mode 100644 grub-core/commands/i386/pc/nusetkey.c
>> >  create mode 100644 grub-core/term/i386/pc/nuconsole.c
>> >  create mode 100644 include/grub/i386/pc/nusetkey.h
>> >
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 9741 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map
  2015-07-14 17:25     ` Luc Van Rompaey
@ 2015-07-14 19:00       ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 9+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-07-14 19:00 UTC (permalink / raw
  To: The development of GRUB 2; +Cc: Andrey Borzenkov

[-- Attachment #1: Type: text/plain, Size: 8025 bytes --]

Le 14 juil. 2015 19:25, "Luc Van Rompaey" <luc.vanrompaey@gmail.com> a
écrit :
>
> Just a few quick notes:
> I have just retried to integrate my 'setkey' and 'setnumpad' commands
into my input terminal module, and it works.
> I have no idea what I did wrong when I tried it earlier on, but it
obviously must have been something silly.
> The INT16H/10H extended keyboard input call, used by my input terminal
module, is not powerful enough to fully support a keymap.
> For instance, the Belgian keyboard layout uses quite a few <AltGr> (or
<RightAlt>) key combinations for various characters, and the call doesn't
distinguish between <LeftAlt> and <RightAlt>.
> Furthermore, not all keys report their <Alt> combination. As a result,
under the Belgian keyboard layout, there would be no way to input, for
example, a backslash character.
Yep. I've run into the same problem when I was investigating possibility of
keymap with BIOS. Only few keyboards end up functional under those
restrictions. You might have better luck of you read some of this data from
BDA directly.
I have few others comments as to code style but I skip them as I'm not even
sure it's a viable solution at all.
> Of course, my 'setkey' command runs into similar problems, so that is not
a perfect solution either.
> Since it's a bit silly to replace one not entirely satisfying solution
with another, I will not further pursue a solution that is based upon my
input terminal modules; that really seems somewhat like a waste of time.
Instead, I'll try and find out what is going wrong with 'at_keyboard', and
see if I can fix it.

Most likely you just need to add code to disable keyboard inferior INT1
AFAIR
> In any case, I can continue to use my input terminal for now, until I can
work out a better option.
>
> 2015-07-12 14:25 GMT+02:00 Luc Van Rompaey <luc.vanrompaey@gmail.com>:
>>
>>
>> 2015-07-12 12:03 GMT+02:00 Andrei Borzenkov <arvidjaar@gmail.com>:
>>>
>>> В Sat, 11 Jul 2015 20:28:20 +0200
>>> Luc Van Rompaey <luc.vanrompaey@gmail.com> пишет:
>>>
>>> > Legacy GRUB had a 'setkey' command to remap the keyboard keys.
>>> > GRUB2 no longer has this command.  Instead, it provides an
'at_keyboard'
>>> > input terminal module, which can load a GRUB keymap.
>>> > Unfortunately, at least on the i386-pc platform, 'at_keyboard' is
problematic,
>>> > in that it easily causes hangups.
>>> >
>>>
>>> Do you have some more data? Fixing it would be preferable.
>>>
>> For starters, the first keystroke after I activate 'at_keyboard', will
not get processed, even though the countdown until automatic boot will get
stopped.
>> Further keystrokes are something of a hit-and-miss, until the system no
longer responds to keyboard input.
>> At that point, either some kind of crash will happen, after which the
computer reboots, or I need to perform a hard reset (power cycle).
>>
>> If I do get to the point where I can chainload another GRUB copy (with a
default config as automatically generated under, e.g., Debian or Ubuntu),
then apparently, the keystrokes that didn't get processed earlier on,
suddenly seem to be run, ... after which the system locks up, and a hard
reset is, again, required.
>>
>> I would love to fix the 'at_keyboard' issue, and I will if I can. I
cannot at this point promise anything, though. Plus, something less
convoluted is a great exercise to get a feel for the GRUB code.
>>
>>> > For now, I'm unsure what needs to be done to fix 'at_keyboard', which
is why
>>> > I decided to look for a different solution.  Whether I can fix the
'at_keyboard'
>>> > input terminal, and in what time frame, remains to be seen.
>>> >
>>> > This patch set reintroduces a 'setkey' command, to support changing
the keyboard
>>> > map, similarly to what was possible under Legacy GRUB.
>>> >
>>>
>>> GRUB2 already has framework for custom keyboard layouts. Why not reuse
>>> grub_term_map_key() from keylayouts same as at_keyboard and
>>> usb_keyboard do? Map scan code to GRUB_KEYBOARD_* and let
>>> grub_term_map_key() to care about keyboard mapping. This has additional
>>> advantage of supporting localized keyboard tables (your approach does
>>> not, it only changes ASCII layouts).
>>
>>
>> Hmm... good idea. I'll look into this. Thanks for the pointer.
>>
>>>
>>> > The first patch just makes a simple edit to a comment line in the
'memory.h'
>>> > header file.  It updates the URL for the 'bios_data_area.html' web
page, which
>>> > contains helpful information about BIOS, and specifically, the
keyboard
>>> > interface.
>>> >
>>>
>>> You already sent this one, it hardly belongs to this patch series.
>>
>>
>> Sorry about that.
>>>
>>>
>>> > The second patch implements the 'nusetkey' module, which provides the
'setkey'
>>> > command. In addition, it provides a 'setnumpad' command, to change the
>>> > behavior of the numeric keypad.
>>> >
>>>
>>> Why NumLock is not sufficient?
>>
>>
>> NumLock is 'sufficient' in that it works.
>> I implemented the 'always output numeric character' feature because I
find it annoying that the numeric keypad doesn't produce numeric characters
by default.
>> The BIOS of my laptop doesn't offer me the option of automatically
turning NumLock on, which is an added annoyance.
>> And, last but not least, my laptop doesn't have a NumLock LED, so I
cannot even visually verify if NumLock is on or off.
>>
>> I use the numeric keypad only ever to get numeric characters anyway
(which is what it should be there for in the first place, in my not so
humble opinion), and since the feature was pretty easy to implement, I
decided to go for it.
>>>
>>>
>>> > The third patch implements the 'nuconsole' input terminal, which
works in
>>> > conjunction with the 'nusetkey' module to support keyboard map
changes.
>>> >
>>>
>>> Making them two different modules in your case is pointless; nuconsole
>>> cannot work without nusetkey and nusetkey is used only by nuconsole.
>>
>>
>> I won't disagree that it seems pointless.
>> In fact, I initially wanted to integrate all of my code in one module,
but that didn't work.
>> I got some kind of error about some out-of-memory or table-full
condition, or some such (don't remember exactly; failed to take notes).
>> It seemed to me that terminal input and/or output modules couldn't
provide their own commands.
>> I may be wrong, though, in which case I must have done something awfully
stupid.
>>
>>>
>>> Also, something like ext_keyboard would probably be more appropriate.
>>
>>
>> Agreed.. will go for the 'ext_keyboard' name.
>>>
>>>
>>> > Finally, the fourth patch provides updates to the GRUB manual.
>>> > It documents the 'keymap' command (which loads a keyboard map for use
by
>>> > the 'at_keyboard' or 'usb_keyboard' input terminals), plus the
'setkey' and
>>> > 'setnumpad' commands implemented by the 'nusetkey' module.
>>> >
>>> > Luc Van Rompaey (4):
>>> >   update URL to bios_data_area.html on comment line
>>> >   implement the nusetkey module
>>> >   implement the nuconsole input terminal
>>> >   add documentation for keymap, setkey, and setnumpad commands
>>> >
>>> >  docs/grub.texi                        | 150 +++++++++
>>> >  grub-core/Makefile.core.def           |  12 +
>>> >  grub-core/commands/i386/pc/nusetkey.c | 583
++++++++++++++++++++++++++++++++++
>>> >  grub-core/term/i386/pc/nuconsole.c    | 111 +++++++
>>> >  include/grub/i386/pc/memory.h         |   2 +-
>>> >  include/grub/i386/pc/nusetkey.h       |  25 ++
>>> >  6 files changed, 882 insertions(+), 1 deletion(-)
>>> >  create mode 100644 grub-core/commands/i386/pc/nusetkey.c
>>> >  create mode 100644 grub-core/term/i386/pc/nuconsole.c
>>> >  create mode 100644 include/grub/i386/pc/nusetkey.h
>>> >
>>>
>>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 10391 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-07-14 19:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-11 18:28 [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Luc Van Rompaey
2015-07-11 18:28 ` [PATCH 1/4] update URL to bios_data_area.html on comment line Luc Van Rompaey
2015-07-11 18:28 ` [PATCH 2/4] implement the nusetkey module Luc Van Rompaey
2015-07-11 18:28 ` [PATCH 3/4] implement the nuconsole input terminal Luc Van Rompaey
2015-07-11 18:28 ` [PATCH 4/4] add documentation for keymap, setkey, and setnumpad commands Luc Van Rompaey
2015-07-12 10:03 ` [PATCH 0/4] Implement the 'setkey' command to allow changing the keyboard map Andrei Borzenkov
2015-07-12 12:25   ` Luc Van Rompaey
2015-07-14 17:25     ` Luc Van Rompaey
2015-07-14 19:00       ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.