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

void putchar ( int  character)

Write a single character to each console device.

Parameters
characterCharacter to be written

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

Definition at line 27 of file console.c.

27  {
28  struct console_driver *console;
29 
30  /* Automatic LF -> CR,LF translation */
31  if ( character == '\n' )
32  putchar ( '\r' );
33 
34  for_each_table_entry ( console, CONSOLES ) {
35  if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
36  ( console_usage & console->usage ) &&
37  console->putchar )
38  console->putchar ( character );
39  }
40 }
#define CONSOLES
Console driver table.
Definition: console.h:114
void putchar(int character)
Write a single character to each console device.
Definition: console.c:27
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:358
int disabled
Console disabled flags.
Definition: console.h:62
A console driver.
Definition: console.h:55

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

51  {
52  struct console_driver *console;
53 
54  for_each_table_entry ( console, CONSOLES ) {
55  if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
56  console->iskey ) {
57  if ( console->iskey () )
58  return console;
59  }
60  }
61  return NULL;
62 }
#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:358
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:362

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

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

127  {
128  return has_input() ? 1 : 0;
129 }
static struct console_driver * has_input(void)
Check to see if any input is available on any console.
Definition: console.c:51

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

143  {
144  struct console_driver *console;
145  int rc;
146 
147  /* Reset console width and height */
149 
150  /* Try to configure each console */
151  for_each_table_entry ( console, CONSOLES ) {
152  if ( ( console->configure ) &&
153  ( ( rc = console->configure ( config ) ) != 0 ) )
154  goto err;
155  }
156 
157  return 0;
158 
159  err:
160  /* Reset all consoles, avoiding a potential infinite loop */
161  if ( config )
162  console_reset();
163  return rc;
164 }
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:358
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().