|
@@ -1,31 +1,24 @@
|
1
|
|
-/*
|
2
|
|
- * Central console switch. Various console devices can be selected
|
3
|
|
- * via the build options CONSOLE_FIRMWARE, CONSOLE_SERIAL etc.
|
4
|
|
- * config.c picks up on these definitions and drags in the relevant
|
5
|
|
- * objects. The linker compiles the console_drivers table for us; we
|
6
|
|
- * simply delegate to each console_driver that we find in the table.
|
7
|
|
- *
|
8
|
|
- * Doing it this way allows for changing CONSOLE_XXX without
|
9
|
|
- * rebuilding anything other than config.o. This is extremely useful
|
10
|
|
- * for rom-o-matic.
|
11
|
|
- */
|
12
|
|
-
|
13
|
1
|
#include "stddef.h"
|
14
|
2
|
#include "console.h"
|
15
|
3
|
|
16
|
|
-/* FIXME: we need a cleaner way to pick up cpu_nap(). It makes a
|
17
|
|
- * real-mode call, and so we don't want to use it with LinuxBIOS.
|
18
|
|
- */
|
|
4
|
+/** @file */
|
|
5
|
+
|
19
|
6
|
#include "bios.h"
|
20
|
7
|
|
21
|
8
|
static struct console_driver console_drivers[0] __table_start ( console );
|
22
|
9
|
static struct console_driver console_drivers_end[0] __table_end ( console );
|
23
|
10
|
|
24
|
|
-/*****************************************************************************
|
25
|
|
- * putchar : write a single character to each console
|
26
|
|
- *****************************************************************************
|
|
11
|
+/**
|
|
12
|
+ * Write a single character to each console device.
|
|
13
|
+ *
|
|
14
|
+ * @v character Character to be written
|
|
15
|
+ * @ret None
|
|
16
|
+ * @err None
|
|
17
|
+ *
|
|
18
|
+ * The character is written out to all enabled console devices, using
|
|
19
|
+ * each device's console_driver::putchar() method.
|
|
20
|
+ *
|
27
|
21
|
*/
|
28
|
|
-
|
29
|
22
|
void putchar ( int character ) {
|
30
|
23
|
struct console_driver *console;
|
31
|
24
|
|
|
@@ -40,10 +33,18 @@ void putchar ( int character ) {
|
40
|
33
|
}
|
41
|
34
|
}
|
42
|
35
|
|
43
|
|
-/*****************************************************************************
|
44
|
|
- * has_input : check to see if any input is available on any console,
|
45
|
|
- * and return a pointer to the console device if so
|
46
|
|
- *****************************************************************************
|
|
36
|
+/**
|
|
37
|
+ * Check to see if any input is available on any console.
|
|
38
|
+ *
|
|
39
|
+ * @v None
|
|
40
|
+ * @ret console Console device that has input available, if any.
|
|
41
|
+ * @ret NULL No console device has input available.
|
|
42
|
+ * @err None
|
|
43
|
+ *
|
|
44
|
+ * All enabled console devices are checked once for available input
|
|
45
|
+ * using each device's console_driver::iskey() method. The first
|
|
46
|
+ * console device that has available input will be returned, if any.
|
|
47
|
+ *
|
47
|
48
|
*/
|
48
|
49
|
static struct console_driver * has_input ( void ) {
|
49
|
50
|
struct console_driver *console;
|
|
@@ -58,13 +59,30 @@ static struct console_driver * has_input ( void ) {
|
58
|
59
|
return NULL;
|
59
|
60
|
}
|
60
|
61
|
|
61
|
|
-/*****************************************************************************
|
62
|
|
- * getchar : read a single character from any console
|
|
62
|
+/**
|
|
63
|
+ * Read a single character from any console.
|
|
64
|
+ *
|
|
65
|
+ * @v None
|
|
66
|
+ * @ret character Character read from a console.
|
|
67
|
+ * @err None
|
|
68
|
+ *
|
|
69
|
+ * A character will be read from the first enabled console device that
|
|
70
|
+ * has input available using that console's console_driver::getchar()
|
|
71
|
+ * method. If no console has input available to be read, this method
|
|
72
|
+ * will block. To perform a non-blocking read, use something like
|
|
73
|
+ *
|
|
74
|
+ * @code
|
|
75
|
+ *
|
|
76
|
+ * int key = iskey() ? getchar() : -1;
|
|
77
|
+ *
|
|
78
|
+ * @endcode
|
|
79
|
+ *
|
|
80
|
+ * The character read will not be echoed back to any console.
|
|
81
|
+ *
|
|
82
|
+ * @bug We need a cleaner way to pick up cpu_nap(). It makes a
|
|
83
|
+ * real-mode call, and so we don't want to use it with LinuxBIOS.
|
63
|
84
|
*
|
64
|
|
- * NOTE : this function does not echo the character, and it does block
|
65
|
|
- *****************************************************************************
|
66
|
85
|
*/
|
67
|
|
-
|
68
|
86
|
int getchar ( void ) {
|
69
|
87
|
struct console_driver *console;
|
70
|
88
|
int character = 256;
|
|
@@ -92,11 +110,20 @@ int getchar ( void ) {
|
92
|
110
|
return character;
|
93
|
111
|
}
|
94
|
112
|
|
95
|
|
-/*****************************************************************************
|
96
|
|
- * iskey : check to see if any input is available on any console
|
97
|
|
- *****************************************************************************
|
|
113
|
+/** Check for available input on any console.
|
|
114
|
+ *
|
|
115
|
+ * @v None
|
|
116
|
+ * @ret True Input is available on a console
|
|
117
|
+ * @ret False Input is not available on any console
|
|
118
|
+ * @err None
|
|
119
|
+ *
|
|
120
|
+ * All enabled console devices are checked once for available input
|
|
121
|
+ * using each device's console_driver::iskey() method. If any console
|
|
122
|
+ * device has input available, this call will return True. If this
|
|
123
|
+ * call returns True, you can then safely call getchar() without
|
|
124
|
+ * blocking.
|
|
125
|
+ *
|
98
|
126
|
*/
|
99
|
|
-
|
100
|
127
|
int iskey ( void ) {
|
101
|
128
|
return has_input() ? 1 : 0;
|
102
|
129
|
}
|