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

Variables

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

Detailed Description

Definition in file console.c.


Function Documentation

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

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

                               {
        struct console_driver *console;

        /* Automatic LF -> CR,LF translation */
        if ( character == '\n' )
                putchar ( '\r' );

        for_each_table_entry ( console, CONSOLES ) {
                if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
                     ( console_usage & console->usage ) &&
                     console->putchar )
                        console->putchar ( character );
        }
}
static struct console_driver* has_input ( void  ) [static, read]

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.

References CONSOLE_DISABLED_INPUT, CONSOLES, console_driver::disabled, for_each_table_entry, console_driver::iskey, and NULL.

Referenced by getchar(), and iskey().

                                                  {
        struct console_driver *console;

        for_each_table_entry ( console, CONSOLES ) {
                if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
                     console->iskey ) {
                        if ( console->iskey () )
                                return console;
                }
        }
        return NULL;
}
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.

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

                     {
        struct console_driver *console;
        int character;

        while ( 1 ) {
                console = has_input();
                if ( console && console->getchar ) {
                        character = console->getchar ();
                        break;
                }

                /* Doze for a while (until the next interrupt).  This works
                 * fine, because the keyboard is interrupt-driven, and the
                 * timer interrupt (approx. every 50msec) takes care of the
                 * serial port, which is read by polling.  This reduces the
                 * power dissipation of a modern CPU considerably, and also
                 * makes Etherboot waiting for user interaction waste a lot
                 * less CPU time in a VMware session.
                 */
                cpu_nap();

                /* Keep processing background tasks while we wait for
                 * input.
                 */
                step();
        }

        /* CR -> LF translation */
        if ( character == '\r' )
                character = '\n';

        return character;
}
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 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;
}

Variable Documentation

Current console usage.

Definition at line 11 of file console.c.

Referenced by console_set_usage(), and putchar().

Console width.

Definition at line 14 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().

Console height.

Definition at line 17 of file console.c.

Referenced by bios_handle_ed(), and console_set_size().