iPXE
console.h File Reference

User interaction. More...

#include <stddef.h>
#include <stdio.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  console_configuration
 A console configuration. More...
struct  console_driver
 A console driver. More...

Macros

#define CONSOLE_DISABLED_INPUT   0x0001
 Console is disabled for input.
#define CONSOLE_DISABLED_OUTPUT   0x0002
 Console is disabled for output.
#define CONSOLE_DISABLED   ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
 Console is disabled for all uses.
#define CONSOLES   __table ( struct console_driver, "consoles" )
 Console driver table.
#define __console_driver   __table_entry ( CONSOLES, 01 )
 Mark a struct console_driver as being part of the console drivers table.
#define CONSOLE_USAGE_STDOUT   0x0001
 Standard output.
#define CONSOLE_USAGE_DEBUG   0x0002
 Debug messages.
#define CONSOLE_USAGE_TUI   0x0004
 Text-based user interface.
#define CONSOLE_USAGE_LOG   0x0008
 Log messages.
#define CONSOLE_USAGE_ALL
 All console usages.
#define CONSOLE_EXPLICIT(console)
 Test to see if console has an explicit usage.
#define CONSOLE_DEFAULT_WIDTH   80
 Default console width.
#define CONSOLE_DEFAULT_HEIGHT   25
 Default console height.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int console_set_usage (int usage)
 Set console usage.
static void console_set_size (unsigned int width, unsigned int height)
 Set console size.
int iskey (void)
 Check for available input on any console.
int getkey (unsigned long timeout)
 Get single keypress.
int console_configure (struct console_configuration *config)
 Configure console.
static void console_reset (void)
 Reset console.

Variables

int console_usage
 Current console usage.
unsigned int console_width
 Console width.
unsigned int console_height
 Console height.

Detailed Description

User interaction.

Various console devices can be selected via the build options CONSOLE_FIRMWARE, CONSOLE_SERIAL etc. The console functions putchar(), getchar() and iskey() delegate to the individual console drivers.

Definition in file console.h.

Macro Definition Documentation

◆ CONSOLE_DISABLED_INPUT

#define CONSOLE_DISABLED_INPUT   0x0001

Console is disabled for input.

Definition at line 106 of file console.h.

Referenced by has_input().

◆ CONSOLE_DISABLED_OUTPUT

#define CONSOLE_DISABLED_OUTPUT   0x0002

Console is disabled for output.

Definition at line 109 of file console.h.

Referenced by efifb_configure(), putchar(), and vesafb_configure().

◆ CONSOLE_DISABLED

#define CONSOLE_DISABLED   ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )

Console is disabled for all uses.

Definition at line 112 of file console.h.

Referenced by apply_syslog_settings(), apply_syslogs_settings(), debugcon_init(), efifb_configure(), and vesafb_configure().

◆ CONSOLES

#define CONSOLES   __table ( struct console_driver, "consoles" )

Console driver table.

Definition at line 115 of file console.h.

Referenced by console_configure(), has_input(), and putchar().

◆ __console_driver

struct console_driver vesafb_console __console_driver   __table_entry ( CONSOLES, 01 )

Mark a struct console_driver as being part of the console drivers table.

VESA frame buffer console driver.

INT13 console driver.

EFI graphics output protocol console driver.

Encrypted syslog console driver.

Use as e.g.

struct console_driver my_console __console_driver = {
.putchar = my_putchar,
.getchar = my_getchar,
.iskey = my_iskey,
};
#define __console_driver
Mark a struct console_driver as being part of the console drivers table.
Definition console.h:134
A console driver.
Definition console.h:56

Definition at line 134 of file console.h.

◆ CONSOLE_EXPLICIT

#define CONSOLE_EXPLICIT ( console)
Value:
( ( 2 * console + 1 ) != 2 )

Test to see if console has an explicit usage.

Parameters
consoleConsole definition (e.g. CONSOLE_PCBIOS)
Return values
explicitConsole has an explicit usage

This relies upon the trick that the expression ( 2 * N + 1 ) will be valid even if N is defined to be empty, since it will then evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.

Definition at line 169 of file console.h.

◆ CONSOLE_DEFAULT_WIDTH

#define CONSOLE_DEFAULT_WIDTH   80

Default console width.

Definition at line 172 of file console.h.

Referenced by console_configure().

◆ CONSOLE_DEFAULT_HEIGHT

#define CONSOLE_DEFAULT_HEIGHT   25

Default console height.

Definition at line 175 of file console.h.

Referenced by console_configure().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ console_set_usage()

int console_set_usage ( int usage)
inlinestatic

Set console usage.

Parameters
usageNew console usage
Return values
old_usagePrevious console usage

Definition at line 188 of file console.h.

188 {
189 int old_usage = console_usage;
190
191 console_usage = usage;
192 return old_usage;
193}
int console_usage
Current console usage.
Definition console.c:12

References console_usage.

Referenced by ansiscr_exit(), ansiscr_init(), dbg_printf(), and log_vprintf().

◆ console_set_size()

void console_set_size ( unsigned int width,
unsigned int height )
inlinestatic

Set console size.

Parameters
widthWidth, in characters
heightHeight, in characters

Definition at line 202 of file console.h.

202 {
203 console_width = width;
204 console_height = height;
205}
unsigned int console_width
Console width.
Definition console.c:15
unsigned int console_height
Console height.
Definition console.c:18

References console_height, console_width, console_configuration::height, and console_configuration::width.

Referenced by console_configure(), and fbcon_init().

◆ iskey()

int iskey ( void )
extern

Check for available input on any console.

Return values
is_availableInput is available on a console

All enabled console devices are checked once for available input using each device's console_driver::iskey() method. If any console device has input available, this call will return true. If this call returns true, you can then safely call getchar() without blocking.

Definition at line 131 of file console.c.

131 {
132 return has_input() ? 1 : 0;
133}
static struct console_driver * has_input(void)
Check to see if any input is available on any console.
Definition console.c:55

References has_input().

Referenced by ansiscr_peek(), bios_inject(), getchar_timeout(), int21(), keypress_interrupted(), loopback_wait(), monojob_wait(), and pxe_menu_prompt_and_select().

◆ getkey()

int getkey ( unsigned long timeout)
extern

Get single keypress.

Parameters
timeoutTimeout period, in ticks (0=indefinite)
Return values
keyKey pressed

The returned key will be an ASCII value or a KEY_XXX special constant. This function differs from getchar() in that getchar() will return "special" keys (e.g. cursor keys) as a series of characters forming an ANSI escape sequence.

Definition at line 72 of file getkey.c.

72 {
73 int character;
74 unsigned int n = 0;
75
76 character = getchar_timeout ( timeout );
77 if ( character != ESC )
78 return character;
79
80 character = getchar_timeout ( GETKEY_TIMEOUT );
81 if ( character < 0 )
82 return ESC;
83
84 if ( isalpha ( character ) )
85 return ( toupper ( character ) - 'A' + 1 );
86
87 while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) {
88 if ( isdigit ( character ) ) {
89 n = ( ( n * 10 ) + ( character - '0' ) );
90 continue;
91 }
92 if ( character >= 0x40 )
93 return KEY_ANSI ( n, character );
94 }
95
96 return ESC;
97}
#define ESC
Escape character.
Definition ansiesc.h:93
static int toupper(int character)
Convert character to upper case.
Definition ctype.h:121
static int isdigit(int character)
Check if character is a decimal digit.
Definition ctype.h:30
static int isalpha(int character)
Check if character is alphabetic.
Definition ctype.h:76
void timeout(int)
#define GETKEY_TIMEOUT
Definition getkey.c:40
static int getchar_timeout(unsigned long timeout)
Read character from console if available within timeout period.
Definition getkey.c:48
#define KEY_ANSI(n, terminator)
Construct ANSI escape sequence key value.
Definition keys.h:87

References ESC, getchar_timeout(), GETKEY_TIMEOUT, isalpha(), isdigit(), KEY_ANSI, timeout(), and toupper().

Referenced by bios_inject(), form_loop(), main_loop(), menu_loop(), prompt(), pxe_menu_prompt_and_select(), pxe_menu_select(), and readline_history().

◆ console_configure()

int console_configure ( struct console_configuration * config)
extern

Configure console.

Parameters
configConsole configuration
Return values
rcReturn status code

The configuration is passed to all configurable consoles, including those which are currently disabled. Consoles may choose to enable or disable themselves depending upon the configuration.

If configuration fails, then all consoles will be reset.

Definition at line 147 of file console.c.

147 {
148 struct console_driver *console;
149 int rc;
150
151 /* Reset console width and height */
153
154 /* Try to configure each console */
155 for_each_table_entry ( console, CONSOLES ) {
156 if ( ( console->configure ) &&
157 ( ( rc = console->configure ( config ) ) != 0 ) )
158 goto err;
159 }
160
161 return 0;
162
163 err:
164 /* Reset all consoles, avoiding a potential infinite loop */
165 if ( config )
167 return rc;
168}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define CONSOLE_DEFAULT_WIDTH
Default console width.
Definition console.h:172
static void console_reset(void)
Reset console.
Definition console.h:215
#define CONSOLES
Console driver table.
Definition console.h:115
#define CONSOLE_DEFAULT_HEIGHT
Default console height.
Definition console.h:175
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition console.h:202
int(* configure)(struct console_configuration *config)
Configure console.
Definition console.h:95
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References console_driver::configure, CONSOLE_DEFAULT_HEIGHT, CONSOLE_DEFAULT_WIDTH, console_reset(), console_set_size(), CONSOLES, for_each_table_entry, and rc.

Referenced by console_exec(), and console_reset().

◆ console_reset()

void console_reset ( void )
inlinestatic

Reset console.

Definition at line 215 of file console.h.

215 {
216
218}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
int console_configure(struct console_configuration *config)
Configure console.
Definition console.c:147

References console_configure(), and NULL.

Referenced by call_bootsector(), com32_exec(), comboot_exec(), console_configure(), efi_image_exec(), efi_snp_load_file(), pxe_exec(), and shutdown().

Variable Documentation

◆ console_usage

int console_usage
extern

Current console usage.

Definition at line 12 of file console.c.

Referenced by console_set_usage(), and putchar().

◆ console_width

unsigned int console_width
extern

Console width.

Definition at line 15 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().

◆ console_height

unsigned int console_height
extern

Console height.

Definition at line 18 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().