3 #include <gpxe/process.h>
8 FILE_LICENCE ( GPL2_OR_LATER
);
11 * Write a single character to each console device.
13 * @v character Character to be written
17 * The character is written out to all enabled console devices, using
18 * each device's console_driver::putchar() method.
21 void putchar ( int character
) {
22 struct console_driver
*console
;
24 /* Automatic LF -> CR,LF translation */
25 if ( character
== '\n' )
28 for_each_table_entry ( console
, CONSOLES
) {
29 if ( ( ! console
->disabled
) && console
->putchar
)
30 console
->putchar ( character
);
35 * Check to see if any input is available on any console.
38 * @ret console Console device that has input available, if any.
39 * @ret NULL No console device has input available.
42 * All enabled console devices are checked once for available input
43 * using each device's console_driver::iskey() method. The first
44 * console device that has available input will be returned, if any.
47 static struct console_driver
* has_input ( void ) {
48 struct console_driver
*console
;
50 for_each_table_entry ( console
, CONSOLES
) {
51 if ( ( ! console
->disabled
) && console
->iskey
) {
52 if ( console
->iskey () )
60 * Read a single character from any console.
63 * @ret character Character read from a console.
66 * A character will be read from the first enabled console device that
67 * has input available using that console's console_driver::getchar()
68 * method. If no console has input available to be read, this method
69 * will block. To perform a non-blocking read, use something like
73 * int key = iskey() ? getchar() : -1;
77 * The character read will not be echoed back to any console.
80 int getchar ( void ) {
81 struct console_driver
*console
;
85 console
= has_input();
86 if ( console
&& console
->getchar
) {
87 character
= console
->getchar ();
91 /* Doze for a while (until the next interrupt). This works
92 * fine, because the keyboard is interrupt-driven, and the
93 * timer interrupt (approx. every 50msec) takes care of the
94 * serial port, which is read by polling. This reduces the
95 * power dissipation of a modern CPU considerably, and also
96 * makes Etherboot waiting for user interaction waste a lot
97 * less CPU time in a VMware session.
101 /* Keep processing background tasks while we wait for
107 /* CR -> LF translation */
108 if ( character
== '\r' )
114 /** Check for available input on any console.
117 * @ret True Input is available on a console
118 * @ret False Input is not available on any console
121 * All enabled console devices are checked once for available input
122 * using each device's console_driver::iskey() method. If any console
123 * device has input available, this call will return True. If this
124 * call returns True, you can then safely call getchar() without
129 return has_input() ? 1 : 0;