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

Macros

#define CONSOLE_DISABLED_INPUT   0x0001
 Console is disabled for input. More...
 
#define CONSOLE_DISABLED_OUTPUT   0x0002
 Console is disabled for output. More...
 
#define CONSOLE_DISABLED   ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
 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...
 
#define CONSOLE_USAGE_ALL
 All console usages. More...
 
#define CONSOLE_EXPLICIT(console)   ( ( 2 * console + 1 ) != 2 )
 Test to see if console has an explicit usage. More...
 
#define CONSOLE_DEFAULT_WIDTH   80
 Default console width. More...
 
#define CONSOLE_DEFAULT_HEIGHT   25
 Default console height. More...
 

Functions

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

Variables

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_DISABLED_INPUT

#define CONSOLE_DISABLED_INPUT   0x0001

Console is disabled for input.

Definition at line 105 of file console.h.

◆ CONSOLE_DISABLED_OUTPUT

#define CONSOLE_DISABLED_OUTPUT   0x0002

Console is disabled for output.

Definition at line 108 of file console.h.

◆ CONSOLE_DISABLED

#define CONSOLE_DISABLED   ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )

Console is disabled for all uses.

Definition at line 111 of file console.h.

◆ CONSOLES

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

◆ CONSOLE_EXPLICIT

#define CONSOLE_EXPLICIT (   console)    ( ( 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 168 of file console.h.

◆ CONSOLE_DEFAULT_WIDTH

#define CONSOLE_DEFAULT_WIDTH   80

Default console width.

Definition at line 171 of file console.h.

◆ CONSOLE_DEFAULT_HEIGHT

#define CONSOLE_DEFAULT_HEIGHT   25

Default console height.

Definition at line 174 of file console.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ console_set_usage()

static int console_set_usage ( int  usage)
inlinestatic

Set console usage.

Parameters
usageNew console usage
Return values
old_usagePrevious console usage

Definition at line 187 of file console.h.

187  {
188  int old_usage = console_usage;
189 
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 
)
inlinestatic

Set console size.

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

◆ getkey()

int getkey ( unsigned long  timeout)

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

71  {
72  int character;
73  unsigned int n = 0;
74 
75  character = getchar_timeout ( timeout );
76  if ( character != ESC )
77  return character;
78 
79  character = getchar_timeout ( GETKEY_TIMEOUT );
80  if ( character < 0 )
81  return ESC;
82 
83  if ( isalpha ( character ) )
84  return ( toupper ( character ) - 'A' + 1 );
85 
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  }
94 
95  return ESC;
96 }
static int isalpha(int character)
Check if character is alphabetic.
Definition: ctype.h:64
static int toupper(int character)
Convert character to upper case.
Definition: ctype.h:109
static int isdigit(int character)
Check if character is a decimal digit.
Definition: ctype.h:18
#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)
unsigned int n
Definition: entropy.h:159
#define GETKEY_TIMEOUT
Definition: getkey.c:39
#define KEY_ANSI(n, terminator)
Definition: keys.h:60

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

Referenced by bios_inject(), login_ui(), 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)

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

◆ console_reset()

static void console_reset ( void  )
inlinestatic

Reset console.

Definition at line 214 of file console.h.

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

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