Browse Source

[console] Add facility for rudimentary keyboard mapping

Allow for remapping of ASCII characters returned by the BIOS, using a
map consisting of (from,to) pairs.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
f98cf7d70f
2 changed files with 49 additions and 2 deletions
  1. 19
    2
      src/arch/i386/firmware/pcbios/bios_console.c
  2. 30
    0
      src/include/ipxe/keymap.h

+ 19
- 2
src/arch/i386/firmware/pcbios/bios_console.c View File

@@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
22 22
 #include <realmode.h>
23 23
 #include <ipxe/console.h>
24 24
 #include <ipxe/ansiesc.h>
25
+#include <ipxe/keymap.h>
25 26
 
26 27
 #define ATTR_BOLD		0x08
27 28
 
@@ -228,6 +229,22 @@ static const char * scancode_to_ansi_seq ( unsigned int scancode ) {
228 229
 	return NULL;
229 230
 }
230 231
 
232
+/**
233
+ * Map a key
234
+ *
235
+ * @v character		Character read from console
236
+ * @ret character	Mapped character
237
+ */
238
+static int bios_keymap ( unsigned int character ) {
239
+	struct key_mapping *mapping;
240
+
241
+	for_each_table_entry ( mapping, KEYMAP ) {
242
+		if ( mapping->from == character )
243
+			return mapping->to;
244
+	}
245
+	return character;
246
+}
247
+
231 248
 /**
232 249
  * Get character from BIOS console
233 250
  *
@@ -251,9 +268,9 @@ static int bios_getchar ( void ) {
251 268
 			       : "=a" ( keypress ) : "a" ( 0x1000 ) );
252 269
 	character = ( keypress & 0xff );
253 270
 
254
-	/* If it's a normal character, just return it */
271
+	/* If it's a normal character, just map and return it */
255 272
 	if ( character && ( character < 0x80 ) )
256
-		return character;
273
+		return bios_keymap ( character );
257 274
 
258 275
 	/* Otherwise, check for a special key that we know about */
259 276
 	if ( ( ansi_seq = scancode_to_ansi_seq ( keypress >> 8 ) ) ) {

+ 30
- 0
src/include/ipxe/keymap.h View File

@@ -0,0 +1,30 @@
1
+#ifndef _IPXE_KEYMAP_H
2
+#define _IPXE_KEYMAP_H
3
+
4
+/**
5
+ * @file
6
+ *
7
+ * Keyboard mappings
8
+ *
9
+ */
10
+
11
+FILE_LICENCE ( GPL2_OR_LATER );
12
+
13
+#include <stdint.h>
14
+#include <ipxe/tables.h>
15
+
16
+/** A keyboard mapping */
17
+struct key_mapping {
18
+	/** Character read from keyboard */
19
+	uint8_t from;
20
+	/** Character to be used instead */
21
+	uint8_t to;
22
+} __attribute__ (( packed ));
23
+
24
+/** Keyboard mapping table */
25
+#define KEYMAP __table ( struct key_mapping, "keymap" )
26
+
27
+/** Define a keyboard mapping */
28
+#define __keymap __table_entry ( KEYMAP, 01 )
29
+
30
+#endif /* _IPXE_KEYMAP_H */

Loading…
Cancel
Save