Data Structures | Macros | Functions | Variables
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...


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


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


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

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 is disabled for input.

Definition at line 105 of file console.h.



Console is disabled for output.

Definition at line 108 of file console.h.



Console is disabled for all uses.

Definition at line 111 of file console.h.


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

Console driver table.

Definition at line 114 of file console.h.

◆ __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,

Definition at line 133 of file console.h.


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

Test to see if console has an explicit usage.

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 168 of file console.h.



Default console width.

Definition at line 171 of file console.h.



Default console height.

Definition at line 174 of file console.h.

Function Documentation



◆ console_set_usage()

static int console_set_usage ( int  usage)

Set console usage.

usageNew console usage
Return values
old_usagePrevious console usage

Definition at line 187 of file console.h.

187  {
188  int old_usage = console_usage;
191  return old_usage;
192 }
int usage
Console usage bitmask.
Definition: console.h:101
int console_usage
Current console usage.
Definition: console.c:11

References console_usage.

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

◆ console_set_size()

static void console_set_size ( unsigned int  width,
unsigned int  height 

Set console size.

widthWidth, in characters
heightHeight, in characters

Definition at line 201 of file console.h.

201  {
202  console_width = width;
203  console_height = height;
204 }
unsigned int console_width
Console width.
Definition: console.c:14
unsigned int console_height
Console height.
Definition: console.c:17

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

Referenced by console_configure(), and fbcon_init().

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

◆ getkey()

int getkey ( unsigned long  timeout)

Get single keypress.

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 71 of file getkey.c.

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

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

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

◆ console_configure()

int console_configure ( struct console_configuration config)

Configure console.

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;
150  /* Reset console width and height */
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  }
160  return 0;
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
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
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().

◆ console_reset()

static void console_reset ( void  )

Reset console.

Definition at line 214 of file console.h.

214  {
217 }
int console_configure(struct console_configuration *config)
Configure console.
Definition: console.c:146
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

Definition at line 17 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().