Macroify GRUB_TERM_NO_KEY and use grub_checkkey in grub_getkey
This commit is contained in:
parent
df2174dded
commit
9518e2a12b
7 changed files with 39 additions and 47 deletions
|
@ -19,6 +19,8 @@
|
|||
#ifndef GRUB_TERM_HEADER
|
||||
#define GRUB_TERM_HEADER 1
|
||||
|
||||
#define GRUB_TERM_NO_KEY -1
|
||||
|
||||
/* Internal codes used by GRUB to represent terminal input. */
|
||||
/* Only for keys otherwise not having shifted modification. */
|
||||
#define GRUB_TERM_SHIFT 0x01000000
|
||||
|
|
|
@ -1226,6 +1226,9 @@ notpending:
|
|||
.code16
|
||||
DATA32 call real_to_prot
|
||||
.code32
|
||||
#if GRUB_TERM_NO_KEY != -1
|
||||
#error Fix this asm code
|
||||
#endif
|
||||
decl %eax
|
||||
jmp 2b
|
||||
|
||||
|
|
50
kern/term.c
50
kern/term.c
|
@ -78,43 +78,14 @@ grub_xputs_dumb (const char *str)
|
|||
|
||||
void (*grub_xputs) (const char *str) = grub_xputs_dumb;
|
||||
|
||||
static int pending_key = -1;
|
||||
|
||||
int
|
||||
grub_getkey (void)
|
||||
{
|
||||
grub_term_input_t term;
|
||||
|
||||
grub_refresh ();
|
||||
|
||||
if (pending_key != -1)
|
||||
{
|
||||
pending_key = -1;
|
||||
return pending_key;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (grub_term_poll_usb)
|
||||
grub_term_poll_usb ();
|
||||
|
||||
FOR_ACTIVE_TERM_INPUTS(term)
|
||||
{
|
||||
int key = term->getkey (term);
|
||||
if (key != -1)
|
||||
return key;
|
||||
}
|
||||
|
||||
grub_cpu_idle ();
|
||||
}
|
||||
}
|
||||
static int pending_key = GRUB_TERM_NO_KEY;
|
||||
|
||||
int
|
||||
grub_checkkey (void)
|
||||
{
|
||||
grub_term_input_t term;
|
||||
|
||||
if (pending_key != -1)
|
||||
if (pending_key != GRUB_TERM_NO_KEY)
|
||||
return pending_key;
|
||||
|
||||
if (grub_term_poll_usb)
|
||||
|
@ -123,13 +94,28 @@ grub_checkkey (void)
|
|||
FOR_ACTIVE_TERM_INPUTS(term)
|
||||
{
|
||||
pending_key = term->getkey (term);
|
||||
if (pending_key != -1)
|
||||
if (pending_key != GRUB_TERM_NO_KEY)
|
||||
return pending_key;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
grub_getkey (void)
|
||||
{
|
||||
grub_refresh ();
|
||||
|
||||
while (pending_key != GRUB_TERM_NO_KEY)
|
||||
{
|
||||
grub_cpu_idle ();
|
||||
grub_checkkey ();
|
||||
}
|
||||
pending_key = GRUB_TERM_NO_KEY;
|
||||
return pending_key;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_refresh (void)
|
||||
{
|
||||
|
|
|
@ -475,14 +475,15 @@ grub_keyboard_getkey (void)
|
|||
return key;
|
||||
}
|
||||
|
||||
/* If there is a character pending, return it; otherwise return -1. */
|
||||
/* If there is a character pending, return it;
|
||||
otherwise return GRUB_TERM_NO_KEY. */
|
||||
static int
|
||||
grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
||||
{
|
||||
int code;
|
||||
code = grub_keyboard_getkey ();
|
||||
if (code == -1)
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
#ifdef DEBUG_AT_KEYBOARD
|
||||
grub_dprintf ("atkeyb", "Detected key 0x%x\n", key);
|
||||
#endif
|
||||
|
@ -496,7 +497,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
|||
#ifdef DEBUG_AT_KEYBOARD
|
||||
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
|
||||
#endif
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
case GRUB_KEYBOARD_KEY_NUM_LOCK:
|
||||
at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
|
||||
led_status ^= KEYBOARD_LED_NUM;
|
||||
|
@ -505,12 +506,12 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
|||
#ifdef DEBUG_AT_KEYBOARD
|
||||
grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_NUM_LOCK));
|
||||
#endif
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
|
||||
at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
|
||||
led_status ^= KEYBOARD_LED_SCROLL;
|
||||
keyboard_controller_led (led_status);
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
default:
|
||||
return grub_term_map_key (code, at_keyboard_status);
|
||||
}
|
||||
|
|
|
@ -120,14 +120,14 @@ grub_console_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
|||
status = efi_call_2 (i->read_key_stroke, i, &key);
|
||||
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
|
||||
if (key.scan_code == 0)
|
||||
return key.unicode_char;
|
||||
else if (key.scan_code < ARRAY_SIZE (efi_codes))
|
||||
return efi_codes[key.scan_code];
|
||||
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
static grub_uint16_t
|
||||
|
|
|
@ -490,7 +490,7 @@ grub_terminfo_getkey (struct grub_term_input *termi)
|
|||
return data->input_buf[0];
|
||||
}
|
||||
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
|
|
|
@ -279,7 +279,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
|
|||
grub_size_t actual;
|
||||
|
||||
if (termdata->dead)
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
|
||||
/* Poll interrupt pipe. */
|
||||
err = grub_usb_check_transfer (termdata->transfer, &actual);
|
||||
|
@ -293,7 +293,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
|
|||
+ GRUB_TERM_REPEAT_INTERVAL;
|
||||
return termdata->last_key;
|
||||
}
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
grub_memcpy (data, termdata->report, sizeof (data));
|
||||
|
@ -318,29 +318,29 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
|
|||
data[4], data[5], data[6], data[7]);
|
||||
|
||||
if (err || actual < 1)
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
|
||||
termdata->status = data[0];
|
||||
|
||||
if (actual < 3)
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
|
||||
if (data[2] == KEY_NO_KEY || data[2] == KEY_ERR_BUFFER
|
||||
|| data[2] == KEY_ERR_POST || data[2] == KEY_ERR_UNDEF)
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
|
||||
if (data[2] == KEY_CAPS_LOCK)
|
||||
{
|
||||
termdata->mods ^= GRUB_TERM_STATUS_CAPS;
|
||||
send_leds (termdata);
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
if (data[2] == KEY_NUM_LOCK)
|
||||
{
|
||||
termdata->mods ^= GRUB_TERM_STATUS_NUM;
|
||||
send_leds (termdata);
|
||||
return -1;
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
termdata->last_key = grub_term_map_key (data[2], interpret_status (data[0])
|
||||
|
|
Loading…
Reference in a new issue