summaryrefslogtreecommitdiff
path: root/payloads/libpayload/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/drivers')
-rw-r--r--payloads/libpayload/drivers/keyboard.c65
1 files changed, 56 insertions, 9 deletions
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();