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