#include <assert.h>#include <realmode.h>#include <console.h>#include <gpxe/ansiesc.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 |
| #define | BIOS_KEY_MIN 0x42 |
| Lowest BIOS scancode of interest. | |
| #define | BIOS_KEY(scancode) ( (scancode) - BIOS_KEY_MIN ) |
| Offset into list of interesting BIOS scancodes. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static void | bios_handle_cup (unsigned int count __unused, int params[]) |
| Handle ANSI CUP (cursor position). | |
| static void | bios_handle_ed (unsigned int count __unused, int params[] __unused) |
| Handle ANSI ED (erase in page). | |
| static void | bios_handle_sgr (unsigned int count, int params[]) |
| Handle ANSI SGR (set graphics rendition). | |
| static void | bios_putchar (int character) |
| Print a character to BIOS console. | |
| static const char * | scancode_to_ansi_seq (unsigned int scancode) |
| Get ANSI escape sequence corresponding to BIOS scancode. | |
| static int | bios_getchar (void) |
| Get character from BIOS console. | |
| static int | bios_iskey (void) |
| Check for character ready to read from BIOS console. | |
Variables | |
| static unsigned int | bios_attr = ATTR_DEFAULT |
| Current character attribute. | |
| static struct ansiesc_handler | bios_ansiesc_handlers [] |
| BIOS console ANSI escape sequence handlers. | |
| static struct ansiesc_context | bios_ansiesc_ctx |
| BIOS console ANSI escape sequence context. | |
| static const char * | ansi_input = "" |
| Pointer to current ANSI output sequence. | |
| static const char * | ansi_sequences [] |
| Mapping from BIOS scan codes to ANSI escape sequences. | |
| struct console_driver bios_console | __console_driver |
| #define ATTR_BOLD 0x08 |
Definition at line 26 of file bios_console.c.
| #define ATTR_FCOL_MASK 0x07 |
Definition at line 28 of file bios_console.c.
| #define ATTR_FCOL_BLACK 0x00 |
Definition at line 29 of file bios_console.c.
| #define ATTR_FCOL_BLUE 0x01 |
Definition at line 30 of file bios_console.c.
| #define ATTR_FCOL_GREEN 0x02 |
Definition at line 31 of file bios_console.c.
| #define ATTR_FCOL_CYAN 0x03 |
Definition at line 32 of file bios_console.c.
| #define ATTR_FCOL_RED 0x04 |
Definition at line 33 of file bios_console.c.
| #define ATTR_FCOL_MAGENTA 0x05 |
Definition at line 34 of file bios_console.c.
| #define ATTR_FCOL_YELLOW 0x06 |
Definition at line 35 of file bios_console.c.
| #define ATTR_FCOL_WHITE 0x07 |
Definition at line 36 of file bios_console.c.
| #define ATTR_BCOL_MASK 0x70 |
Definition at line 38 of file bios_console.c.
| #define ATTR_BCOL_BLACK 0x00 |
Definition at line 39 of file bios_console.c.
| #define ATTR_BCOL_BLUE 0x10 |
Definition at line 40 of file bios_console.c.
| #define ATTR_BCOL_GREEN 0x20 |
Definition at line 41 of file bios_console.c.
| #define ATTR_BCOL_CYAN 0x30 |
Definition at line 42 of file bios_console.c.
| #define ATTR_BCOL_RED 0x40 |
Definition at line 43 of file bios_console.c.
| #define ATTR_BCOL_MAGENTA 0x50 |
Definition at line 44 of file bios_console.c.
| #define ATTR_BCOL_YELLOW 0x60 |
Definition at line 45 of file bios_console.c.
| #define ATTR_BCOL_WHITE 0x70 |
Definition at line 46 of file bios_console.c.
| #define ATTR_DEFAULT ATTR_FCOL_WHITE |
Definition at line 48 of file bios_console.c.
| #define BIOS_KEY_MIN 0x42 |
Lowest BIOS scancode of interest.
Most of the BIOS key scancodes that we are interested in are in a dense range, so subtracting a constant and treating them as offsets into an array works efficiently.
Definition at line 198 of file bios_console.c.
| #define BIOS_KEY | ( | scancode | ) | ( (scancode) - BIOS_KEY_MIN ) |
Offset into list of interesting BIOS scancodes.
Definition at line 201 of file bios_console.c.
Referenced by scancode_to_ansi_seq().
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static void bios_handle_cup | ( | unsigned int count | __unused, | |
| int | params[] | |||
| ) | [static] |
Handle ANSI CUP (cursor position).
| count | Parameter count | |
| params[0] | Row (1 is top) | |
| params[1] | Column (1 is left) |
Definition at line 60 of file bios_console.c.
References __asm__(), and REAL_CODE.
00060 { 00061 int cx = ( params[1] - 1 ); 00062 int cy = ( params[0] - 1 ); 00063 00064 if ( cx < 0 ) 00065 cx = 0; 00066 if ( cy < 0 ) 00067 cy = 0; 00068 00069 __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" 00070 "int $0x10\n\t" 00071 "cli\n\t" ) 00072 : : "a" ( 0x0200 ), "b" ( 1 ), 00073 "d" ( ( cy << 8 ) | cx ) ); 00074 }
| static void bios_handle_ed | ( | unsigned int count | __unused, | |
| int params[] | __unused | |||
| ) | [static] |
Handle ANSI ED (erase in page).
| count | Parameter count | |
| params[0] | Region to erase |
Definition at line 82 of file bios_console.c.
References __asm__(), ANSIESC_ED_ALL, assert, bios_attr, and REAL_CODE.
00083 { 00084 /* We assume that we always clear the whole screen */ 00085 assert ( params[0] == ANSIESC_ED_ALL ); 00086 00087 __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" 00088 "int $0x10\n\t" 00089 "cli\n\t" ) 00090 : : "a" ( 0x0600 ), "b" ( bios_attr << 8 ), 00091 "c" ( 0 ), "d" ( 0xffff ) ); 00092 }
| static void bios_handle_sgr | ( | unsigned int | count, | |
| int | params[] | |||
| ) | [static] |
Handle ANSI SGR (set graphics rendition).
| count | Parameter count | |
| params | List of graphic rendition aspects |
Definition at line 100 of file bios_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, and bios_attr.
00100 { 00101 static const uint8_t bios_attr_fcols[10] = { 00102 ATTR_FCOL_BLACK, ATTR_FCOL_RED, ATTR_FCOL_GREEN, 00103 ATTR_FCOL_YELLOW, ATTR_FCOL_BLUE, ATTR_FCOL_MAGENTA, 00104 ATTR_FCOL_CYAN, ATTR_FCOL_WHITE, 00105 ATTR_FCOL_WHITE, ATTR_FCOL_WHITE /* defaults */ 00106 }; 00107 static const uint8_t bios_attr_bcols[10] = { 00108 ATTR_BCOL_BLACK, ATTR_BCOL_RED, ATTR_BCOL_GREEN, 00109 ATTR_BCOL_YELLOW, ATTR_BCOL_BLUE, ATTR_BCOL_MAGENTA, 00110 ATTR_BCOL_CYAN, ATTR_BCOL_WHITE, 00111 ATTR_BCOL_BLACK, ATTR_BCOL_BLACK /* defaults */ 00112 }; 00113 unsigned int i; 00114 int aspect; 00115 00116 for ( i = 0 ; i < count ; i++ ) { 00117 aspect = params[i]; 00118 if ( aspect == 0 ) { 00119 bios_attr = ATTR_DEFAULT; 00120 } else if ( aspect == 1 ) { 00121 bios_attr |= ATTR_BOLD; 00122 } else if ( aspect == 22 ) { 00123 bios_attr &= ~ATTR_BOLD; 00124 } else if ( ( aspect >= 30 ) && ( aspect <= 39 ) ) { 00125 bios_attr &= ~ATTR_FCOL_MASK; 00126 bios_attr |= bios_attr_fcols[ aspect - 30 ]; 00127 } else if ( ( aspect >= 40 ) && ( aspect <= 49 ) ) { 00128 bios_attr &= ~ATTR_BCOL_MASK; 00129 bios_attr |= bios_attr_bcols[ aspect - 40 ]; 00130 } 00131 } 00132 }
| static void bios_putchar | ( | int | character | ) | [static] |
Print a character to BIOS console.
| character | Character to be printed |
Definition at line 152 of file bios_console.c.
References __asm__(), ansiesc_process(), bios_attr, and REAL_CODE.
00152 { 00153 int discard_a, discard_b, discard_c; 00154 00155 /* Intercept ANSI escape sequences */ 00156 character = ansiesc_process ( &bios_ansiesc_ctx, character ); 00157 if ( character < 0 ) 00158 return; 00159 00160 /* Print character with attribute */ 00161 __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" 00162 /* Skip non-printable characters */ 00163 "cmpb $0x20, %%al\n\t" 00164 "jb 1f\n\t" 00165 /* Set attribute */ 00166 "movw $0x0001, %%cx\n\t" 00167 "movb $0x09, %%ah\n\t" 00168 "int $0x10\n\t" 00169 "\n1:\n\t" 00170 /* Print character */ 00171 "xorw %%bx, %%bx\n\t" 00172 "movb $0x0e, %%ah\n\t" 00173 "int $0x10\n\t" 00174 "cli\n\t" ) 00175 : "=a" ( discard_a ), "=b" ( discard_b ), 00176 "=c" ( discard_c ) 00177 : "a" ( character ), "b" ( bios_attr ) 00178 : "ebp" ); 00179 }
| static const char* scancode_to_ansi_seq | ( | unsigned int | scancode | ) | [static] |
Get ANSI escape sequence corresponding to BIOS scancode.
| scancode | BIOS scancode |
| ansi_seq | ANSI escape sequence, if any, otherwise NULL |
Definition at line 221 of file bios_console.c.
References ansi_sequences, BIOS_KEY, DBG, and NULL.
00221 { 00222 unsigned int bios_key = BIOS_KEY ( scancode ); 00223 00224 if ( bios_key < ( sizeof ( ansi_sequences ) / 00225 sizeof ( ansi_sequences[0] ) ) ) { 00226 return ansi_sequences[bios_key]; 00227 } 00228 DBG ( "Unrecognised BIOS scancode %02x\n", scancode ); 00229 return NULL; 00230 }
| static int bios_getchar | ( | void | ) | [static] |
Get character from BIOS console.
| character | Character read from console |
Definition at line 237 of file bios_console.c.
References __asm__(), ansi_input, REAL_CODE, and scancode_to_ansi_seq().
00237 { 00238 uint16_t keypress; 00239 unsigned int character; 00240 const char *ansi_seq; 00241 00242 /* If we are mid-sequence, pass out the next byte */ 00243 if ( ( character = *ansi_input ) ) { 00244 ansi_input++; 00245 return character; 00246 } 00247 00248 /* Read character from real BIOS console */ 00249 __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" 00250 "int $0x16\n\t" 00251 "cli\n\t" ) 00252 : "=a" ( keypress ) : "a" ( 0x1000 ) ); 00253 character = ( keypress & 0xff ); 00254 00255 /* If it's a normal character, just return it */ 00256 if ( character && ( character < 0x80 ) ) 00257 return character; 00258 00259 /* Otherwise, check for a special key that we know about */ 00260 if ( ( ansi_seq = scancode_to_ansi_seq ( keypress >> 8 ) ) ) { 00261 /* Start of escape sequence: return ESC (0x1b) */ 00262 ansi_input = ansi_seq; 00263 return 0x1b; 00264 } 00265 00266 return 0; 00267 }
| static int bios_iskey | ( | void | ) | [static] |
Check for character ready to read from BIOS console.
| True | Character available to read | |
| False | No character available to read |
Definition at line 275 of file bios_console.c.
References __asm__(), ansi_input, REAL_CODE, and ZF.
00275 { 00276 unsigned int discard_a; 00277 unsigned int flags; 00278 00279 /* If we are mid-sequence, we are always ready */ 00280 if ( *ansi_input ) 00281 return 1; 00282 00283 /* Otherwise check the real BIOS console */ 00284 __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" 00285 "int $0x16\n\t" 00286 "pushfw\n\t" 00287 "popw %w0\n\t" 00288 "cli\n\t" ) 00289 : "=r" ( flags ), "=a" ( discard_a ) 00290 : "a" ( 0x0100 ) ); 00291 return ( ! ( flags & ZF ) ); 00292 }
unsigned int bios_attr = ATTR_DEFAULT [static] |
Current character attribute.
Definition at line 51 of file bios_console.c.
Referenced by bios_handle_ed(), bios_handle_sgr(), and bios_putchar().
struct ansiesc_handler bios_ansiesc_handlers[] [static] |
Initial value:
{
{ ANSIESC_CUP, bios_handle_cup },
{ ANSIESC_ED, bios_handle_ed },
{ ANSIESC_SGR, bios_handle_sgr },
{ 0, NULL }
}
Definition at line 135 of file bios_console.c.
struct ansiesc_context bios_ansiesc_ctx [static] |
Initial value:
{
.handlers = bios_ansiesc_handlers,
}
Definition at line 143 of file bios_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 189 of file bios_console.c.
const char* ansi_sequences[] [static] |
Initial value:
{
[ BIOS_KEY ( 0x42 ) ] = "[19~",
[ BIOS_KEY ( 0x47 ) ] = "[H",
[ BIOS_KEY ( 0x48 ) ] = "[A",
[ BIOS_KEY ( 0x4b ) ] = "[D",
[ BIOS_KEY ( 0x4d ) ] = "[C",
[ BIOS_KEY ( 0x4f ) ] = "[F",
[ BIOS_KEY ( 0x50 ) ] = "[B",
[ BIOS_KEY ( 0x53 ) ] = "[3~",
}
Definition at line 204 of file bios_console.c.
| struct console_driver bios_console __console_driver |
Initial value:
{
.putchar = bios_putchar,
.getchar = bios_getchar,
.iskey = bios_iskey,
}
Definition at line 294 of file bios_console.c.
1.5.7.1