iPXE
console.h
Go to the documentation of this file.
1 #ifndef _IPXE_CONSOLE_H
2 #define _IPXE_CONSOLE_H
3 
4 #include <stddef.h>
5 #include <stdio.h>
6 #include <ipxe/tables.h>
7 
8 /** @file
9  *
10  * User interaction.
11  *
12  * Various console devices can be selected via the build options
13  * CONSOLE_FIRMWARE, CONSOLE_SERIAL etc. The console functions
14  * putchar(), getchar() and iskey() delegate to the individual console
15  * drivers.
16  *
17  */
18 
19 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
20 FILE_SECBOOT ( PERMITTED );
21 
22 struct pixel_buffer;
23 
24 /** A console configuration */
26  /** Width */
27  unsigned int width;
28  /** Height */
29  unsigned int height;
30  /** Colour depth */
31  unsigned int depth;
32  /** Left margin */
33  unsigned int left;
34  /** Right margin */
35  unsigned int right;
36  /** Top margin */
37  unsigned int top;
38  /** Bottom margin */
39  unsigned int bottom;
40  /** Background picture, if any */
42 };
43 
44 /**
45  * A console driver
46  *
47  * Defines the functions that implement a particular console type.
48  * Must be made part of the console drivers table by using
49  * #__console_driver.
50  *
51  * @note Consoles that cannot be used before their initialisation
52  * function has completed should set #disabled initially. This allows
53  * other console devices to still be used to print out early debugging
54  * messages.
55  */
57  /**
58  * Console disabled flags
59  *
60  * This is the bitwise OR of zero or more console disabled
61  * flags.
62  */
63  int disabled;
64  /**
65  * Write a character to the console
66  *
67  * @v character Character to be written
68  */
69  void ( * putchar ) ( int character );
70  /**
71  * Read a character from the console
72  *
73  * @ret character Character read
74  *
75  * If no character is available to be read, this method will
76  * block. The character read should not be echoed back to the
77  * console.
78  */
79  int ( * getchar ) ( void );
80  /**
81  * Check for available input
82  *
83  * @ret is_available Input is available
84  *
85  * This should return true if a subsequent call to getchar()
86  * will not block.
87  */
88  int ( * iskey ) ( void );
89  /**
90  * Configure console
91  *
92  * @v config Console configuration, or NULL to reset
93  * @ret rc Return status code
94  */
95  int ( * configure ) ( struct console_configuration *config );
96  /**
97  * Console usage bitmask
98  *
99  * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
100  * values.
101  */
102  int usage;
103 };
104 
105 /** Console is disabled for input */
106 #define CONSOLE_DISABLED_INPUT 0x0001
107 
108 /** Console is disabled for output */
109 #define CONSOLE_DISABLED_OUTPUT 0x0002
110 
111 /** Console is disabled for all uses */
112 #define CONSOLE_DISABLED ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
113 
114 /** Console driver table */
115 #define CONSOLES __table ( struct console_driver, "consoles" )
116 
117 /**
118  * Mark a <tt> struct console_driver </tt> as being part of the
119  * console drivers table.
120  *
121  * Use as e.g.
122  *
123  * @code
124  *
125  * struct console_driver my_console __console_driver = {
126  * .putchar = my_putchar,
127  * .getchar = my_getchar,
128  * .iskey = my_iskey,
129  * };
130  *
131  * @endcode
132  *
133  */
134 #define __console_driver __table_entry ( CONSOLES, 01 )
135 
136 /**
137  * @defgroup consoleusage Console usages
138  * @{
139  */
140 
141 /** Standard output */
142 #define CONSOLE_USAGE_STDOUT 0x0001
143 
144 /** Debug messages */
145 #define CONSOLE_USAGE_DEBUG 0x0002
146 
147 /** Text-based user interface */
148 #define CONSOLE_USAGE_TUI 0x0004
149 
150 /** Log messages */
151 #define CONSOLE_USAGE_LOG 0x0008
152 
153 /** All console usages */
154 #define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG | \
155  CONSOLE_USAGE_TUI | CONSOLE_USAGE_LOG )
156 
157 /** @} */
158 
159 /**
160  * Test to see if console has an explicit usage
161  *
162  * @v console Console definition (e.g. CONSOLE_PCBIOS)
163  * @ret explicit Console has an explicit usage
164  *
165  * This relies upon the trick that the expression ( 2 * N + 1 ) will
166  * be valid even if N is defined to be empty, since it will then
167  * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
168  */
169 #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
170 
171 /** Default console width */
172 #define CONSOLE_DEFAULT_WIDTH 80
173 
174 /** Default console height */
175 #define CONSOLE_DEFAULT_HEIGHT 25
176 
177 extern int console_usage;
178 extern unsigned int console_width;
179 extern unsigned int console_height;
180 
181 /**
182  * Set console usage
183  *
184  * @v usage New console usage
185  * @ret old_usage Previous console usage
186  */
187 static inline __attribute__ (( always_inline )) int
188 console_set_usage ( int usage ) {
189  int old_usage = console_usage;
190 
191  console_usage = usage;
192  return old_usage;
193 }
194 
195 /**
196  * Set console size
197  *
198  * @v width Width, in characters
199  * @v height Height, in characters
200  */
201 static inline __attribute__ (( always_inline )) void
202 console_set_size ( unsigned int width, unsigned int height ) {
205 }
206 
207 extern int iskey ( void );
208 extern int getkey ( unsigned long timeout );
209 extern int console_configure ( struct console_configuration *config );
210 
211 /**
212  * Reset console
213  *
214  */
215 static inline __attribute__ (( always_inline )) void console_reset ( void ) {
216 
218 }
219 
220 #endif /* _IPXE_CONSOLE_H */
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition: console.h:202
#define __attribute__(x)
Definition: compiler.h:10
unsigned int height
Height.
Definition: console.h:29
unsigned int width
Width.
Definition: console.h:27
unsigned int depth
Colour depth.
Definition: console.h:31
int(* configure)(struct console_configuration *config)
Configure console.
Definition: console.h:95
A console configuration.
Definition: console.h:25
unsigned int console_width
Console width.
Definition: console.c:15
int usage
Console usage bitmask.
Definition: console.h:102
unsigned int console_height
Console height.
Definition: console.c:18
unsigned int bottom
Bottom margin.
Definition: console.h:39
void(* putchar)(int character)
Write a character to the console.
Definition: console.h:69
A pixel buffer.
Definition: pixbuf.h:17
int(* iskey)(void)
Check for available input.
Definition: console.h:88
static void console_reset(void)
Reset console.
Definition: console.h:215
int getkey(unsigned long timeout)
Get single keypress.
Definition: getkey.c:72
unsigned int right
Right margin.
Definition: console.h:35
int console_configure(struct console_configuration *config)
Configure console.
Definition: console.c:147
int console_usage
Current console usage.
Definition: console.c:12
int disabled
Console disabled flags.
Definition: console.h:63
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:41
int iskey(void)
Check for available input on any console.
Definition: console.c:131
unsigned int top
Top margin.
Definition: console.h:37
static int console_set_usage(int usage)
Set console usage.
Definition: console.h:188
Linker tables.
void timeout(int)
A console driver.
Definition: console.h:56
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int(* getchar)(void)
Read a character from the console.
Definition: console.h:79
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
FILE_SECBOOT(PERMITTED)
unsigned int left
Left margin.
Definition: console.h:33