iPXE
Data Structures | Defines | 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...

Defines

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

Functions

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

Variables

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

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.


Define Documentation

#define CONSOLE_DISABLED_INPUT   0x0001

Console is disabled for input.

Definition at line 105 of file console.h.

Referenced by has_input().

#define CONSOLE_DISABLED_OUTPUT   0x0002

Console is disabled for output.

Definition at line 108 of file console.h.

Referenced by efifb_configure(), putchar(), and vesafb_configure().

Console is disabled for all uses.

Definition at line 111 of file console.h.

Referenced by apply_syslog_settings(), apply_syslogs_settings(), debugcon_init(), efifb_configure(), and vesafb_configure().

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

Console driver table.

Definition at line 114 of file console.h.

Referenced by console_configure(), has_input(), and putchar().

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.

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.

#define CONSOLE_DEFAULT_WIDTH   80

Default console width.

Definition at line 171 of file console.h.

Referenced by console_configure().

#define CONSOLE_DEFAULT_HEIGHT   25

Default console height.

Definition at line 174 of file console.h.

Referenced by console_configure().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int console_set_usage ( int  usage) [inline, static]

Set console usage.

Parameters:
usageNew console usage
Return values:
old_usagePrevious console usage

Definition at line 187 of file console.h.

References console_usage.

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

                                {
        int old_usage = console_usage;

        console_usage = usage;
        return old_usage;
}
static void console_set_size ( unsigned int  width,
unsigned int  height 
) [inline, static]

Set console size.

Parameters:
widthWidth, in characters
heightHeight, in characters

Definition at line 201 of file console.h.

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

Referenced by console_configure(), and fbcon_init().

                                                             {
        console_width = width;
        console_height = height;
}
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.

References has_input().

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

                   {
        return has_input() ? 1 : 0;
}
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.

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

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

                                     {
        int character;
        unsigned int n = 0;

        character = getchar_timeout ( timeout );
        if ( character != ESC )
                return character;

        character = getchar_timeout ( GETKEY_TIMEOUT );
        if ( character < 0 )
                return ESC;

        if ( isalpha ( character ) )
                return ( toupper ( character ) - 'A' + 1 );

        while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) {
                if ( isdigit ( character ) ) {
                        n = ( ( n * 10 ) + ( character - '0' ) );
                        continue;
                }
                if ( character >= 0x40 )
                        return KEY_ANSI ( n, character );
        }

        return ESC;
}
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.

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

                                                               {
        struct console_driver *console;
        int rc;

        /* Reset console width and height */
        console_set_size ( CONSOLE_DEFAULT_WIDTH, CONSOLE_DEFAULT_HEIGHT );

        /* Try to configure each console */
        for_each_table_entry ( console, CONSOLES ) {
                if ( ( console->configure ) &&
                     ( ( rc = console->configure ( config ) ) != 0 ) )
                                goto err;
        }

        return 0;

 err:
        /* Reset all consoles, avoiding a potential infinite loop */
        if ( config )
                console_reset();
        return rc;
}
static void console_reset ( void  ) [inline, static]

Variable Documentation

Current console usage.

Definition at line 11 of file console.c.

Referenced by console_set_usage(), and putchar().

unsigned int console_width

Console width.

Definition at line 14 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().

unsigned int console_height

Console height.

Definition at line 17 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().