Macroify GRUB_TERM_NO_KEY and use grub_checkkey in grub_getkey

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-08-23 12:53:42 +02:00
parent df2174dded
commit 9518e2a12b
7 changed files with 39 additions and 47 deletions

View file

@ -19,6 +19,8 @@
#ifndef GRUB_TERM_HEADER #ifndef GRUB_TERM_HEADER
#define GRUB_TERM_HEADER 1 #define GRUB_TERM_HEADER 1
#define GRUB_TERM_NO_KEY -1
/* Internal codes used by GRUB to represent terminal input. */ /* Internal codes used by GRUB to represent terminal input. */
/* Only for keys otherwise not having shifted modification. */ /* Only for keys otherwise not having shifted modification. */
#define GRUB_TERM_SHIFT 0x01000000 #define GRUB_TERM_SHIFT 0x01000000

View file

@ -1226,6 +1226,9 @@ notpending:
.code16 .code16
DATA32 call real_to_prot DATA32 call real_to_prot
.code32 .code32
#if GRUB_TERM_NO_KEY != -1
#error Fix this asm code
#endif
decl %eax decl %eax
jmp 2b jmp 2b

View file

@ -78,43 +78,14 @@ grub_xputs_dumb (const char *str)
void (*grub_xputs) (const char *str) = grub_xputs_dumb; void (*grub_xputs) (const char *str) = grub_xputs_dumb;
static int pending_key = -1; static int pending_key = GRUB_TERM_NO_KEY;
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 ();
}
}
int int
grub_checkkey (void) grub_checkkey (void)
{ {
grub_term_input_t term; grub_term_input_t term;
if (pending_key != -1) if (pending_key != GRUB_TERM_NO_KEY)
return pending_key; return pending_key;
if (grub_term_poll_usb) if (grub_term_poll_usb)
@ -123,13 +94,28 @@ grub_checkkey (void)
FOR_ACTIVE_TERM_INPUTS(term) FOR_ACTIVE_TERM_INPUTS(term)
{ {
pending_key = term->getkey (term); pending_key = term->getkey (term);
if (pending_key != -1) if (pending_key != GRUB_TERM_NO_KEY)
return pending_key; return pending_key;
} }
return -1; 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 void
grub_refresh (void) grub_refresh (void)
{ {

View file

@ -475,14 +475,15 @@ grub_keyboard_getkey (void)
return key; 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 static int
grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
{ {
int code; int code;
code = grub_keyboard_getkey (); code = grub_keyboard_getkey ();
if (code == -1) if (code == -1)
return -1; return GRUB_TERM_NO_KEY;
#ifdef DEBUG_AT_KEYBOARD #ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "Detected key 0x%x\n", key); grub_dprintf ("atkeyb", "Detected key 0x%x\n", key);
#endif #endif
@ -496,7 +497,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
#ifdef DEBUG_AT_KEYBOARD #ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK)); grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
#endif #endif
return -1; return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_NUM_LOCK: case GRUB_KEYBOARD_KEY_NUM_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_NUM; at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
led_status ^= KEYBOARD_LED_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 #ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_NUM_LOCK)); grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_NUM_LOCK));
#endif #endif
return -1; return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_SCROLL_LOCK: case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL; at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
led_status ^= KEYBOARD_LED_SCROLL; led_status ^= KEYBOARD_LED_SCROLL;
keyboard_controller_led (led_status); keyboard_controller_led (led_status);
return -1; return GRUB_TERM_NO_KEY;
default: default:
return grub_term_map_key (code, at_keyboard_status); return grub_term_map_key (code, at_keyboard_status);
} }

View file

@ -120,14 +120,14 @@ grub_console_getkey (struct grub_term_input *term __attribute__ ((unused)))
status = efi_call_2 (i->read_key_stroke, i, &key); status = efi_call_2 (i->read_key_stroke, i, &key);
if (status != GRUB_EFI_SUCCESS) if (status != GRUB_EFI_SUCCESS)
return -1; return GRUB_TERM_NO_KEY;
if (key.scan_code == 0) if (key.scan_code == 0)
return key.unicode_char; return key.unicode_char;
else if (key.scan_code < ARRAY_SIZE (efi_codes)) else if (key.scan_code < ARRAY_SIZE (efi_codes))
return efi_codes[key.scan_code]; return efi_codes[key.scan_code];
return -1; return GRUB_TERM_NO_KEY;
} }
static grub_uint16_t static grub_uint16_t

View file

@ -490,7 +490,7 @@ grub_terminfo_getkey (struct grub_term_input *termi)
return data->input_buf[0]; return data->input_buf[0];
} }
return -1; return GRUB_TERM_NO_KEY;
} }
grub_err_t grub_err_t

View file

@ -279,7 +279,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
grub_size_t actual; grub_size_t actual;
if (termdata->dead) if (termdata->dead)
return -1; return GRUB_TERM_NO_KEY;
/* Poll interrupt pipe. */ /* Poll interrupt pipe. */
err = grub_usb_check_transfer (termdata->transfer, &actual); 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; + GRUB_TERM_REPEAT_INTERVAL;
return termdata->last_key; return termdata->last_key;
} }
return -1; return GRUB_TERM_NO_KEY;
} }
grub_memcpy (data, termdata->report, sizeof (data)); 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]); data[4], data[5], data[6], data[7]);
if (err || actual < 1) if (err || actual < 1)
return -1; return GRUB_TERM_NO_KEY;
termdata->status = data[0]; termdata->status = data[0];
if (actual < 3) if (actual < 3)
return -1; return GRUB_TERM_NO_KEY;
if (data[2] == KEY_NO_KEY || data[2] == KEY_ERR_BUFFER if (data[2] == KEY_NO_KEY || data[2] == KEY_ERR_BUFFER
|| data[2] == KEY_ERR_POST || data[2] == KEY_ERR_UNDEF) || data[2] == KEY_ERR_POST || data[2] == KEY_ERR_UNDEF)
return -1; return GRUB_TERM_NO_KEY;
if (data[2] == KEY_CAPS_LOCK) if (data[2] == KEY_CAPS_LOCK)
{ {
termdata->mods ^= GRUB_TERM_STATUS_CAPS; termdata->mods ^= GRUB_TERM_STATUS_CAPS;
send_leds (termdata); send_leds (termdata);
return -1; return GRUB_TERM_NO_KEY;
} }
if (data[2] == KEY_NUM_LOCK) if (data[2] == KEY_NUM_LOCK)
{ {
termdata->mods ^= GRUB_TERM_STATUS_NUM; termdata->mods ^= GRUB_TERM_STATUS_NUM;
send_leds (termdata); send_leds (termdata);
return -1; return GRUB_TERM_NO_KEY;
} }
termdata->last_key = grub_term_map_key (data[2], interpret_status (data[0]) termdata->last_key = grub_term_map_key (data[2], interpret_status (data[0])