summaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/curses/keyboard.c')
-rw-r--r--payloads/libpayload/curses/keyboard.c220
1 files changed, 20 insertions, 200 deletions
diff --git a/payloads/libpayload/curses/keyboard.c b/payloads/libpayload/curses/keyboard.c
index 83215966b7..cfb7b769d7 100644
--- a/payloads/libpayload/curses/keyboard.c
+++ b/payloads/libpayload/curses/keyboard.c
@@ -138,216 +138,36 @@ static int cook_serial(unsigned char ch)
/* ================ Keyboard ================ */
-/* Scancode macros */
-
-#define DOWN(_c) (0x80 | (_c))
-#define UP(_c) (_c)
-
-#define ISDOWN(_c) ((_c) & 0x80)
-#define ISUP(_c) (!ISDOWN((_c)))
-
-#define SCANCODE(_c) ((_c) & ~0x80)
-
-/* Scancode definitions for the modifiers */
-
-#define SCANCODE_RSHIFT 0x36
-#define SCANCODE_LSHIFT 0x2a
-#define SCANCODE_CAPSLOCK 0x3a
-#define SCANCODE_LALT 0x38
-#define SCANCODE_LCTRL 0x1d
-
-/* Modifier flags */
-
-#define SHIFT_MODIFIER 0x1
-#define CAPSLOCK_MODIFIER 0x2
-#define ALT_MODIFIER 0x4
-#define CTRL_MODIFIER 0x8
-
-#define CTRL(_c) (_c & 0x1f)
-
-struct {
- int normal;
- int shift;
-} scancode_map[] = {
- { },
- { CTRL('['), CTRL('[')},
- { '1', '!' },
- { '2', '@' },
- { '3', '#' },
- { '4', '$' },
- { '5', '%' },
- { '6', '^' },
- { '7', '&' },
- { '8', '*' },
- { '9', '(' },
- { '0', ')' },
- { '-', '_' },
- { '=', '+' },
- { KEY_BACKSPACE, KEY_BACKSPACE},
- { CTRL('I' ), KEY_BTAB }, /* 0x0F */
- { 'q', 'Q' },
- { 'w', 'W' },
- { 'e', 'E' },
- { 'r', 'R' },
- { 't', 'T' },
- { 'y', 'Y' },
- { 'u', 'U' },
- { 'i', 'I' },
- { 'o', 'O' },
- { 'p', 'P' },
- { '[', '{' },
- { ']', '{' },
- { KEY_ENTER, KEY_ENTER },
- { 0 , 0 },
- { 'a', 'A' },
- { 's', 'S' }, /* 0x1F */
- { 'd', 'D' },
- { 'f', 'F' },
- { 'g', 'G' },
- { 'h', 'H' },
- { 'j', 'J' },
- { 'k', 'K' },
- { 'l', 'L' },
- { ';', ':' },
- { '\'', '\"' },
- { '`', '~', },
- { 0, 0 },
- { '\\', '|' },
- { 'z', 'Z' },
- { 'x', 'X' },
- { 'c', 'C' },
- { 'v', 'V' }, /* 0x2F */
- { 'b', 'B' },
- { 'n', 'N' },
- { 'm', 'M' },
- { ',', '<'},
- { '.', '>' },
- { '/', '?' },
- { 0, 0 }, /* RSHIFT */
- { '*', '*' },
- { 0, 0 }, /* LALT */
- { ' ', ' ' }, /* Space */
- { 0, 0 }, /* Capslock */
- { KEY_F(1), KEY_F(1) },
- { KEY_F(2), KEY_F(2) },
- { KEY_F(3), KEY_F(3) },
- { KEY_F(4), KEY_F(4) },
- { KEY_F(5), KEY_F(5) }, /* 0x3F */
- { KEY_F(6), KEY_F(6) },
- { KEY_F(7), KEY_F(7) },
- { KEY_F(8), KEY_F(8) },
- { KEY_F(9), KEY_F(9) },
- { KEY_F(10), KEY_F(10) },
- { 0, 0 }, /* Numlock */
- { 0, 0 }, /* Scroll lock */
- { KEY_HOME, KEY_HOME },
- { KEY_UP, KEY_UP },
- { KEY_PPAGE, KEY_PPAGE },
- { '-', '-' },
- { KEY_LEFT, KEY_LEFT },
- { 0, 0 },
- { KEY_RIGHT, KEY_RIGHT },
- { '-', '-' },
- { KEY_END, KEY_END }, /* 0x4F */
- { KEY_DOWN, KEY_DOWN },
- { KEY_NPAGE, KEY_NPAGE },
- { KEY_IC, KEY_IC },
- { KEY_DC, KEY_DC },
- { 0, 0 }, /* sysreq */
- { 0, 0 },
- { KEY_F(11), KEY_F(11) },
- { KEY_F(12), KEY_F(12) },
-};
-
-static int cook_scancodes(unsigned char code)
-{
- static int modifiers = 0;
- int ch = 0, sc, shift;
-
- switch (code) {
- case DOWN(SCANCODE_RSHIFT):
- case DOWN(SCANCODE_LSHIFT):
- modifiers |= SHIFT_MODIFIER;
- return 0;
- case UP(SCANCODE_RSHIFT):
- case UP(SCANCODE_LSHIFT):
- modifiers &= ~SHIFT_MODIFIER;
- return 0;
- case UP(SCANCODE_CAPSLOCK):
- if (modifiers & CAPSLOCK_MODIFIER)
- modifiers &= ~CAPSLOCK_MODIFIER;
- else
- modifiers |= CAPSLOCK_MODIFIER;
- return 0;
- case DOWN(SCANCODE_LALT):
- modifiers |= ALT_MODIFIER;
- return 0;
- case UP(SCANCODE_LALT):
- modifiers &= ~ALT_MODIFIER;
- return 0;
- case DOWN(SCANCODE_LCTRL):
- modifiers |= CTRL_MODIFIER;
- return 0;
- case UP(SCANCODE_LCTRL):
- modifiers &= ~CTRL_MODIFIER;
- return 0;
- }
-
- /* Only process keys on an upstroke. */
- if (!ISUP(code))
- return 0;
-
- sc = SCANCODE(code);
-
- if (sc == 0 || sc > 0x59)
- return ERR;
-
- shift = (modifiers & SHIFT_MODIFIER) ^ (modifiers & CAPSLOCK_MODIFIER);
-
- ch = shift ? scancode_map[sc].shift : scancode_map[sc].normal;
-
- if (modifiers & CTRL_MODIFIER)
- ch = (ch >= 0x3F && ch <= 0x5F) ? CTRL(ch) : 0;
-
- return ch;
-}
-
static int curses_getchar(int delay)
{
- unsigned char c = 0;
- int ret;
+ unsigned short c;
do {
- if (curses_flags & F_ENABLE_CONSOLE)
- c = inb(0x64);
-
- if ((c & 1) == 0) {
-
- if ((curses_flags & F_ENABLE_SERIAL) &&
- serial_havechar()) {
- c = serial_getchar();
- return cook_serial(c);
- }
-
- if (delay == 0)
- break;
-
- if (delay > 0) {
- mdelay(100);
- delay--;
- }
-
- continue;
+#ifdef CONFIG_PC_KEYBOARD
+ if ((curses_flags & F_ENABLE_CONSOLE) &&
+ keyboard_havechar()) {
+ c = keyboard_getchar();
+ if (c != 0) return c;
}
+#endif
- c = inb(0x60);
+#ifdef CONFIG_SERIAL_CONSOLE
+ if ((curses_flags & F_ENABLE_SERIAL) &&
+ serial_havechar()) {
+ c = serial_getchar();
+ return cook_serial(c);
+ }
+#endif
- ret = cook_scancodes(c);
+ if (delay == 0)
+ break;
- if (ret != 0) {
- return ret;
+ if (delay > 0) {
+ mdelay(100);
+ delay--;
}
+
} while (1);
return ERR;