iPXE
Macros | Functions | Variables
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)
 
 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) More...
 
static void efi_handle_ed (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
 Handle ANSI ED (erase in page) More...
 
static void efi_handle_sgr (struct ansiesc_context *ctx __unused, unsigned int count, int params[])
 Handle ANSI SGR (set graphics rendition) More...
 
static void efi_handle_dectcem_set (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
 Handle ANSI DECTCEM set (show cursor) More...
 
static void efi_handle_dectcem_reset (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
 Handle ANSI DECTCEM reset (hide cursor) More...
 
static void efi_putchar (int character)
 Print a character to EFI console. More...
 
static const char * scancode_to_ansi_seq (unsigned int scancode)
 Get ANSI escape sequence corresponding to EFI scancode. More...
 
static int efi_getchar (void)
 Get character from EFI console. More...
 
static int efi_iskey (void)
 Check for character ready to read from EFI console. More...
 
static void efi_console_init (void)
 Initialise EFI console. More...
 
struct init_fn efi_console_init_fn __init_fn (INIT_EARLY)
 EFI console initialisation function. More...
 

Variables

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

Macro Definition Documentation

◆ ATTR_BOLD

#define ATTR_BOLD   0x08

Definition at line 35 of file efi_console.c.

◆ ATTR_FCOL_MASK

#define ATTR_FCOL_MASK   0x07

Definition at line 37 of file efi_console.c.

◆ ATTR_FCOL_BLACK

#define ATTR_FCOL_BLACK   0x00

Definition at line 38 of file efi_console.c.

◆ ATTR_FCOL_BLUE

#define ATTR_FCOL_BLUE   0x01

Definition at line 39 of file efi_console.c.

◆ ATTR_FCOL_GREEN

#define ATTR_FCOL_GREEN   0x02

Definition at line 40 of file efi_console.c.

◆ ATTR_FCOL_CYAN

#define ATTR_FCOL_CYAN   0x03

Definition at line 41 of file efi_console.c.

◆ ATTR_FCOL_RED

#define ATTR_FCOL_RED   0x04

Definition at line 42 of file efi_console.c.

◆ ATTR_FCOL_MAGENTA

#define ATTR_FCOL_MAGENTA   0x05

Definition at line 43 of file efi_console.c.

◆ ATTR_FCOL_YELLOW

#define ATTR_FCOL_YELLOW   0x06

Definition at line 44 of file efi_console.c.

◆ ATTR_FCOL_WHITE

#define ATTR_FCOL_WHITE   0x07

Definition at line 45 of file efi_console.c.

◆ ATTR_BCOL_MASK

#define ATTR_BCOL_MASK   0x70

Definition at line 47 of file efi_console.c.

◆ ATTR_BCOL_BLACK

#define ATTR_BCOL_BLACK   0x00

Definition at line 48 of file efi_console.c.

◆ ATTR_BCOL_BLUE

#define ATTR_BCOL_BLUE   0x10

Definition at line 49 of file efi_console.c.

◆ ATTR_BCOL_GREEN

#define ATTR_BCOL_GREEN   0x20

Definition at line 50 of file efi_console.c.

◆ ATTR_BCOL_CYAN

#define ATTR_BCOL_CYAN   0x30

Definition at line 51 of file efi_console.c.

◆ ATTR_BCOL_RED

#define ATTR_BCOL_RED   0x40

Definition at line 52 of file efi_console.c.

◆ ATTR_BCOL_MAGENTA

#define ATTR_BCOL_MAGENTA   0x50

Definition at line 53 of file efi_console.c.

◆ ATTR_BCOL_YELLOW

#define ATTR_BCOL_YELLOW   0x60

Definition at line 54 of file efi_console.c.

◆ ATTR_BCOL_WHITE

#define ATTR_BCOL_WHITE   0x70

Definition at line 55 of file efi_console.c.

◆ ATTR_DEFAULT

#define ATTR_DEFAULT   ATTR_FCOL_WHITE

Definition at line 57 of file efi_console.c.

◆ CONSOLE_EFI

#define CONSOLE_EFI   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Definition at line 62 of file efi_console.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ EFI_REQUEST_PROTOCOL()

EFI_REQUEST_PROTOCOL ( EFI_CONSOLE_CONTROL_PROTOCOL  ,
conctrl 
)

◆ efi_handle_cup()

static 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 83 of file efi_console.c.

84  {
86  int cx = ( params[1] - 1 );
87  int cy = ( params[0] - 1 );
88 
89  if ( cx < 0 )
90  cx = 0;
91  if ( cy < 0 )
92  cy = 0;
93 
94  conout->SetCursorPosition ( conout, cx, cy );
95 }
EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition
uint16_t cx
Definition: registers.h:51
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2012
EFI_SYSTEM_TABLE * efi_systab

References EFI_SYSTEM_TABLE::ConOut, cx, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetCursorPosition.

◆ efi_handle_ed()

static 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 104 of file efi_console.c.

106  {
108 
109  /* We assume that we always clear the whole screen */
110  assert ( params[0] == ANSIESC_ED_ALL );
111 
112  conout->ClearScreen ( conout );
113 }
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
#define ANSIESC_ED_ALL
Erase whole page.
Definition: ansiesc.h:115
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2012
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
EFI_TEXT_CLEAR_SCREEN ClearScreen
EFI_SYSTEM_TABLE * efi_systab

References ANSIESC_ED_ALL, assert(), _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::ClearScreen, EFI_SYSTEM_TABLE::ConOut, and efi_systab.

◆ efi_handle_sgr()

static 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 122 of file efi_console.c.

123  {
125  static const uint8_t efi_attr_fcols[10] = {
129  ATTR_FCOL_WHITE, ATTR_FCOL_WHITE /* defaults */
130  };
131  static const uint8_t efi_attr_bcols[10] = {
135  ATTR_BCOL_BLACK, ATTR_BCOL_BLACK /* defaults */
136  };
137  unsigned int i;
138  int aspect;
139 
140  for ( i = 0 ; i < count ; i++ ) {
141  aspect = params[i];
142  if ( aspect == 0 ) {
144  } else if ( aspect == 1 ) {
145  efi_attr |= ATTR_BOLD;
146  } else if ( aspect == 22 ) {
147  efi_attr &= ~ATTR_BOLD;
148  } else if ( ( aspect >= 30 ) && ( aspect <= 39 ) ) {
150  efi_attr |= efi_attr_fcols[ aspect - 30 ];
151  } else if ( ( aspect >= 40 ) && ( aspect <= 49 ) ) {
153  efi_attr |= efi_attr_bcols[ aspect - 40 ];
154  }
155  }
156 
157  conout->SetAttribute ( conout, efi_attr );
158 }
#define ATTR_FCOL_MAGENTA
Definition: efi_console.c:43
#define ATTR_BCOL_GREEN
Definition: efi_console.c:50
#define ATTR_FCOL_CYAN
Definition: efi_console.c:41
static unsigned int efi_attr
Current character attribute.
Definition: efi_console.c:66
#define ATTR_FCOL_GREEN
Definition: efi_console.c:40
#define ATTR_FCOL_MASK
Definition: efi_console.c:37
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
#define ATTR_BOLD
Definition: efi_console.c:35
#define ATTR_BCOL_BLUE
Definition: efi_console.c:49
EFI_TEXT_SET_ATTRIBUTE SetAttribute
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2012
#define ATTR_BCOL_MAGENTA
Definition: efi_console.c:53
#define ATTR_BCOL_YELLOW
Definition: efi_console.c:54
#define ATTR_FCOL_WHITE
Definition: efi_console.c:45
#define ATTR_FCOL_YELLOW
Definition: efi_console.c:44
unsigned char uint8_t
Definition: stdint.h:10
#define ATTR_BCOL_RED
Definition: efi_console.c:52
#define ATTR_BCOL_MASK
Definition: efi_console.c:47
#define ATTR_FCOL_BLACK
Definition: efi_console.c:38
#define ATTR_FCOL_BLUE
Definition: efi_console.c:39
#define ATTR_BCOL_WHITE
Definition: efi_console.c:55
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
#define ATTR_BCOL_CYAN
Definition: efi_console.c:51
#define ATTR_DEFAULT
Definition: efi_console.c:57
#define ATTR_BCOL_BLACK
Definition: efi_console.c:48
#define ATTR_FCOL_RED
Definition: efi_console.c:42

References 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, EFI_SYSTEM_TABLE::ConOut, count, efi_attr, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetAttribute.

◆ efi_handle_dectcem_set()

static 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 167 of file efi_console.c.

169  {
171 
172  conout->EnableCursor ( conout, TRUE );
173 }
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2012
EFI_TEXT_ENABLE_CURSOR EnableCursor
#define TRUE
Definition: tlan.h:46
EFI_SYSTEM_TABLE * efi_systab

References EFI_SYSTEM_TABLE::ConOut, efi_systab, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::EnableCursor, and TRUE.

◆ efi_handle_dectcem_reset()

static 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 182 of file efi_console.c.

184  {
186 
187  conout->EnableCursor ( conout, FALSE );
188 }
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2012
EFI_TEXT_ENABLE_CURSOR EnableCursor
#define FALSE
Definition: tlan.h:45
EFI_SYSTEM_TABLE * efi_systab

References EFI_SYSTEM_TABLE::ConOut, efi_systab, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::EnableCursor, and FALSE.

◆ efi_putchar()

static void efi_putchar ( int  character)
static

Print a character to EFI console.

Parameters
characterCharacter to be printed

Definition at line 213 of file efi_console.c.

213  {
215  wchar_t wstr[2];
216 
217  /* Intercept ANSI escape sequences */
218  character = ansiesc_process ( &efi_ansiesc_ctx, character );
219  if ( character < 0 )
220  return;
221 
222  /* Accumulate Unicode characters */
223  character = utf8_accumulate ( &efi_utf8_acc, character );
224  if ( character == 0 )
225  return;
226 
227  /* Treat unrepresentable (non-UCS2) characters as invalid */
228  if ( character & ~( ( wchar_t ) -1UL ) )
229  character = UTF8_INVALID;
230 
231  /* Output character */
232  wstr[0] = character;
233  wstr[1] = L'\0';
234  conout->OutputString ( conout, wstr );
235 }
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
#define UTF8_INVALID
Invalid character returned when decoding fails.
Definition: utf8.h:54
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition: ansiesc.c:74
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2012
static struct utf8_accumulator efi_utf8_acc
EFI console UTF-8 accumulator.
Definition: efi_console.c:206
unsigned int utf8_accumulate(struct utf8_accumulator *utf8, uint8_t byte)
Accumulate Unicode character from UTF-8 byte sequence.
Definition: utf8.c:43
static struct ansiesc_context efi_ansiesc_ctx
EFI console ANSI escape sequence context.
Definition: efi_console.c:201
EFI_SYSTEM_TABLE * efi_systab

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

◆ scancode_to_ansi_seq()

static 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 286 of file efi_console.c.

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

References ansi_sequences, and NULL.

Referenced by efi_getchar().

◆ efi_getchar()

static int efi_getchar ( void  )
static

Get character from EFI console.

Return values
characterCharacter read from console

Definition at line 299 of file efi_console.c.

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

References ansi_input, utf8_accumulator::character, EFI_SYSTEM_TABLE::ConIn, 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()

static 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 386 of file efi_console.c.

386  {
390  EFI_EVENT *event;
391  EFI_STATUS efirc;
392 
393  /* If we are mid-sequence, we are always ready */
394  if ( *ansi_input )
395  return 1;
396 
397  /* Check to see if the WaitForKey event has fired */
398  event = ( conin_ex ? conin_ex->WaitForKeyEx : conin->WaitForKey );
399  if ( ( efirc = bs->CheckEvent ( event ) ) == 0 )
400  return 1;
401 
402  return 0;
403 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2030
static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL * efi_conin_ex
Extended simple text input protocol, if present.
Definition: efi_console.c:73
The EFI_SIMPLE_TEXT_INPUT_PROTOCOL is used on the ConsoleIn device.
Definition: SimpleTextIn.h:118
VOID * EFI_EVENT
Handle to an event structure.
Definition: UefiBaseType.h:39
EFI_EVENT WaitForKey
Event to use with WaitForEvent() to wait for a key to be available.
Definition: SimpleTextIn.h:124
EFI_EVENT WaitForKeyEx
Event to use with WaitForEvent() to wait for a key to be available.
EFI_SIMPLE_TEXT_INPUT_PROTOCOL * ConIn
A pointer to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL interface that is associated with ConsoleInHandle.
Definition: UefiSpec.h:2003
The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL is used on the ConsoleIn device.
EFI Boot Services Table.
Definition: UefiSpec.h:1866
EFI_CHECK_EVENT CheckEvent
Definition: UefiSpec.h:1895
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
static const char * ansi_input
Pointer to current ANSI output sequence.
Definition: efi_console.c:245

References ansi_input, EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CheckEvent, EFI_SYSTEM_TABLE::ConIn, efi_conin_ex, efi_systab, _EFI_SIMPLE_TEXT_INPUT_PROTOCOL::WaitForKey, and _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL::WaitForKeyEx.

◆ efi_console_init()

static void efi_console_init ( void  )
static

Initialise EFI console.

Definition at line 417 of file efi_console.c.

417  {
420  union {
421  void *interface;
423  } u;
424  EFI_STATUS efirc;
425  int rc;
426 
427  /* On some older EFI 1.10 implementations, we must use the
428  * (now obsolete) EFI_CONSOLE_CONTROL_PROTOCOL to switch the
429  * console into text mode.
430  */
431  if ( conctrl ) {
432  conctrl->GetMode ( conctrl, &mode, NULL, NULL );
433  if ( mode != EfiConsoleControlScreenText ) {
436  }
437  }
438 
439  /* Attempt to open the Simple Text Input Ex protocol on the
440  * console input handle. This is provably unsafe, but is
441  * apparently the expected behaviour for all UEFI
442  * applications. Don't ask.
443  */
444  if ( ( efirc = bs->OpenProtocol ( efi_systab->ConsoleInHandle,
446  &u.interface, efi_image_handle,
448  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) {
449  efi_conin_ex = u.wtf;
450  DBG ( "EFI using SimpleTextInputEx\n" );
451  } else {
452  rc = -EEFI ( efirc );
453  DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
454  }
455 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2030
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL * efi_conin_ex
Extended simple text input protocol, if present.
Definition: efi_console.c:73
EFI_CONSOLE_CONTROL_SCREEN_MODE
EFI_HANDLE ConsoleInHandle
The handle for the active console input device.
Definition: UefiSpec.h:1998
EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE GetMode
static EFI_CONSOLE_CONTROL_PROTOCOL * conctrl
Console control protocol.
Definition: efi_console.c:69
An object interface.
Definition: interface.h:124
The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL is used on the ConsoleIn device.
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1299
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1866
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
EFI_GUID efi_simple_text_input_ex_protocol_guid
Simple text input extension protocol GUID.
Definition: efi_guid.c:248
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
union @17 u
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1935
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE SetMode
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References EFI_SYSTEM_TABLE::BootServices, conctrl, EFI_SYSTEM_TABLE::ConsoleInHandle, DBG, EEFI, efi_conin_ex, efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_simple_text_input_ex_protocol_guid, efi_systab, EfiConsoleControlScreenText, _EFI_CONSOLE_CONTROL_PROTOCOL::GetMode, NULL, EFI_BOOT_SERVICES::OpenProtocol, rc, _EFI_CONSOLE_CONTROL_PROTOCOL::SetMode, strerror(), and u.

◆ __init_fn()

struct init_fn efi_console_init_fn __init_fn ( INIT_EARLY  )

EFI console initialisation function.

Variable Documentation

◆ efi_attr

unsigned int efi_attr = ATTR_DEFAULT
static

Current character attribute.

Definition at line 66 of file efi_console.c.

Referenced by efi_handle_sgr().

◆ conctrl

Console control protocol.

Definition at line 69 of file efi_console.c.

Referenced by efi_console_init().

◆ efi_conin_ex

EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL* efi_conin_ex
static

Extended simple text input protocol, if present.

Definition at line 73 of file efi_console.c.

Referenced by efi_console_init(), efi_getchar(), and efi_iskey().

◆ efi_ansiesc_handlers

struct ansiesc_handler efi_ansiesc_handlers[]
static
Initial value:
= {
{ 0, NULL }
}
static void efi_handle_dectcem_reset(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
Handle ANSI DECTCEM reset (hide cursor)
Definition: efi_console.c:182
#define ANSIESC_ED
Erase in page.
Definition: ansiesc.h:106
#define ANSIESC_CUP
Cursor position.
Definition: ansiesc.h:103
#define ANSIESC_SGR
Select graphic rendition.
Definition: ansiesc.h:118
static void efi_handle_dectcem_set(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
Handle ANSI DECTCEM set (show cursor)
Definition: efi_console.c:167
static void efi_handle_sgr(struct ansiesc_context *ctx __unused, unsigned int count, int params[])
Handle ANSI SGR (set graphics rendition)
Definition: efi_console.c:122
#define ANSIESC_DECTCEM_RESET
Hide cursor.
Definition: ansiesc.h:131
#define ANSIESC_DECTCEM_SET
Show cursor.
Definition: ansiesc.h:128
static void efi_handle_ed(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[] __unused)
Handle ANSI ED (erase in page)
Definition: efi_console.c:104
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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:83

EFI console ANSI escape sequence handlers.

Definition at line 191 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.
Definition: efi_console.c:191

EFI console ANSI escape sequence context.

Definition at line 201 of file efi_console.c.

Referenced by efi_putchar().

◆ efi_utf8_acc

struct utf8_accumulator efi_utf8_acc
static

EFI console UTF-8 accumulator.

Definition at line 206 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 245 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_ESC
Definition: SimpleTextIn.h:74
#define SCAN_LEFT
Definition: SimpleTextIn.h:57
#define SCAN_DOWN
Definition: SimpleTextIn.h:55
#define SCAN_F12
#define SCAN_HOME
Definition: SimpleTextIn.h:58
#define SCAN_F6
Definition: SimpleTextIn.h:69
#define SCAN_F10
Definition: SimpleTextIn.h:73
#define SCAN_DELETE
Definition: SimpleTextIn.h:61
#define SCAN_F7
Definition: SimpleTextIn.h:70
#define SCAN_PAGE_DOWN
Definition: SimpleTextIn.h:63
#define SCAN_F9
Definition: SimpleTextIn.h:72
#define SCAN_UP
Definition: SimpleTextIn.h:54
#define SCAN_F11
#define SCAN_INSERT
Definition: SimpleTextIn.h:60
#define SCAN_END
Definition: SimpleTextIn.h:59
#define SCAN_RIGHT
Definition: SimpleTextIn.h:56
#define SCAN_PAGE_UP
Definition: SimpleTextIn.h:62
#define SCAN_F5
Definition: SimpleTextIn.h:68
#define SCAN_F8
Definition: SimpleTextIn.h:71

Mapping from EFI scan codes to ANSI escape sequences.

Definition at line 248 of file efi_console.c.

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:62
static int efi_getchar(void)
Get character from EFI console.
Definition: efi_console.c:299
static void efi_putchar(int character)
Print a character to EFI console.
Definition: efi_console.c:213
static int efi_iskey(void)
Check for character ready to read from EFI console.
Definition: efi_console.c:386

EFI console driver.

Definition at line 406 of file efi_console.c.