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/console.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 CTRL_MASK   0x1f
 
#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 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 33 of file efi_console.c.

◆ ATTR_FCOL_MASK

#define ATTR_FCOL_MASK   0x07

Definition at line 35 of file efi_console.c.

◆ ATTR_FCOL_BLACK

#define ATTR_FCOL_BLACK   0x00

Definition at line 36 of file efi_console.c.

◆ ATTR_FCOL_BLUE

#define ATTR_FCOL_BLUE   0x01

Definition at line 37 of file efi_console.c.

◆ ATTR_FCOL_GREEN

#define ATTR_FCOL_GREEN   0x02

Definition at line 38 of file efi_console.c.

◆ ATTR_FCOL_CYAN

#define ATTR_FCOL_CYAN   0x03

Definition at line 39 of file efi_console.c.

◆ ATTR_FCOL_RED

#define ATTR_FCOL_RED   0x04

Definition at line 40 of file efi_console.c.

◆ ATTR_FCOL_MAGENTA

#define ATTR_FCOL_MAGENTA   0x05

Definition at line 41 of file efi_console.c.

◆ ATTR_FCOL_YELLOW

#define ATTR_FCOL_YELLOW   0x06

Definition at line 42 of file efi_console.c.

◆ ATTR_FCOL_WHITE

#define ATTR_FCOL_WHITE   0x07

Definition at line 43 of file efi_console.c.

◆ ATTR_BCOL_MASK

#define ATTR_BCOL_MASK   0x70

Definition at line 45 of file efi_console.c.

◆ ATTR_BCOL_BLACK

#define ATTR_BCOL_BLACK   0x00

Definition at line 46 of file efi_console.c.

◆ ATTR_BCOL_BLUE

#define ATTR_BCOL_BLUE   0x10

Definition at line 47 of file efi_console.c.

◆ ATTR_BCOL_GREEN

#define ATTR_BCOL_GREEN   0x20

Definition at line 48 of file efi_console.c.

◆ ATTR_BCOL_CYAN

#define ATTR_BCOL_CYAN   0x30

Definition at line 49 of file efi_console.c.

◆ ATTR_BCOL_RED

#define ATTR_BCOL_RED   0x40

Definition at line 50 of file efi_console.c.

◆ ATTR_BCOL_MAGENTA

#define ATTR_BCOL_MAGENTA   0x50

Definition at line 51 of file efi_console.c.

◆ ATTR_BCOL_YELLOW

#define ATTR_BCOL_YELLOW   0x60

Definition at line 52 of file efi_console.c.

◆ ATTR_BCOL_WHITE

#define ATTR_BCOL_WHITE   0x70

Definition at line 53 of file efi_console.c.

◆ ATTR_DEFAULT

#define ATTR_DEFAULT   ATTR_FCOL_WHITE

Definition at line 55 of file efi_console.c.

◆ CTRL_MASK

#define CTRL_MASK   0x1f

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:1982
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:1982
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:41
#define ATTR_BCOL_GREEN
Definition: efi_console.c:48
#define ATTR_FCOL_CYAN
Definition: efi_console.c:39
static unsigned int efi_attr
Current character attribute.
Definition: efi_console.c:66
#define ATTR_FCOL_GREEN
Definition: efi_console.c:38
#define ATTR_FCOL_MASK
Definition: efi_console.c:35
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
#define ATTR_BOLD
Definition: efi_console.c:33
#define ATTR_BCOL_BLUE
Definition: efi_console.c:47
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:1982
#define ATTR_BCOL_MAGENTA
Definition: efi_console.c:51
#define ATTR_BCOL_YELLOW
Definition: efi_console.c:52
#define ATTR_FCOL_WHITE
Definition: efi_console.c:43
#define ATTR_FCOL_YELLOW
Definition: efi_console.c:42
unsigned char uint8_t
Definition: stdint.h:10
#define ATTR_BCOL_RED
Definition: efi_console.c:50
#define ATTR_BCOL_MASK
Definition: efi_console.c:45
#define ATTR_FCOL_BLACK
Definition: efi_console.c:36
#define ATTR_FCOL_BLUE
Definition: efi_console.c:37
#define ATTR_BCOL_WHITE
Definition: efi_console.c:53
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
#define ATTR_BCOL_CYAN
Definition: efi_console.c:49
#define ATTR_DEFAULT
Definition: efi_console.c:55
#define ATTR_BCOL_BLACK
Definition: efi_console.c:46
#define ATTR_FCOL_RED
Definition: efi_console.c:40

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:1982
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:1982
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 210 of file efi_console.c.

210  {
212  wchar_t wstr[] = { character, 0 };
213 
214  /* Intercept ANSI escape sequences */
215  character = ansiesc_process ( &efi_ansiesc_ctx, character );
216  if ( character < 0 )
217  return;
218 
219  conout->OutputString ( conout, wstr );
220 }
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
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:1982
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(), EFI_SYSTEM_TABLE::ConOut, efi_ansiesc_ctx, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::OutputString.

◆ 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 271 of file efi_console.c.

271  {
272  if ( scancode < ( sizeof ( ansi_sequences ) /
273  sizeof ( ansi_sequences[0] ) ) ) {
274  return ansi_sequences[scancode];
275  }
276  return NULL;
277 }
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static const char * ansi_sequences[]
Mapping from EFI scan codes to ANSI escape sequences.
Definition: efi_console.c:233

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

284  {
287  const char *ansi_seq;
289  EFI_STATUS efirc;
290  int rc;
291 
292  /* If we are mid-sequence, pass out the next byte */
293  if ( *ansi_input )
294  return *(ansi_input++);
295 
296  /* Read key from real EFI console */
297  memset ( &key, 0, sizeof ( key ) );
298  if ( conin_ex ) {
299  if ( ( efirc = conin_ex->ReadKeyStrokeEx ( conin_ex,
300  &key ) ) != 0 ) {
301  rc = -EEFI ( efirc );
302  DBG ( "EFI could not read extended keystroke: %s\n",
303  strerror ( rc ) );
304  return 0;
305  }
306  } else {
307  if ( ( efirc = conin->ReadKeyStroke ( conin,
308  &key.Key ) ) != 0 ) {
309  rc = -EEFI ( efirc );
310  DBG ( "EFI could not read keystroke: %s\n",
311  strerror ( rc ) );
312  return 0;
313  }
314  }
315  DBG2 ( "EFI read key stroke shift %08x toggle %02x unicode %04x "
316  "scancode %04x\n", key.KeyState.KeyShiftState,
317  key.KeyState.KeyToggleState, key.Key.UnicodeChar,
318  key.Key.ScanCode );
319 
320  /* Translate Ctrl-<key> */
321  if ( ( key.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID ) &&
322  ( key.KeyState.KeyShiftState & ( EFI_LEFT_CONTROL_PRESSED |
324  key.Key.UnicodeChar &= CTRL_MASK;
325  }
326 
327  /* If key has a Unicode representation, return it */
328  if ( key.Key.UnicodeChar )
329  return key.Key.UnicodeChar;
330 
331  /* Otherwise, check for a special key that we know about */
332  if ( ( ansi_seq = scancode_to_ansi_seq ( key.Key.ScanCode ) ) ) {
333  /* Start of escape sequence: return ESC (0x1b) */
334  ansi_input = ansi_seq;
335  return 0x1b;
336  }
337 
338  return 0;
339 }
static const char * scancode_to_ansi_seq(unsigned int scancode)
Get ANSI escape sequence corresponding to EFI scancode.
Definition: efi_console.c:271
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
The EFI_SIMPLE_TEXT_INPUT_PROTOCOL is used on the ConsoleIn device.
Definition: SimpleTextIn.h:124
#define EFI_RIGHT_CONTROL_PRESSED
EFI_INPUT_READ_KEY ReadKeyStroke
Definition: SimpleTextIn.h:126
EFI_SIMPLE_TEXT_INPUT_PROTOCOL * ConIn
A pointer to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL interface that is associated with ConsoleInHandle.
Definition: UefiSpec.h:1973
#define EFI_LEFT_CONTROL_PRESSED
The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL is used on the ConsoleIn device.
#define CTRL_MASK
Definition: efi_console.c:57
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EFI_SHIFT_STATE_VALID
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
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:230
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
union @376 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, EFI_SYSTEM_TABLE::ConIn, CTRL_MASK, DBG, DBG2, EEFI, efi_conin_ex, EFI_LEFT_CONTROL_PRESSED, EFI_RIGHT_CONTROL_PRESSED, EFI_SHIFT_STATE_VALID, efi_systab, key, 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 347 of file efi_console.c.

347  {
351  EFI_EVENT *event;
352  EFI_STATUS efirc;
353 
354  /* If we are mid-sequence, we are always ready */
355  if ( *ansi_input )
356  return 1;
357 
358  /* Check to see if the WaitForKey event has fired */
359  event = ( conin_ex ? conin_ex->WaitForKeyEx : conin->WaitForKey );
360  if ( ( efirc = bs->CheckEvent ( event ) ) == 0 )
361  return 1;
362 
363  return 0;
364 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:124
VOID * EFI_EVENT
Handle to an event structure.
Definition: UefiBaseType.h:43
EFI_EVENT WaitForKey
Event to use with WaitForEvent() to wait for a key to be available.
Definition: SimpleTextIn.h:130
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:1973
The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL is used on the ConsoleIn device.
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_CHECK_EVENT CheckEvent
Definition: UefiSpec.h:1865
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
static const char * ansi_input
Pointer to current ANSI output sequence.
Definition: efi_console.c:230

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

378  {
381  union {
382  void *interface;
384  } u;
385  EFI_STATUS efirc;
386  int rc;
387 
388  /* On some older EFI 1.10 implementations, we must use the
389  * (now obsolete) EFI_CONSOLE_CONTROL_PROTOCOL to switch the
390  * console into text mode.
391  */
392  if ( conctrl ) {
393  conctrl->GetMode ( conctrl, &mode, NULL, NULL );
394  if ( mode != EfiConsoleControlScreenText ) {
397  }
398  }
399 
400  /* Attempt to open the Simple Text Input Ex protocol on the
401  * console input handle. This is provably unsafe, but is
402  * apparently the expected behaviour for all UEFI
403  * applications. Don't ask.
404  */
405  if ( ( efirc = bs->OpenProtocol ( efi_systab->ConsoleInHandle,
407  &u.interface, efi_image_handle,
409  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) {
410  efi_conin_ex = u.wtf;
411  DBG ( "EFI using SimpleTextInputEx\n" );
412  } else {
413  rc = -EEFI ( efirc );
414  DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
415  }
416 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:1968
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:1271
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
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:35
union @17 u
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
#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:362

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:362
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().

◆ 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 230 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:80
#define SCAN_LEFT
Definition: SimpleTextIn.h:63
#define SCAN_DOWN
Definition: SimpleTextIn.h:61
#define SCAN_F12
#define SCAN_HOME
Definition: SimpleTextIn.h:64
#define SCAN_F6
Definition: SimpleTextIn.h:75
#define SCAN_F10
Definition: SimpleTextIn.h:79
#define SCAN_DELETE
Definition: SimpleTextIn.h:67
#define SCAN_F7
Definition: SimpleTextIn.h:76
#define SCAN_PAGE_DOWN
Definition: SimpleTextIn.h:69
#define SCAN_F9
Definition: SimpleTextIn.h:78
#define SCAN_UP
Definition: SimpleTextIn.h:60
#define SCAN_F11
#define SCAN_INSERT
Definition: SimpleTextIn.h:66
#define SCAN_END
Definition: SimpleTextIn.h:65
#define SCAN_RIGHT
Definition: SimpleTextIn.h:62
#define SCAN_PAGE_UP
Definition: SimpleTextIn.h:68
#define SCAN_F5
Definition: SimpleTextIn.h:74
#define SCAN_F8
Definition: SimpleTextIn.h:77

Mapping from EFI scan codes to ANSI escape sequences.

Definition at line 233 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:284
static void efi_putchar(int character)
Print a character to EFI console.
Definition: efi_console.c:210
static int efi_iskey(void)
Check for character ready to read from EFI console.
Definition: efi_console.c:347

EFI console driver.

Definition at line 367 of file efi_console.c.