iPXE
console.c File Reference
#include "stddef.h"
#include <ipxe/console.h>
#include <ipxe/process.h>
#include <ipxe/nap.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int putchar (int character)
 Write a single character to each console device.
static struct console_driverhas_input (void)
 Check to see if any input is available on any console.
int getchar (void)
 Read a single character from any console.
int iskey (void)
 Check for available input on any console.
int console_configure (struct console_configuration *config)
 Configure console.

Variables

int console_usage = CONSOLE_USAGE_STDOUT
 Current console usage.
unsigned int console_width = CONSOLE_DEFAULT_WIDTH
 Console width.
unsigned int console_height = CONSOLE_DEFAULT_HEIGHT
 Console height.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ putchar()

int putchar ( int character)

Write a single character to each console device.

Parameters
characterCharacter to be written
Return values
characterCharacter written

The character is written out to all enabled console devices, using each device's console_driver::putchar() method.

Definition at line 29 of file console.c.

29 {
30 struct console_driver *console;
31
32 /* Automatic LF -> CR,LF translation */
33 if ( character == '\n' )
34 putchar ( '\r' );
35
36 for_each_table_entry ( console, CONSOLES ) {
37 if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
38 ( console_usage & console->usage ) &&
39 console->putchar )
40 console->putchar ( character );
41 }
42
43 return character;
44}
int console_usage
Current console usage.
Definition console.c:12
int putchar(int character)
Write a single character to each console device.
Definition console.c:29
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition console.h:109
#define CONSOLES
Console driver table.
Definition console.h:115
A console driver.
Definition console.h:56
void(* putchar)(int character)
Write a character to the console.
Definition console.h:69
int usage
Console usage bitmask.
Definition console.h:102
int disabled
Console disabled flags.
Definition console.h:63
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References CONSOLE_DISABLED_OUTPUT, console_usage, CONSOLES, console_driver::disabled, for_each_table_entry, console_driver::putchar, putchar(), and console_driver::usage.

Referenced by ansiscr_putc(), clrline(), eepro_poll(), epic100_open(), falcon_init_xmac(), get_eeprom_data(), int21(), monojob_clear(), print_user_string(), printf_putchar(), putchar(), readline_history(), and sync_console().

◆ has_input()

struct console_driver * has_input ( void )
static

Check to see if any input is available on any console.

Return values
consoleConsole device that has input available, or NULL

All enabled console devices are checked once for available input using each device's console_driver::iskey() method. The first console device that has available input will be returned, if any.

Definition at line 55 of file console.c.

55 {
56 struct console_driver *console;
57
58 for_each_table_entry ( console, CONSOLES ) {
59 if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
60 console->iskey ) {
61 if ( console->iskey () )
62 return console;
63 }
64 }
65 return NULL;
66}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define CONSOLE_DISABLED_INPUT
Console is disabled for input.
Definition console.h:106
int(* iskey)(void)
Check for available input.
Definition console.h:88

References CONSOLE_DISABLED_INPUT, CONSOLES, console_driver::disabled, for_each_table_entry, console_driver::iskey, and NULL.

Referenced by getchar(), and iskey().

◆ getchar()

int getchar ( void )

Read a single character from any console.

Return values
characterCharacter read from a console.

A character will be read from the first enabled console device that has input available using that console's console_driver::getchar() method. If no console has input available to be read, this method will block. To perform a non-blocking read, use something like

int key = iskey() ? getchar() : -1;
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
int getchar(void)
Read a single character from any console.
Definition console.c:86
int iskey(void)
Check for available input on any console.
Definition console.c:131

The character read will not be echoed back to any console.

Definition at line 86 of file console.c.

86 {
87 struct console_driver *console;
88 int character;
89
90 while ( 1 ) {
91 console = has_input();
92 if ( console && console->getchar ) {
93 character = console->getchar ();
94 break;
95 }
96
97 /* Doze for a while (until the next interrupt). This works
98 * fine, because the keyboard is interrupt-driven, and the
99 * timer interrupt (approx. every 50msec) takes care of the
100 * serial port, which is read by polling. This reduces the
101 * power dissipation of a modern CPU considerably, and also
102 * makes Etherboot waiting for user interaction waste a lot
103 * less CPU time in a VMware session.
104 */
105 cpu_nap();
106
107 /* Keep processing background tasks while we wait for
108 * input.
109 */
110 step();
111 }
112
113 /* CR -> LF translation */
114 if ( character == '\r' )
115 character = '\n';
116
117 return character;
118}
static struct console_driver * has_input(void)
Check to see if any input is available on any console.
Definition console.c:55
void cpu_nap(void)
Sleep with interrupts enabled until next CPU interrupt.
void step(void)
Single-step a single process.
Definition process.c:99
int(* getchar)(void)
Read a character from the console.
Definition console.h:79

References cpu_nap(), console_driver::getchar, has_input(), and step().

Referenced by ansiscr_getc(), dbg_more(), dbg_pause(), getchar_timeout(), int21(), keypress_interrupted(), loopback_wait(), and monojob_wait().

◆ iskey()

int iskey ( void )

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}

References has_input().

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

◆ console_configure()

int console_configure ( struct console_configuration * config)

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 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

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

Variable Documentation

◆ console_usage

int console_usage = CONSOLE_USAGE_STDOUT

Current console usage.

Definition at line 12 of file console.c.

Referenced by console_set_usage(), and putchar().

◆ console_width

unsigned int console_width = CONSOLE_DEFAULT_WIDTH

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 = CONSOLE_DEFAULT_HEIGHT

Console height.

Definition at line 18 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().