summaryrefslogtreecommitdiff
path: root/payloads
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@coresystems.de>2008-09-17 18:12:46 +0000
committerPatrick Georgi <patrick.georgi@coresystems.de>2008-09-17 18:12:46 +0000
commite6408a36c9dfb98b2c15b66052f12f195e763dbf (patch)
treece892668f079ee618f099369eabe8c02bb653538 /payloads
parent57700ff81f1048d6083299f3a0262d62b4612130 (diff)
- unify keycodes for non-ASCII keys by using curses' codes and labels
- fix ctrl-[a-z] - get rid of curses' ps/2 driver. uses generic one instead - #ifdef's around ps/2 keyboard handling and serial handling - add alt-key handling (necessary for german keymap) - flush keyboard controller buffer on init Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3580 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads')
-rw-r--r--payloads/libpayload/curses/keyboard.c220
-rw-r--r--payloads/libpayload/drivers/keyboard.c65
2 files changed, 76 insertions, 209 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;
diff --git a/payloads/libpayload/drivers/keyboard.c b/payloads/libpayload/drivers/keyboard.c
index 96285d0d15..895c956ec9 100644
--- a/payloads/libpayload/drivers/keyboard.c
+++ b/payloads/libpayload/drivers/keyboard.c
@@ -28,14 +28,15 @@
*/
#include <libpayload.h>
+#include <curses.h>
#define I8042_CMD_READ_MODE 0x20
#define I8042_CMD_WRITE_MODE 0x60
#define I8042_MODE_XLATE 0x40
-unsigned char map[2][0x57] = {
- {
+unsigned short map[4][0x57] = {
+ { /* No modifier */
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
@@ -43,9 +44,12 @@ unsigned char map[2][0x57] = {
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
- 0x00, 0x20,
+ 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, KEY_HOME,
+ KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
+ KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00
},
- {
+ { /* Shift */
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
@@ -53,13 +57,43 @@ unsigned char map[2][0x57] = {
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
- 0x00, 0x20,
+ 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, KEY_HOME,
+ KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
+ KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00
+ },
+ { /* ALT */
+ 0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
+ 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
+ 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
+ 0x6F, 0x70, 0x5B, 0x5D, 0x0A, 0x00, 0x61, 0x73,
+ 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
+ 0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
+ 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
+ 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, KEY_HOME,
+ KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
+ KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00
+ },
+ { /* Shift-ALT */
+ 0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
+ 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
+ 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
+ 0x4F, 0x50, 0x7B, 0x7D, 0x0A, 0x00, 0x41, 0x53,
+ 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
+ 0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
+ 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
+ 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, KEY_HOME,
+ KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
+ KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00
}
};
-#define MOD_SHIFT 1
-#define MOD_CTRL 2
-#define MOD_CAPSLOCK 4
+#define MOD_SHIFT (1 << 0)
+#define MOD_CTRL (1 << 1)
+#define MOD_CAPSLOCK (1 << 2)
+#define MOD_ALT (1 << 3)
int keyboard_havechar(void)
{
@@ -97,6 +131,12 @@ int keyboard_getchar(void)
case 0x80 | 0x2a:
modifier &= ~MOD_SHIFT;
break;
+ case 0x38:
+ modifier |= MOD_ALT;
+ break;
+ case 0x80 | 0x38:
+ modifier &= ~MOD_ALT;
+ break;
case 0x1d:
modifier |= MOD_CTRL;
break;
@@ -114,10 +154,14 @@ int keyboard_getchar(void)
if (!(ch & 0x80) && ch < 0x57) {
shift =
(modifier & MOD_SHIFT) ^ (modifier & MOD_CAPSLOCK) ? 1 : 0;
+
+ if (modifier & MOD_ALT)
+ shift += 2;
+
ret = map[shift][ch];
if (modifier & MOD_CTRL)
- ret = (ret >= 0x3F && ret <= 0x5F) ? ret & 0x1f : 0;
+ ret = (ret >= 'a' && ret <= 'z') ? ret & 0x1f : 0;
return ret;
}
@@ -163,6 +207,9 @@ void keyboard_init(void)
{
u8 mode;
+ /* Empty keyboard buffer */
+ while (keyboard_havechar()) keyboard_getchar();
+
/* Read the current mode */
mode = keyboard_get_mode();