]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Remove checkkey on term level
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 23 Aug 2010 10:07:49 +0000 (12:07 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 23 Aug 2010 10:07:49 +0000 (12:07 +0200)
13 files changed:
include/grub/i386/pc/console.h
include/grub/term.h
include/grub/terminfo.h
kern/emu/console.c
kern/i386/pc/startup.S
kern/term.c
term/at_keyboard.c
term/efi/console.c
term/i386/pc/console.c
term/ieee1275/ofconsole.c
term/serial.c
term/terminfo.c
term/usb_keyboard.c

index fabb13d5cb52ca31ce1484d4f1157c1cb7c266da..1631a40ad423b48b89f8b477e7d23107f1be8400 100644 (file)
@@ -27,7 +27,6 @@
 #include <grub/i386/vga_common.h>
 
 /* These are global to share code between C and asm.  */
-int grub_console_checkkey (struct grub_term_input *term);
 int grub_console_getkey (struct grub_term_input *term);
 grub_uint16_t grub_console_getxy (struct grub_term_output *term);
 void grub_console_gotoxy (struct grub_term_output *term,
index bfe1c8f9bacb49ce3ab6154fc99688ea7c068ea9..4289781429c294ab7d365c0cc7cfff1228befb09 100644 (file)
@@ -158,10 +158,7 @@ struct grub_term_input
   /* Clean up the terminal.  */
   grub_err_t (*fini) (struct grub_term_input *term);
 
-  /* Check if any input character is available.  */
-  int (*checkkey) (struct grub_term_input *term);
-
-  /* Get a character.  */
+  /* Get a character if any input character is available. Otherwise return -1  */
   int (*getkey) (struct grub_term_input *term);
 
   /* Get keyboard modifier status.  */
index 85ddb5779880d6c17a0190f2493f94bdd80d3fb2..1962c71b72798fab6b1665ebe413f0732f15a2f7 100644 (file)
@@ -64,7 +64,6 @@ void EXPORT_FUNC (grub_terminfo_setcolorstate) (struct grub_term_output *term,
                                  const grub_term_color_state state);
 
 
-int EXPORT_FUNC (grub_terminfo_checkkey) (struct grub_term_input *term);
 grub_err_t EXPORT_FUNC (grub_terminfo_input_init) (struct grub_term_input *term);
 int EXPORT_FUNC (grub_terminfo_getkey) (struct grub_term_input *term);
 void EXPORT_FUNC (grub_terminfo_putchar) (struct grub_term_output *term,
index f6b13b19b95bd5031f7b030b2b5aeb31ed827b1a..0bf1e05f92e7808b060edff2642f758cd543cc82 100644 (file)
@@ -102,49 +102,18 @@ grub_ncurses_setcolorstate (struct grub_term_output *term,
     }
 }
 
-static int saved_char = ERR;
-
 static int
-grub_ncurses_checkkey (struct grub_term_input *term __attribute__ ((unused)))
+grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
 {
   int c;
 
-  /* Check for SAVED_CHAR. This should not be true, because this
-     means checkkey is called twice continuously.  */
-  if (saved_char != ERR)
-    return saved_char;
-
   wtimeout (stdscr, 100);
   c = getch ();
-  /* If C is not ERR, then put it back in the input queue.  */
-  if (c != ERR)
-    {
-      saved_char = c;
-      return c;
-    }
-
-  return -1;
-}
-
-static int
-grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
-{
-  int c;
-
-  /* If checkkey has already got a character, then return it.  */
-  if (saved_char != ERR)
-    {
-      c = saved_char;
-      saved_char = ERR;
-    }
-  else
-    {
-      wtimeout (stdscr, -1);
-      c = getch ();
-    }
 
   switch (c)
     {
+    case ERR:
+      return -1;
     case KEY_LEFT:
       c = GRUB_TERM_LEFT;
       break;
@@ -288,7 +257,6 @@ grub_ncurses_fini (struct grub_term_output *term __attribute__ ((unused)))
 static struct grub_term_input grub_ncurses_term_input =
   {
     .name = "console",
-    .checkkey = grub_ncurses_checkkey,
     .getkey = grub_ncurses_getkey,
   };
 
index f78fb5baac5a0a4b7756be353793347d46c0d385..2d726415612231ef2112efd9f055e9a48e6ea645 100644 (file)
@@ -1154,6 +1154,16 @@ LOCAL(bypass_table_end):
 
 /*
  * int grub_console_getkey (void)
+ *     if there is a character pending, return it; otherwise return -1
+ * BIOS call "INT 16H Function 01H" to check whether a character is pending
+ *     Call with       %ah = 0x1
+ *     Return:
+ *             If key waiting to be input:
+ *                     %ah = keyboard scan code
+ *                     %al = ASCII character
+ *                     Zero flag = clear
+ *             else
+ *                     Zero flag = set
  * BIOS call "INT 16H Function 00H" to read character from keyboard
  *     Call with       %ah = 0x0
  *     Return:         %ah = keyboard scan code
@@ -1173,14 +1183,9 @@ FUNCTION(grub_console_getkey)
         * INT 16/AH = 1 before calling INT 16/AH = 0.
         */
 
-1:
        movb    $1, %ah
        int     $0x16
-       jnz     2f
-       hlt
-       jmp     1b
-
-2:
+       jz      notpending
 
        movb    $0, %ah
        int     $0x16
@@ -1217,47 +1222,12 @@ FUNCTION(grub_console_getkey)
        popl    %ebp
        ret
 
-/*
- * int grub_console_checkkey (void)
- *     if there is a character pending, return it; otherwise return -1
- * BIOS call "INT 16H Function 01H" to check whether a character is pending
- *     Call with       %ah = 0x1
- *     Return:
- *             If key waiting to be input:
- *                     %ah = keyboard scan code
- *                     %al = ASCII character
- *                     Zero flag = clear
- *             else
- *                     Zero flag = set
- */
-FUNCTION(grub_console_checkkey)
-       pushl   %ebp
-       xorl    %edx, %edx
-
-       call    prot_to_real    /* enter real mode */
+notpending:    
        .code16
-
-       movb    $0x1, %ah
-       int     $0x16
-
-       jz      notpending
-
-       xorl    %edx, %edx
-       movw    %ax, %dx
-       DATA32  jmp     pending
-
-notpending:
-       xorl    %edx, %edx
-       decl    %edx
-
-pending:
        DATA32  call    real_to_prot
        .code32
-
-       movl    %edx, %eax
-
-       popl    %ebp
-       ret
+       decl %eax
+       jmp 2b
 
 
 /*
index 185626d3647b89a6dea2e9a2292f154361113262..a05325346911bc84b7a1316c076f760962e13182 100644 (file)
@@ -78,6 +78,8 @@ grub_xputs_dumb (const char *str)
 
 void (*grub_xputs) (const char *str) = grub_xputs_dumb;
 
+static int pending_key = -1;
+
 int
 grub_getkey (void)
 {
@@ -85,6 +87,12 @@ grub_getkey (void)
 
   grub_refresh ();
 
+  if (pending_key != -1)
+    {
+      pending_key = -1;
+      return pending_key;
+    }
+
   while (1)
     {
       if (grub_term_poll_usb)
@@ -92,9 +100,9 @@ grub_getkey (void)
 
       FOR_ACTIVE_TERM_INPUTS(term)
       {
-       int key = term->checkkey (term);
+       int key = term->getkey (term);
        if (key != -1)
-         return term->getkey (term);
+         return key;
       }
 
       grub_cpu_idle ();
@@ -106,14 +114,17 @@ grub_checkkey (void)
 {
   grub_term_input_t term;
 
+  if (pending_key != -1)
+    return pending_key;
+
   if (grub_term_poll_usb)
     grub_term_poll_usb ();
 
   FOR_ACTIVE_TERM_INPUTS(term)
   {
-    int key = term->checkkey (term);
-    if (key != -1)
-      return key;
+    pending_key = term->getkey (term);
+    if (pending_key != -1)
+      return pending_key;
   }
 
   return -1;
index e9db7834a57d3235ed68459ee7ee563499dac3a1..6ea908a2b71a50cc5fa36c0846d06bb60c6504fd 100644 (file)
@@ -28,7 +28,6 @@
 static short at_keyboard_status = 0;
 static int e0_received = 0;
 static int f0_received = 0;
-static int pending_key = -1;
 
 static grub_uint8_t led_status;
 
@@ -478,7 +477,7 @@ grub_keyboard_getkey (void)
 
 /* If there is a character pending, return it; otherwise return -1.  */
 static int
-grub_at_keyboard_getkey_noblock (void)
+grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
 {
   int code;
   code = grub_keyboard_getkey ();
@@ -517,41 +516,9 @@ grub_at_keyboard_getkey_noblock (void)
     }
 }
 
-static int
-grub_at_keyboard_checkkey (struct grub_term_input *term __attribute__ ((unused)))
-{
-  if (pending_key != -1)
-    return 1;
-
-  pending_key = grub_at_keyboard_getkey_noblock ();
-
-  if (pending_key != -1)
-    return 1;
-
-  return -1;
-}
-
-static int
-grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
-{
-  int key;
-  if (pending_key != -1)
-    {
-      key = pending_key;
-      pending_key = -1;
-      return key;
-    }
-  do
-    {
-      key = grub_at_keyboard_getkey_noblock ();
-    } while (key == -1);
-  return key;
-}
-
 static grub_err_t
 grub_keyboard_controller_init (struct grub_term_input *term __attribute__ ((unused)))
 {
-  pending_key = -1;
   at_keyboard_status = 0;
   /* Drain input buffer. */
   while (1)
@@ -583,7 +550,6 @@ static struct grub_term_input grub_at_keyboard_term =
     .name = "at_keyboard",
     .init = grub_keyboard_controller_init,
     .fini = grub_keyboard_controller_fini,
-    .checkkey = grub_at_keyboard_checkkey,
     .getkey = grub_at_keyboard_getkey
   };
 
index f47263ee402c8598c5fab7151b4732cb4f20a52b..97fefd9819c4b277a523d0b2a7e10f515448bd10 100644 (file)
@@ -28,8 +28,6 @@ static const grub_uint8_t
 grub_console_standard_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_YELLOW,
                                                  GRUB_EFI_BACKGROUND_BLACK);
 
-static int read_key = -1;
-
 static grub_uint32_t
 map_char (grub_uint32_t c)
 {
@@ -112,15 +110,12 @@ const unsigned efi_codes[] =
 
 
 static int
-grub_console_checkkey (struct grub_term_input *term __attribute__ ((unused)))
+grub_console_getkey (struct grub_term_input *term __attribute__ ((unused)))
 {
   grub_efi_simple_input_interface_t *i;
   grub_efi_input_key_t key;
   grub_efi_status_t status;
 
-  if (read_key >= 0)
-    return 1;
-
   i = grub_efi_system_table->con_in;
   status = efi_call_2 (i->read_key_stroke, i, &key);
 
@@ -128,45 +123,11 @@ grub_console_checkkey (struct grub_term_input *term __attribute__ ((unused)))
     return -1;
 
   if (key.scan_code == 0)
-    read_key = key.unicode_char;
+    return key.unicode_char;
   else if (key.scan_code < ARRAY_SIZE (efi_codes))
-    read_key = efi_codes[key.scan_code];
-
-  return read_key;
-}
-
-static int
-grub_console_getkey (struct grub_term_input *term)
-{
-  grub_efi_simple_input_interface_t *i;
-  grub_efi_boot_services_t *b;
-  grub_efi_uintn_t index;
-  grub_efi_status_t status;
-  int key;
-
-  if (read_key >= 0)
-    {
-      key = read_key;
-      read_key = -1;
-      return key;
-    }
-
-  i = grub_efi_system_table->con_in;
-  b = grub_efi_system_table->boot_services;
-
-  do
-    {
-      status = efi_call_3 (b->wait_for_event, 1, &(i->wait_for_key), &index);
-      if (status != GRUB_EFI_SUCCESS)
-        return -1;
-
-      grub_console_checkkey (term);
-    }
-  while (read_key < 0);
+    return efi_codes[key.scan_code];
 
-  key = read_key;
-  read_key = -1;
-  return key;
+  return -1;
 }
 
 static grub_uint16_t
@@ -268,7 +229,6 @@ grub_efi_console_fini (struct grub_term_output *term)
 static struct grub_term_input grub_console_term_input =
   {
     .name = "console",
-    .checkkey = grub_console_checkkey,
     .getkey = grub_console_getkey,
   };
 
index 009647c4c6c0d8945c4c01c2886cd894adb27911..0efeafe4e8f35d63d151b66046628c212bf38dae 100644 (file)
@@ -34,7 +34,6 @@ grub_console_getkeystatus (struct grub_term_input *term __attribute__ ((unused))
 static struct grub_term_input grub_console_term_input =
   {
     .name = "console",
-    .checkkey = grub_console_checkkey,
     .getkey = grub_console_getkey,
     .getkeystatus = grub_console_getkeystatus
   };
index 604906ceb6690d285389e9ce931574d3cd71e45e..e6550254f0430e4a7f855348d3138181636df4d4 100644 (file)
@@ -189,7 +189,6 @@ static struct grub_term_input grub_ofconsole_term_input =
   {
     .name = "ofconsole",
     .init = grub_ofconsole_init_input,
-    .checkkey = grub_terminfo_checkkey,
     .getkey = grub_terminfo_getkey,
     .data = &grub_ofconsole_terminfo_input
   };
index 2268788af25143d4210e224b3152672f5ff31af5..f435a7bc5a1670de61d679f1f795046f6f09b2c7 100644 (file)
@@ -99,7 +99,6 @@ static struct grub_term_input grub_serial_term_input =
 {
   .name = "serial",
   .init = grub_terminfo_input_init,
-  .checkkey = grub_terminfo_checkkey,
   .getkey = grub_terminfo_getkey,
   .data = &grub_serial_terminfo_input
 };
index 5379aac0c041fed578436c7b89eed45f3d709c1f..d2d821449e9f047b0b40064245547fc5ae4e2d50 100644 (file)
@@ -467,41 +467,32 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
 #undef CONTINUE_READ
 }
 
-/* The terminfo version of checkkey.  */
+/* The terminfo version of getkey.  */
 int
-grub_terminfo_checkkey (struct grub_term_input *termi)
+grub_terminfo_getkey (struct grub_term_input *termi)
 {
   struct grub_terminfo_input_state *data
     = (struct grub_terminfo_input_state *) (termi->data);
   if (data->npending)
-    return data->input_buf[0];
+    {
+      data->npending--;
+      grub_memmove (data->input_buf, data->input_buf + 1, data->npending);
+      return data->input_buf[0];
+    }
 
   grub_terminfo_readkey (termi, data->input_buf,
                         &data->npending, data->readkey);
 
   if (data->npending)
-    return data->input_buf[0];
+    {
+      data->npending--;
+      grub_memmove (data->input_buf, data->input_buf + 1, data->npending);
+      return data->input_buf[0];
+    }
 
   return -1;
 }
 
-/* The terminfo version of getkey.  */
-int
-grub_terminfo_getkey (struct grub_term_input *termi)
-{
-  struct grub_terminfo_input_state *data
-    = (struct grub_terminfo_input_state *) (termi->data);
-  int ret;
-  while (! data->npending)
-    grub_terminfo_readkey (termi, data->input_buf, &data->npending,
-                          data->readkey);
-
-  ret = data->input_buf[0];
-  data->npending--;
-  grub_memmove (data->input_buf, data->input_buf + 1, data->npending);
-  return ret;
-}
-
 grub_err_t
 grub_terminfo_input_init (struct grub_term_input *termi)
 {
index b57b171f89804a6aedccdbc67d011403a2a2385b..ca3a81179e8de8d1b1a4416cbc4a3784e447a8d1 100644 (file)
@@ -68,7 +68,6 @@ struct grub_usb_keyboard_data
   grub_usb_device_t usbdev;
   grub_uint8_t status;
   grub_uint16_t mods;
-  int key;
   int interfno;
   struct grub_usb_desc_endp *endp;
   grub_usb_transfer_t transfer;
@@ -78,15 +77,11 @@ struct grub_usb_keyboard_data
   grub_uint64_t repeat_time;
 };
 
-static struct grub_term_input grub_usb_keyboards[16];
-
-static int grub_usb_keyboard_checkkey (struct grub_term_input *term);
 static int grub_usb_keyboard_getkey (struct grub_term_input *term);
 static int grub_usb_keyboard_getkeystatus (struct grub_term_input *term);
 
 static struct grub_term_input grub_usb_keyboard_term =
   {
-    .checkkey = grub_usb_keyboard_checkkey,
     .getkey = grub_usb_keyboard_getkey,
     .getkeystatus = grub_usb_keyboard_getkeystatus,
     .next = 0
@@ -231,19 +226,12 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
                                USB_HID_GET_REPORT, 0x0100, interfno,
                                sizeof (report), (char *) report);
     if (err)
-      {
-       data->status = 0;
-       data->key = -1;
-      }
+      data->status = 0;
     else
-      {
-       data->status = report[0];
-       data->key = report[2] ? : -1;
-      }
+      data->status = report[0];
   }
 #else
   data->status = 0;
-  data->key = -1;
 #endif
 
   data->transfer = grub_usb_bulk_read_background (usbdev,
@@ -283,16 +271,13 @@ send_leds (struct grub_usb_keyboard_data *termdata)
 }
 
 static int
-grub_usb_keyboard_checkkey (struct grub_term_input *term)
+grub_usb_keyboard_getkey (struct grub_term_input *term)
 {
   grub_usb_err_t err;
   struct grub_usb_keyboard_data *termdata = term->data;
   grub_uint8_t data[sizeof (termdata->report)];
   grub_size_t actual;
 
-  if (termdata->key != -1)
-    return termdata->key;
-
   if (termdata->dead)
     return -1;
 
@@ -304,11 +289,11 @@ grub_usb_keyboard_checkkey (struct grub_term_input *term)
       if (termdata->last_key != -1
          && grub_get_time_ms () > termdata->repeat_time)
        {
-         termdata->key = termdata->last_key;
          termdata->repeat_time = grub_get_time_ms ()
            + GRUB_TERM_REPEAT_INTERVAL;
+         return termdata->last_key;
        }
-      return termdata->key;
+      return -1;
     }
 
   grub_memcpy (data, termdata->report, sizeof (data));
@@ -358,29 +343,13 @@ grub_usb_keyboard_checkkey (struct grub_term_input *term)
       return -1;
     }
 
-  termdata->last_key = termdata->key
-    = grub_term_map_key (data[2], interpret_status (data[0]) | termdata->mods);
+  termdata->last_key = grub_term_map_key (data[2], interpret_status (data[0])
+                                         | termdata->mods);
   termdata->repeat_time = grub_get_time_ms () + GRUB_TERM_REPEAT_PRE_INTERVAL;
 
   grub_errno = GRUB_ERR_NONE;
 
-  return termdata->key;
-}
-
-static int
-grub_usb_keyboard_getkey (struct grub_term_input *term)
-{
-  int ret;
-  struct grub_usb_keyboard_data *termdata = term->data;
-
-  while (termdata->key == -1)
-    grub_usb_keyboard_checkkey (term);
-
-  ret = termdata->key;
-
-  termdata->key = -1;
-
-  return ret;
+  return termdata->last_key;
 }
 
 static int
@@ -388,8 +357,6 @@ grub_usb_keyboard_getkeystatus (struct grub_term_input *term)
 {
   struct grub_usb_keyboard_data *termdata = term->data;
 
-  grub_usb_keyboard_checkkey (term);
-
   return interpret_status (termdata->status) | termdata->mods;
 }