efi_console.c File Reference

#include <stddef.h>
#include <assert.h>
#include <gpxe/efi/efi.h>
#include <gpxe/ansiesc.h>
#include <console.h>

Go to the source code of this file.

Defines

#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

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void efi_handle_cup (unsigned int count __unused, int params[])
 Handle ANSI CUP (cursor position).
static void efi_handle_ed (unsigned int count __unused, int params[] __unused)
 Handle ANSI ED (erase in page).
static void efi_handle_sgr (unsigned int count, int params[])
 Handle ANSI SGR (set graphics rendition).
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.

Variables

static unsigned int efi_attr = ATTR_DEFAULT
 Current character attribute.
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 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


Define Documentation

#define ATTR_BOLD   0x08

Definition at line 27 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_MASK   0x07

Definition at line 29 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_BLACK   0x00

Definition at line 30 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_BLUE   0x01

Definition at line 31 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_GREEN   0x02

Definition at line 32 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_CYAN   0x03

Definition at line 33 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_RED   0x04

Definition at line 34 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_MAGENTA   0x05

Definition at line 35 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_YELLOW   0x06

Definition at line 36 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_FCOL_WHITE   0x07

Definition at line 37 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_MASK   0x70

Definition at line 39 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_BLACK   0x00

Definition at line 40 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_BLUE   0x10

Definition at line 41 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_GREEN   0x20

Definition at line 42 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_CYAN   0x30

Definition at line 43 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_RED   0x40

Definition at line 44 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_MAGENTA   0x50

Definition at line 45 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_YELLOW   0x60

Definition at line 46 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_BCOL_WHITE   0x70

Definition at line 47 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().

#define ATTR_DEFAULT   ATTR_FCOL_WHITE

Definition at line 49 of file efi_console.c.

Referenced by bios_handle_sgr(), and efi_handle_sgr().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void efi_handle_cup ( unsigned int count  __unused,
int  params[] 
) [static]

Handle ANSI CUP (cursor position).

Parameters:
count Parameter count
params[0] Row (1 is top)
params[1] Column (1 is left)

Definition at line 61 of file efi_console.c.

References _EFI_SYSTEM_TABLE::ConOut, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetCursorPosition.

00061                                                                          {
00062         EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
00063         int cx = ( params[1] - 1 );
00064         int cy = ( params[0] - 1 );
00065 
00066         if ( cx < 0 )
00067                 cx = 0;
00068         if ( cy < 0 )
00069                 cy = 0;
00070 
00071         conout->SetCursorPosition ( conout, cx, cy );
00072 }

static void efi_handle_ed ( unsigned int count  __unused,
int params[]  __unused 
) [static]

Handle ANSI ED (erase in page).

Parameters:
count Parameter count
params[0] Region to erase

Definition at line 80 of file efi_console.c.

References ANSIESC_ED_ALL, assert, _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::ClearScreen, _EFI_SYSTEM_TABLE::ConOut, and efi_systab.

00081                                                      {
00082         EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
00083 
00084         /* We assume that we always clear the whole screen */
00085         assert ( params[0] == ANSIESC_ED_ALL );
00086 
00087         conout->ClearScreen ( conout );
00088 }

static void efi_handle_sgr ( unsigned int  count,
int  params[] 
) [static]

Handle ANSI SGR (set graphics rendition).

Parameters:
count Parameter count
params List of graphic rendition aspects

Definition at line 96 of file efi_console.c.

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

00096                                                                 {
00097         EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
00098         static const uint8_t efi_attr_fcols[10] = {
00099                 ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN,
00100                 ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA,
00101                 ATTR_FCOL_CYAN, ATTR_FCOL_WHITE,
00102                 ATTR_FCOL_WHITE, ATTR_FCOL_WHITE /* defaults */
00103         };
00104         static const uint8_t efi_attr_bcols[10] = {
00105                 ATTR_BCOL_BLACK, ATTR_BCOL_RED, ATTR_BCOL_GREEN,
00106                 ATTR_BCOL_YELLOW, ATTR_BCOL_BLUE, ATTR_BCOL_MAGENTA,
00107                 ATTR_BCOL_CYAN, ATTR_BCOL_WHITE,
00108                 ATTR_BCOL_BLACK, ATTR_BCOL_BLACK /* defaults */
00109         };
00110         unsigned int i;
00111         int aspect;
00112 
00113         for ( i = 0 ; i < count ; i++ ) {
00114                 aspect = params[i];
00115                 if ( aspect == 0 ) {
00116                         efi_attr = ATTR_DEFAULT;
00117                 } else if ( aspect == 1 ) {
00118                         efi_attr |= ATTR_BOLD;
00119                 } else if ( aspect == 22 ) {
00120                         efi_attr &= ~ATTR_BOLD;
00121                 } else if ( ( aspect >= 30 ) && ( aspect <= 39 ) ) {
00122                         efi_attr &= ~ATTR_FCOL_MASK;
00123                         efi_attr |= efi_attr_fcols[ aspect - 30 ];
00124                 } else if ( ( aspect >= 40 ) && ( aspect <= 49 ) ) {
00125                         efi_attr &= ~ATTR_BCOL_MASK;
00126                         efi_attr |= efi_attr_bcols[ aspect - 40 ];
00127                 }
00128         }
00129 
00130         conout->SetAttribute ( conout, efi_attr );
00131 }

static void efi_putchar ( int  character  )  [static]

Print a character to EFI console.

Parameters:
character Character to be printed

Definition at line 151 of file efi_console.c.

References ansiesc_process(), _EFI_SYSTEM_TABLE::ConOut, efi_systab, and _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::OutputString.

00151                                           {
00152         EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
00153         wchar_t wstr[] = { character, 0 };
00154 
00155         /* Intercept ANSI escape sequences */
00156         character = ansiesc_process ( &efi_ansiesc_ctx, character );
00157         if ( character < 0 )
00158                 return;
00159 
00160         conout->OutputString ( conout, wstr );
00161 }

static const char* scancode_to_ansi_seq ( unsigned int  scancode  )  [static]

Get ANSI escape sequence corresponding to EFI scancode.

Parameters:
scancode EFI scancode
Return values:
ansi_seq ANSI escape sequence, if any, otherwise NULL

Definition at line 204 of file efi_console.c.

References ansi_sequences, and NULL.

Referenced by bios_getchar(), and efi_getchar().

00204                                                                    {
00205         if ( scancode < ( sizeof ( ansi_sequences ) /
00206                           sizeof ( ansi_sequences[0] ) ) ) {
00207                 return ansi_sequences[scancode];
00208         }
00209         return NULL;
00210 }

static int efi_getchar ( void   )  [static]

Get character from EFI console.

Return values:
character Character read from console

Definition at line 217 of file efi_console.c.

References ansi_input, _EFI_SYSTEM_TABLE::ConIn, DBG, DBG2, efi_strerror(), efi_systab, _EFI_SIMPLE_TEXT_INPUT_PROTOCOL::ReadKeyStroke, EFI_INPUT_KEY::ScanCode, scancode_to_ansi_seq(), and EFI_INPUT_KEY::UnicodeChar.

00217                                 {
00218         EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin = efi_systab->ConIn;
00219         const char *ansi_seq;
00220         EFI_INPUT_KEY key;
00221         EFI_STATUS efirc;
00222 
00223         /* If we are mid-sequence, pass out the next byte */
00224         if ( *ansi_input )
00225                 return *(ansi_input++);
00226 
00227         /* Read key from real EFI console */
00228         if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) {
00229                 DBG ( "EFI could not read keystroke: %s\n",
00230                       efi_strerror ( efirc ) );
00231                 return 0;
00232         }
00233         DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",
00234                key.UnicodeChar, key.ScanCode );
00235 
00236         /* If key has a Unicode representation, return it */
00237         if ( key.UnicodeChar )
00238                 return key.UnicodeChar;
00239 
00240         /* Otherwise, check for a special key that we know about */
00241         if ( ( ansi_seq = scancode_to_ansi_seq ( key.ScanCode ) ) ) {
00242                 /* Start of escape sequence: return ESC (0x1b) */
00243                 ansi_input = ansi_seq;
00244                 return 0x1b;
00245         }
00246 
00247         return 0;
00248 }

static int efi_iskey ( void   )  [static]

Check for character ready to read from EFI console.

Return values:
True Character available to read
False No character available to read

Definition at line 256 of file efi_console.c.

References ansi_input, _EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CheckEvent, _EFI_SYSTEM_TABLE::ConIn, efi_systab, and _EFI_SIMPLE_TEXT_INPUT_PROTOCOL::WaitForKey.

00256                               {
00257         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00258         EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin = efi_systab->ConIn;
00259         EFI_STATUS efirc;
00260 
00261         /* If we are mid-sequence, we are always ready */
00262         if ( *ansi_input )
00263                 return 1;
00264 
00265         /* Check to see if the WaitForKey event has fired */
00266         if ( ( efirc = bs->CheckEvent ( conin->WaitForKey ) ) == 0 )
00267                 return 1;
00268 
00269         return 0;
00270 }


Variable Documentation

unsigned int efi_attr = ATTR_DEFAULT [static]

Current character attribute.

Definition at line 52 of file efi_console.c.

Referenced by efi_handle_sgr().

Initial value:

EFI console ANSI escape sequence handlers.

Definition at line 134 of file efi_console.c.

Initial value:

 {
        .handlers = efi_ansiesc_handlers,
}
EFI console ANSI escape sequence context.

Definition at line 142 of file efi_console.c.

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

Referenced by bios_getchar(), bios_iskey(), efi_getchar(), and efi_iskey().

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_ESC] = "",
}
Mapping from EFI scan codes to ANSI escape sequences.

Definition at line 174 of file efi_console.c.

Referenced by scancode_to_ansi_seq().

struct console_driver efi_console __console_driver

Initial value:

 {
        .putchar = efi_putchar,
        .getchar = efi_getchar,
        .iskey = efi_iskey,
}

Definition at line 272 of file efi_console.c.


Generated on Tue Apr 6 20:01:53 2010 for gPXE by  doxygen 1.5.7.1