iPXE
Functions | Variables
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)
 
int putchar (int character)
 Write a single character to each console device. More...
 
static struct console_driverhas_input (void)
 Check to see if any input is available on any console. More...
 
int getchar (void)
 Read a single character from any console. More...
 
int iskey (void)
 Check for available input on any console. More...
 
int console_configure (struct console_configuration *config)
 Configure console. More...
 

Variables

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 28 of file console.c.

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

References CONSOLE_DISABLED_OUTPUT, console_usage, CONSOLES, console_driver::disabled, for_each_table_entry, putchar(), console_driver::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()

static 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 54 of file console.c.

54  {
55  struct console_driver *console;
56 
57  for_each_table_entry ( console, CONSOLES ) {
58  if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
59  console->iskey ) {
60  if ( console->iskey () )
61  return console;
62  }
63  }
64  return NULL;
65 }
#define CONSOLES
Console driver table.
Definition: console.h:114
#define CONSOLE_DISABLED_INPUT
Console is disabled for input.
Definition: console.h:105
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
int(* iskey)(void)
Check for available input.
Definition: console.h:87
int disabled
Console disabled flags.
Definition: console.h:62
A console driver.
Definition: console.h:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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;

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

Definition at line 85 of file console.c.

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

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 130 of file console.c.

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

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 146 of file console.c.

146  {
147  struct console_driver *console;
148  int rc;
149 
150  /* Reset console width and height */
152 
153  /* Try to configure each console */
154  for_each_table_entry ( console, CONSOLES ) {
155  if ( ( console->configure ) &&
156  ( ( rc = console->configure ( config ) ) != 0 ) )
157  goto err;
158  }
159 
160  return 0;
161 
162  err:
163  /* Reset all consoles, avoiding a potential infinite loop */
164  if ( config )
165  console_reset();
166  return rc;
167 }
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition: console.h:201
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define CONSOLE_DEFAULT_WIDTH
Default console width.
Definition: console.h:171
#define CONSOLES
Console driver table.
Definition: console.h:114
int(* configure)(struct console_configuration *config)
Configure console.
Definition: console.h:94
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
static void console_reset(void)
Reset console.
Definition: console.h:214
A console driver.
Definition: console.h:55
#define CONSOLE_DEFAULT_HEIGHT
Default console height.
Definition: console.h:174

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 11 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 14 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 17 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().