mirror of https://github.com/ipxe/ipxe.git
[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>pull/1/head
parent
b9326c3655
commit
f98cf7d70f
|
@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <realmode.h>
|
#include <realmode.h>
|
||||||
#include <ipxe/console.h>
|
#include <ipxe/console.h>
|
||||||
#include <ipxe/ansiesc.h>
|
#include <ipxe/ansiesc.h>
|
||||||
|
#include <ipxe/keymap.h>
|
||||||
|
|
||||||
#define ATTR_BOLD 0x08
|
#define ATTR_BOLD 0x08
|
||||||
|
|
||||||
|
@ -228,6 +229,22 @@ static const char * scancode_to_ansi_seq ( unsigned int scancode ) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a key
|
||||||
|
*
|
||||||
|
* @v character Character read from console
|
||||||
|
* @ret character Mapped character
|
||||||
|
*/
|
||||||
|
static int bios_keymap ( unsigned int character ) {
|
||||||
|
struct key_mapping *mapping;
|
||||||
|
|
||||||
|
for_each_table_entry ( mapping, KEYMAP ) {
|
||||||
|
if ( mapping->from == character )
|
||||||
|
return mapping->to;
|
||||||
|
}
|
||||||
|
return character;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get character from BIOS console
|
* Get character from BIOS console
|
||||||
*
|
*
|
||||||
|
@ -251,9 +268,9 @@ static int bios_getchar ( void ) {
|
||||||
: "=a" ( keypress ) : "a" ( 0x1000 ) );
|
: "=a" ( keypress ) : "a" ( 0x1000 ) );
|
||||||
character = ( keypress & 0xff );
|
character = ( keypress & 0xff );
|
||||||
|
|
||||||
/* If it's a normal character, just return it */
|
/* If it's a normal character, just map and return it */
|
||||||
if ( character && ( character < 0x80 ) )
|
if ( character && ( character < 0x80 ) )
|
||||||
return character;
|
return bios_keymap ( character );
|
||||||
|
|
||||||
/* Otherwise, check for a special key that we know about */
|
/* Otherwise, check for a special key that we know about */
|
||||||
if ( ( ansi_seq = scancode_to_ansi_seq ( keypress >> 8 ) ) ) {
|
if ( ( ansi_seq = scancode_to_ansi_seq ( keypress >> 8 ) ) ) {
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef _IPXE_KEYMAP_H
|
||||||
|
#define _IPXE_KEYMAP_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
*
|
||||||
|
* Keyboard mappings
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ipxe/tables.h>
|
||||||
|
|
||||||
|
/** A keyboard mapping */
|
||||||
|
struct key_mapping {
|
||||||
|
/** Character read from keyboard */
|
||||||
|
uint8_t from;
|
||||||
|
/** Character to be used instead */
|
||||||
|
uint8_t to;
|
||||||
|
} __attribute__ (( packed ));
|
||||||
|
|
||||||
|
/** Keyboard mapping table */
|
||||||
|
#define KEYMAP __table ( struct key_mapping, "keymap" )
|
||||||
|
|
||||||
|
/** Define a keyboard mapping */
|
||||||
|
#define __keymap __table_entry ( KEYMAP, 01 )
|
||||||
|
|
||||||
|
#endif /* _IPXE_KEYMAP_H */
|
Loading…
Reference in New Issue