iPXE
efi_console.c File Reference
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/ConsoleControl/ConsoleControl.h>
#include <ipxe/ansiesc.h>
#include <ipxe/utf8.h>
#include <ipxe/console.h>
#include <ipxe/keymap.h>
#include <ipxe/init.h>
#include <config/console.h>

Go to the source code of this file.

Macros

#define ATTR_BOLD   0x08
#define ATTR_FCOL_MASK   0x07
#define ATTR_FCOL_BLACK   0x00
#define ATTR_FCOL_BLUE   0x01
#define ATTR_FCOL_GREEN   0x02
#define ATTR_FCOL_CYAN   0x03
#define ATTR_FCOL_RED   0x04
#define ATTR_FCOL_MAGENTA   0x05
#define ATTR_FCOL_YELLOW   0x06
#define ATTR_FCOL_WHITE   0x07
#define ATTR_BCOL_MASK   0x70
#define ATTR_BCOL_BLACK   0x00
#define ATTR_BCOL_BLUE   0x10
#define ATTR_BCOL_GREEN   0x20
#define ATTR_BCOL_CYAN   0x30
#define ATTR_BCOL_RED   0x40
#define ATTR_BCOL_MAGENTA   0x50
#define ATTR_BCOL_YELLOW   0x60
#define ATTR_BCOL_WHITE   0x70
#define ATTR_DEFAULT   ATTR_FCOL_WHITE
#define CONSOLE_EFI   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 FILE_SECBOOT (PERMITTED)
 EFI_REQUEST_PROTOCOL (EFI_CONSOLE_CONTROL_PROTOCOL, &conctrl)
static void efi_handle_cup (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[])
 Handle ANSI CUP (cursor position)
static void efi_handle_ed (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
 Handle ANSI ED (erase in page)
static void efi_handle_sgr (struct ansiesc_context *ctx __unused, unsigned int count, int params[])
 Handle ANSI SGR (set graphics rendition)
static void efi_handle_dectcem_set (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
 Handle ANSI DECTCEM set (show cursor)
static void efi_handle_dectcem_reset (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
 Handle ANSI DECTCEM reset (hide cursor)
static void efi_putchar (int character)
 Print a character to EFI console.
static const char * scancode_to_ansi_seq (unsigned int scancode)
 Get ANSI escape sequence corresponding to EFI scancode.
static int efi_getchar (void)
 Get character from EFI console.
static int efi_iskey (void)
 Check for character ready to read from EFI console.
static void efi_console_init (void)
 Initialise EFI console.
struct init_fn efi_console_init_fn __init_fn (INIT_EARLY)
 EFI console initialisation function.

Variables

static unsigned int efi_attr = ATTR_DEFAULT
 Current character attribute.
static EFI_CONSOLE_CONTROL_PROTOCOLconctrl
 Console control protocol.
static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOLefi_conin_ex
 Extended simple text input protocol, if present.
static struct ansiesc_handler efi_ansiesc_handlers []
 EFI console ANSI escape sequence handlers.
static struct ansiesc_context efi_ansiesc_ctx
 EFI console ANSI escape sequence context.
static struct utf8_accumulator efi_utf8_acc
 EFI console UTF-8 accumulator.
static const char * ansi_input = ""
 Pointer to current ANSI output sequence.
static const char * ansi_sequences []
 Mapping from EFI scan codes to ANSI escape sequences.
struct console_driver efi_console __console_driver
 EFI console driver.

Macro Definition Documentation

◆ ATTR_BOLD

#define ATTR_BOLD   0x08

Definition at line 36 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_MASK

#define ATTR_FCOL_MASK   0x07

Definition at line 38 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_BLACK

#define ATTR_FCOL_BLACK   0x00

Definition at line 39 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_BLUE

#define ATTR_FCOL_BLUE   0x01

Definition at line 40 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_GREEN

#define ATTR_FCOL_GREEN   0x02

Definition at line 41 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_CYAN

#define ATTR_FCOL_CYAN   0x03

Definition at line 42 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_RED

#define ATTR_FCOL_RED   0x04

Definition at line 43 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_MAGENTA

#define ATTR_FCOL_MAGENTA   0x05

Definition at line 44 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_YELLOW

#define ATTR_FCOL_YELLOW   0x06

Definition at line 45 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_FCOL_WHITE

#define ATTR_FCOL_WHITE   0x07

Definition at line 46 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_MASK

#define ATTR_BCOL_MASK   0x70

Definition at line 48 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_BLACK

#define ATTR_BCOL_BLACK   0x00

Definition at line 49 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_BLUE

#define ATTR_BCOL_BLUE   0x10

Definition at line 50 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_GREEN

#define ATTR_BCOL_GREEN   0x20

Definition at line 51 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_CYAN

#define ATTR_BCOL_CYAN   0x30

Definition at line 52 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_RED

#define ATTR_BCOL_RED   0x40

Definition at line 53 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_MAGENTA

#define ATTR_BCOL_MAGENTA   0x50

Definition at line 54 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_YELLOW

#define ATTR_BCOL_YELLOW   0x60

Definition at line 55 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_BCOL_WHITE

#define ATTR_BCOL_WHITE   0x70

Definition at line 56 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ ATTR_DEFAULT

#define ATTR_DEFAULT   ATTR_FCOL_WHITE

Definition at line 58 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

◆ CONSOLE_EFI

#define CONSOLE_EFI   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Definition at line 63 of file efi_console.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ EFI_REQUEST_PROTOCOL()

EFI_REQUEST_PROTOCOL ( EFI_CONSOLE_CONTROL_PROTOCOL ,
& conctrl )

References conctrl.

◆ efi_handle_cup()

void efi_handle_cup ( struct ansiesc_context *ctx __unused,
unsigned int count __unused,
int params[] )
static

Handle ANSI CUP (cursor position)

Parameters
ctxANSI escape sequence context
countParameter count
params[0]Row (1 is top)
params[1]Column (1 is left)

Definition at line 84 of file efi_console.c.

85 {
87 int cx = ( params[1] - 1 );
88 int cy = ( params[0] - 1 );
89
90 if ( cx < 0 )
91 cx = 0;
92 if ( cy < 0 )
93 cy = 0;
94
95 conout->SetCursorPosition ( conout, cx, cy );
96}
struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
EFI_SYSTEM_TABLE * efi_systab
uint16_t cx
Definition registers.h:37
EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition

References __unused, count, ctx, cx, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetCursorPosition.

◆ efi_handle_ed()

void efi_handle_ed ( struct ansiesc_context *ctx __unused,
unsigned int count __unused,
int params[] __unused )
static

Handle ANSI ED (erase in page)

Parameters
ctxANSI escape sequence context
countParameter count
params[0]Region to erase

Definition at line 105 of file efi_console.c.

107 {
109
110 /* We assume that we always clear the whole screen */
111 assert ( params[0] == ANSIESC_ED_ALL );
112
113 conout->ClearScreen ( conout );
114}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define ANSIESC_ED_ALL
Erase whole page.
Definition ansiesc.h:116
EFI_TEXT_CLEAR_SCREEN ClearScreen

References __unused, ANSIESC_ED_ALL, assert, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::ClearScreen, count, ctx, and efi_systab.

◆ efi_handle_sgr()

void efi_handle_sgr ( struct ansiesc_context *ctx __unused,
unsigned int count,
int params[] )
static

Handle ANSI SGR (set graphics rendition)

Parameters
ctxANSI escape sequence context
countParameter count
paramsList of graphic rendition aspects

Definition at line 123 of file efi_console.c.

124 {
126 static const uint8_t efi_attr_fcols[10] = {
130 ATTR_FCOL_WHITE, ATTR_FCOL_WHITE /* defaults */
131 };
132 static const uint8_t efi_attr_bcols[10] = {
136 ATTR_BCOL_BLACK, ATTR_BCOL_BLACK /* defaults */
137 };
138 unsigned int i;
139 int aspect;
140
141 for ( i = 0 ; i < count ; i++ ) {
142 aspect = params[i];
143 if ( aspect == 0 ) {
145 } else if ( aspect == 1 ) {
147 } else if ( aspect == 22 ) {
149 } else if ( ( aspect >= 30 ) && ( aspect <= 39 ) ) {
151 efi_attr |= efi_attr_fcols[ aspect - 30 ];
152 } else if ( ( aspect >= 40 ) && ( aspect <= 49 ) ) {
154 efi_attr |= efi_attr_bcols[ aspect - 40 ];
155 }
156 }
157
158 conout->SetAttribute ( conout, efi_attr );
159}
unsigned char uint8_t
Definition stdint.h:10
#define ATTR_FCOL_BLACK
Definition efi_console.c:39
#define ATTR_BCOL_CYAN
Definition efi_console.c:52
#define ATTR_FCOL_YELLOW
Definition efi_console.c:45
#define ATTR_BCOL_GREEN
Definition efi_console.c:51
#define ATTR_BOLD
Definition efi_console.c:36
#define ATTR_FCOL_MAGENTA
Definition efi_console.c:44
#define ATTR_BCOL_BLACK
Definition efi_console.c:49
#define ATTR_BCOL_WHITE
Definition efi_console.c:56
#define ATTR_FCOL_WHITE
Definition efi_console.c:46
#define ATTR_FCOL_CYAN
Definition efi_console.c:42
#define ATTR_BCOL_BLUE
Definition efi_console.c:50
#define ATTR_BCOL_MAGENTA
Definition efi_console.c:54
static unsigned int efi_attr
Current character attribute.
Definition efi_console.c:67
#define ATTR_BCOL_YELLOW
Definition efi_console.c:55
#define ATTR_FCOL_BLUE
Definition efi_console.c:40
#define ATTR_BCOL_RED
Definition efi_console.c:53
#define ATTR_FCOL_GREEN
Definition efi_console.c:41
#define ATTR_FCOL_MASK
Definition efi_console.c:38
#define ATTR_BCOL_MASK
Definition efi_console.c:48
#define ATTR_FCOL_RED
Definition efi_console.c:43
#define ATTR_DEFAULT
Definition efi_console.c:58
static unsigned int count
Number of entries.
Definition dwmac.h:220
EFI_TEXT_SET_ATTRIBUTE SetAttribute

References __unused, ATTR_BCOL_BLACK, ATTR_BCOL_BLUE, ATTR_BCOL_CYAN, ATTR_BCOL_GREEN, ATTR_BCOL_MAGENTA, ATTR_BCOL_MASK, ATTR_BCOL_RED, ATTR_BCOL_WHITE, ATTR_BCOL_YELLOW, ATTR_BOLD, ATTR_DEFAULT, ATTR_FCOL_BLACK, ATTR_FCOL_BLUE, ATTR_FCOL_CYAN, ATTR_FCOL_GREEN, ATTR_FCOL_MAGENTA, ATTR_FCOL_MASK, ATTR_FCOL_RED, ATTR_FCOL_WHITE, ATTR_FCOL_YELLOW, count, ctx, efi_attr, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetAttribute.

◆ efi_handle_dectcem_set()

void efi_handle_dectcem_set ( struct ansiesc_context *ctx __unused,
unsigned int count __unused,
int params[] __unused )
static

Handle ANSI DECTCEM set (show cursor)

Parameters
ctxANSI escape sequence context
countParameter count
paramsList of graphic rendition aspects

Definition at line 168 of file efi_console.c.

170 {
172
173 conout->EnableCursor ( conout, TRUE );
174}
EFI_TEXT_ENABLE_CURSOR EnableCursor
#define TRUE
Definition tlan.h:46

References __unused, count, ctx, efi_systab, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::EnableCursor, and TRUE.

◆ efi_handle_dectcem_reset()

void efi_handle_dectcem_reset ( struct ansiesc_context *ctx __unused,
unsigned int count __unused,
int params[] __unused )
static

Handle ANSI DECTCEM reset (hide cursor)

Parameters
ctxANSI escape sequence context
countParameter count
paramsList of graphic rendition aspects

Definition at line 183 of file efi_console.c.

185 {
187
188 conout->EnableCursor ( conout, FALSE );
189}
#define FALSE
Definition tlan.h:45

References __unused, count, ctx, efi_systab, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::EnableCursor, and FALSE.

◆ efi_putchar()

void efi_putchar ( int character)
static

Print a character to EFI console.

Parameters
characterCharacter to be printed

Definition at line 214 of file efi_console.c.

214 {
216 wchar_t wstr[2];
217
218 /* Intercept ANSI escape sequences */
219 character = ansiesc_process ( &efi_ansiesc_ctx, character );
220 if ( character < 0 )
221 return;
222
223 /* Accumulate Unicode characters */
224 character = utf8_accumulate ( &efi_utf8_acc, character );
225 if ( character == 0 )
226 return;
227
228 /* Treat unrepresentable (non-UCS2) characters as invalid */
229 if ( character & ~( ( wchar_t ) -1UL ) )
230 character = UTF8_INVALID;
231
232 /* Output character */
233 wstr[0] = character;
234 wstr[1] = L'\0';
235 conout->OutputString ( conout, wstr );
236}
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition ansiesc.c:75
static struct utf8_accumulator efi_utf8_acc
EFI console UTF-8 accumulator.
static struct ansiesc_context efi_ansiesc_ctx
EFI console ANSI escape sequence context.
unsigned int utf8_accumulate(struct utf8_accumulator *utf8, uint8_t byte)
Accumulate Unicode character from UTF-8 byte sequence.
Definition utf8.c:44
#define UTF8_INVALID
Invalid character returned when decoding fails.
Definition utf8.h:55

References ansiesc_process(), utf8_accumulator::character, efi_ansiesc_ctx, efi_systab, efi_utf8_acc, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::OutputString, utf8_accumulate(), and UTF8_INVALID.

◆ scancode_to_ansi_seq()

const char * scancode_to_ansi_seq ( unsigned int scancode)
static

Get ANSI escape sequence corresponding to EFI scancode.

Parameters
scancodeEFI scancode
Return values
ansi_seqANSI escape sequence, if any, otherwise NULL

Definition at line 287 of file efi_console.c.

287 {
288 if ( scancode < ( sizeof ( ansi_sequences ) /
289 sizeof ( ansi_sequences[0] ) ) ) {
290 return ansi_sequences[scancode];
291 }
292 return NULL;
293}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
static const char * ansi_sequences[]
Mapping from EFI scan codes to ANSI escape sequences.

References ansi_sequences, and NULL.

Referenced by efi_getchar().

◆ efi_getchar()

int efi_getchar ( void )
static

Get character from EFI console.

Return values
characterCharacter read from console

Definition at line 300 of file efi_console.c.

300 {
303 const char *ansi_seq;
304 unsigned int character;
305 unsigned int shift;
306 unsigned int toggle;
308 EFI_STATUS efirc;
309 int rc;
310
311 /* If we are mid-sequence, pass out the next byte */
312 if ( *ansi_input )
313 return *(ansi_input++);
314
315 /* Read key from real EFI console */
316 memset ( &key, 0, sizeof ( key ) );
317 if ( conin_ex ) {
318 if ( ( efirc = conin_ex->ReadKeyStrokeEx ( conin_ex,
319 &key ) ) != 0 ) {
320 rc = -EEFI ( efirc );
321 DBG ( "EFI could not read extended keystroke: %s\n",
322 strerror ( rc ) );
323 return 0;
324 }
325 } else {
326 if ( ( efirc = conin->ReadKeyStroke ( conin,
327 &key.Key ) ) != 0 ) {
328 rc = -EEFI ( efirc );
329 DBG ( "EFI could not read keystroke: %s\n",
330 strerror ( rc ) );
331 return 0;
332 }
333 }
334 DBG2 ( "EFI read key stroke shift %08x toggle %02x unicode %04x "
335 "scancode %04x\n", key.KeyState.KeyShiftState,
336 key.KeyState.KeyToggleState, key.Key.UnicodeChar,
337 key.Key.ScanCode );
338
339 /* If key has a Unicode representation, remap and return it.
340 * There is unfortunately no way to avoid remapping the
341 * numeric keypad, since EFI destroys the scan code
342 * information that would allow us to differentiate between
343 * main keyboard and numeric keypad.
344 */
345 if ( ( character = key.Key.UnicodeChar ) != 0 ) {
346
347 /* Apply shift state */
348 shift = key.KeyState.KeyShiftState;
349 if ( shift & EFI_SHIFT_STATE_VALID ) {
350 if ( shift & ( EFI_LEFT_CONTROL_PRESSED |
352 character |= KEYMAP_CTRL;
353 }
354 if ( shift & EFI_RIGHT_ALT_PRESSED ) {
355 character |= KEYMAP_ALTGR;
356 }
357 }
358
359 /* Apply toggle state */
360 toggle = key.KeyState.KeyToggleState;
361 if ( toggle & EFI_TOGGLE_STATE_VALID ) {
362 if ( toggle & EFI_CAPS_LOCK_ACTIVE ) {
363 character |= KEYMAP_CAPSLOCK_REDO;
364 }
365 }
366
367 /* Remap and return key */
368 return key_remap ( character );
369 }
370
371 /* Otherwise, check for a special key that we know about */
372 if ( ( ansi_seq = scancode_to_ansi_seq ( key.Key.ScanCode ) ) ) {
373 /* Start of escape sequence: return ESC (0x1b) */
374 ansi_input = ansi_seq;
375 return 0x1b;
376 }
377
378 return 0;
379}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
#define EFI_SHIFT_STATE_VALID
#define EFI_RIGHT_ALT_PRESSED
#define EFI_CAPS_LOCK_ACTIVE
struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
#define EFI_LEFT_CONTROL_PRESSED
#define EFI_RIGHT_CONTROL_PRESSED
#define EFI_TOGGLE_STATE_VALID
struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static const char * scancode_to_ansi_seq(unsigned int scancode)
Get ANSI escape sequence corresponding to EFI scancode.
static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL * efi_conin_ex
Extended simple text input protocol, if present.
Definition efi_console.c:74
static const char * ansi_input
Pointer to current ANSI output sequence.
#define DBG2(...)
Definition compiler.h:515
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
void * memset(void *dest, int character, size_t len) __nonnull
unsigned int key_remap(unsigned int character)
Remap a key.
Definition keymap.c:62
#define KEYMAP_ALTGR
AltGr key flag.
Definition keymap.h:74
#define KEYMAP_CTRL
Ctrl key flag.
Definition keymap.h:56
#define KEYMAP_CAPSLOCK_REDO
Undo and redo CapsLock key flags.
Definition keymap.h:71
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI_INPUT_READ_KEY_EX ReadKeyStrokeEx
EFI_INPUT_READ_KEY ReadKeyStroke

References ansi_input, utf8_accumulator::character, DBG, DBG2, EEFI, EFI_CAPS_LOCK_ACTIVE, efi_conin_ex, EFI_LEFT_CONTROL_PRESSED, EFI_RIGHT_ALT_PRESSED, EFI_RIGHT_CONTROL_PRESSED, EFI_SHIFT_STATE_VALID, efi_systab, EFI_TOGGLE_STATE_VALID, key, key_remap(), KEYMAP_ALTGR, KEYMAP_CAPSLOCK_REDO, KEYMAP_CTRL, memset(), rc, _EFI_SIMPLE_TEXT_INPUT_PROTOCOL::ReadKeyStroke, _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL::ReadKeyStrokeEx, scancode_to_ansi_seq(), and strerror().

◆ efi_iskey()

int efi_iskey ( void )
static

Check for character ready to read from EFI console.

Return values
TrueCharacter available to read
FalseNo character available to read

Definition at line 387 of file efi_console.c.

387 {
388 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
390 EFI_STATUS efirc;
391
392 /* If we are mid-sequence, we are always ready */
393 if ( *ansi_input )
394 return 1;
395
396 /* Check to see if the WaitForKey event has fired */
397 if ( ( efirc = bs->CheckEvent ( conin->WaitForKey ) ) == 0 )
398 return 1;
399
400 return 0;
401}
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_CHECK_EVENT CheckEvent
Definition UefiSpec.h:1960
EFI_EVENT WaitForKey
Event to use with WaitForEvent() to wait for a key to be available.

References ansi_input, EFI_BOOT_SERVICES::CheckEvent, efi_systab, and _EFI_SIMPLE_TEXT_INPUT_PROTOCOL::WaitForKey.

◆ efi_console_init()

void efi_console_init ( void )
static

Initialise EFI console.

Definition at line 415 of file efi_console.c.

415 {
417 int rc;
418
419 /* On some older EFI 1.10 implementations, we must use the
420 * (now obsolete) EFI_CONSOLE_CONTROL_PROTOCOL to switch the
421 * console into text mode.
422 */
423 if ( conctrl ) {
424 conctrl->GetMode ( conctrl, &mode, NULL, NULL );
426 conctrl->SetMode ( conctrl,
428 }
429 }
430
431 /* Attempt to open the Simple Text Input Ex protocol on the
432 * console input handle. This is provably unsafe, but is
433 * apparently the expected behaviour for all UEFI
434 * applications. Don't ask.
435 */
436 if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle,
438 &efi_conin_ex ) ) == 0 ) {
439 DBG ( "EFI using SimpleTextInputEx\n" );
440 } else {
441 DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
442 }
443}
EFI_CONSOLE_CONTROL_SCREEN_MODE
@ EfiConsoleControlScreenText
static EFI_CONSOLE_CONTROL_PROTOCOL * conctrl
Console control protocol.
Definition efi_console.c:70
EFI_GUID efi_simple_text_input_ex_protocol_guid
Simple text input extension protocol GUID.
Definition efi_guid.c:353
uint16_t mode
Acceleration mode.
Definition ena.h:15
#define efi_open_unsafe(handle, protocol, interface)
Open protocol for unsafe persistent use.
Definition efi.h:459

References conctrl, DBG, efi_conin_ex, efi_open_unsafe, efi_simple_text_input_ex_protocol_guid, efi_systab, EfiConsoleControlScreenText, mode, NULL, rc, and strerror().

Referenced by __init_fn().

◆ __init_fn()

struct init_fn efi_console_init_fn __init_fn ( INIT_EARLY )

EFI console initialisation function.

References __init_fn, efi_console_init(), and INIT_EARLY.

Variable Documentation

◆ efi_attr

unsigned int efi_attr = ATTR_DEFAULT
static

Current character attribute.

Definition at line 67 of file efi_console.c.

Referenced by efi_handle_sgr().

◆ conctrl

Console control protocol.

Definition at line 70 of file efi_console.c.

Referenced by efi_console_init(), and EFI_REQUEST_PROTOCOL().

◆ efi_conin_ex

EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL* efi_conin_ex
static

Extended simple text input protocol, if present.

Definition at line 74 of file efi_console.c.

Referenced by efi_console_init(), and efi_getchar().

◆ efi_ansiesc_handlers

struct ansiesc_handler efi_ansiesc_handlers[]
static
Initial value:
= {
{ 0, NULL }
}
static void efi_handle_dectcem_set(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
Handle ANSI DECTCEM set (show cursor)
static void efi_handle_ed(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
Handle ANSI ED (erase in page)
static void efi_handle_dectcem_reset(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
Handle ANSI DECTCEM reset (hide cursor)
static void efi_handle_cup(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[])
Handle ANSI CUP (cursor position)
Definition efi_console.c:84
static void efi_handle_sgr(struct ansiesc_context *ctx __unused, unsigned int count, int params[])
Handle ANSI SGR (set graphics rendition)
#define ANSIESC_DECTCEM_SET
Show cursor.
Definition ansiesc.h:129
#define ANSIESC_ED
Erase in page.
Definition ansiesc.h:107
#define ANSIESC_DECTCEM_RESET
Hide cursor.
Definition ansiesc.h:132
#define ANSIESC_SGR
Select graphic rendition.
Definition ansiesc.h:119
#define ANSIESC_CUP
Cursor position.
Definition ansiesc.h:104

EFI console ANSI escape sequence handlers.

Definition at line 192 of file efi_console.c.

◆ efi_ansiesc_ctx

struct ansiesc_context efi_ansiesc_ctx
static
Initial value:
= {
.handlers = efi_ansiesc_handlers,
}
static struct ansiesc_handler efi_ansiesc_handlers[]
EFI console ANSI escape sequence handlers.

EFI console ANSI escape sequence context.

Definition at line 202 of file efi_console.c.

202 {
203 .handlers = efi_ansiesc_handlers,
204};

Referenced by efi_putchar().

◆ efi_utf8_acc

struct utf8_accumulator efi_utf8_acc
static

EFI console UTF-8 accumulator.

Definition at line 207 of file efi_console.c.

Referenced by efi_putchar().

◆ ansi_input

const char* ansi_input = ""
static

Pointer to current ANSI output sequence.

While we are in the middle of returning an ANSI sequence for a special key, this will point to the next character to return. When not in the middle of such a sequence, this will point to a NUL (note: not "will be NULL").

Definition at line 246 of file efi_console.c.

Referenced by efi_getchar(), and efi_iskey().

◆ ansi_sequences

const char* ansi_sequences[]
static
Initial value:
= {
[SCAN_UP] = "[A",
[SCAN_DOWN] = "[B",
[SCAN_RIGHT] = "[C",
[SCAN_LEFT] = "[D",
[SCAN_HOME] = "[H",
[SCAN_END] = "[F",
[SCAN_INSERT] = "[2~",
[SCAN_DELETE] = "[3~",
[SCAN_PAGE_UP] = "[5~",
[SCAN_PAGE_DOWN] = "[6~",
[SCAN_F5] = "[15~",
[SCAN_F6] = "[17~",
[SCAN_F7] = "[18~",
[SCAN_F8] = "[19~",
[SCAN_F9] = "[20~",
[SCAN_F10] = "[21~",
[SCAN_F11] = "[23~",
[SCAN_F12] = "[24~",
[SCAN_ESC] = "",
}
#define SCAN_F11
#define SCAN_F12
#define SCAN_PAGE_UP
#define SCAN_LEFT
#define SCAN_PAGE_DOWN
#define SCAN_HOME
#define SCAN_F6
#define SCAN_RIGHT
#define SCAN_F9
#define SCAN_UP
#define SCAN_F8
#define SCAN_F5
#define SCAN_F10
#define SCAN_ESC
#define SCAN_DELETE
#define SCAN_DOWN
#define SCAN_END
#define SCAN_INSERT
#define SCAN_F7

Mapping from EFI scan codes to ANSI escape sequences.

Definition at line 249 of file efi_console.c.

249 {
250 [SCAN_UP] = "[A",
251 [SCAN_DOWN] = "[B",
252 [SCAN_RIGHT] = "[C",
253 [SCAN_LEFT] = "[D",
254 [SCAN_HOME] = "[H",
255 [SCAN_END] = "[F",
256 [SCAN_INSERT] = "[2~",
257 /* EFI translates an incoming backspace via the serial console
258 * into a SCAN_DELETE. There's not much we can do about this.
259 */
260 [SCAN_DELETE] = "[3~",
261 [SCAN_PAGE_UP] = "[5~",
262 [SCAN_PAGE_DOWN] = "[6~",
263 [SCAN_F5] = "[15~",
264 [SCAN_F6] = "[17~",
265 [SCAN_F7] = "[18~",
266 [SCAN_F8] = "[19~",
267 [SCAN_F9] = "[20~",
268 [SCAN_F10] = "[21~",
269 [SCAN_F11] = "[23~",
270 [SCAN_F12] = "[24~",
271 /* EFI translates some (but not all) incoming escape sequences
272 * via the serial console into equivalent scancodes. When it
273 * doesn't recognise a sequence, it helpfully(!) translates
274 * the initial ESC and passes the remainder through verbatim.
275 * Treating SCAN_ESC as equivalent to an empty escape sequence
276 * works around this bug.
277 */
278 [SCAN_ESC] = "",
279};

Referenced by scancode_to_ansi_seq().

◆ __console_driver

struct console_driver efi_console __console_driver
Initial value:
= {
.putchar = efi_putchar,
.getchar = efi_getchar,
.iskey = efi_iskey,
.usage = CONSOLE_EFI,
}
#define CONSOLE_EFI
Definition efi_console.c:63
static int efi_iskey(void)
Check for character ready to read from EFI console.
static int efi_getchar(void)
Get character from EFI console.
static void efi_putchar(int character)
Print a character to EFI console.

EFI console driver.

Definition at line 404 of file efi_console.c.

404 {
405 .putchar = efi_putchar,
406 .getchar = efi_getchar,
407 .iskey = efi_iskey,
408 .usage = CONSOLE_EFI,
409};