1 #ifndef CONSOLE_CONSOLE_H_
2 #define CONSOLE_CONSOLE_H_
5 #include <console/loglevel.h>
8 void console_init(void);
9 void console_tx_byte(unsigned char byte);
10 void console_tx_flush(void);
11 unsigned char console_rx_byte(void);
12 int console_tst_byte(void);
13 void post_code(uint8_t value);
14 void __attribute__ ((noreturn)) die(const char *msg);
15 #if CONFIG_CONSOLE_VGA == 1
16 void vga_console_init(void);
19 struct console_driver {
21 void (*tx_byte)(unsigned char byte);
22 void (*tx_flush)(void);
23 unsigned char (*rx_byte)(void);
24 int (*tst_byte)(void);
27 #define __console __attribute__((used, __section__ (".rodata.console_drivers")))
29 /* Defined by the linker... */
30 extern struct console_driver console_drivers[];
31 extern struct console_driver econsole_drivers[];
33 extern int console_loglevel;
34 #endif /* !__PRE_RAM__ */
37 int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
39 #undef WE_CLEANED_UP_ALL_SIDE_EFFECTS
40 /* We saw some strange effects in the past like coreboot crashing while
41 * disabling cache as ram for a maximum console log level of 6 and above while
42 * it worked fine without. In order to catch such issues reliably we are
43 * always doing a function call to do_printk with the full number of arguments.
44 * Our favorite reason to do it this way was:
46 * printk(BIOS_DEBUG, "CAR disabled\n"); // oops, garbage stack pointer
48 * This slightly increases the code size and some unprinted strings will end
49 * up in the final coreboot binary (most of them compressed). If you want to
51 * #define WE_CLEANED_UP_ALL_SIDE_EFFECTS
53 #ifdef WE_CLEANED_UP_ALL_SIDE_EFFECTS
55 #define printk(LEVEL, fmt, args...) \
57 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
58 do_printk(LEVEL, fmt, ##args); \
64 #define printk(LEVEL, fmt, args...) \
66 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
67 do_printk(LEVEL, fmt, ##args); \
69 do_printk(BIOS_NEVER, fmt, ##args); \
74 #define print_emerg(STR) printk(BIOS_EMERG, "%s", (STR))
75 #define print_alert(STR) printk(BIOS_ALERT, "%s", (STR))
76 #define print_crit(STR) printk(BIOS_CRIT, "%s", (STR))
77 #define print_err(STR) printk(BIOS_ERR, "%s", (STR))
78 #define print_warning(STR) printk(BIOS_WARNING,"%s", (STR))
79 #define print_notice(STR) printk(BIOS_NOTICE, "%s", (STR))
80 #define print_info(STR) printk(BIOS_INFO, "%s", (STR))
81 #define print_debug(STR) printk(BIOS_DEBUG, "%s", (STR))
82 #define print_spew(STR) printk(BIOS_SPEW, "%s", (STR))
84 #define print_emerg_char(CH) printk(BIOS_EMERG, "%c", (CH))
85 #define print_alert_char(CH) printk(BIOS_ALERT, "%c", (CH))
86 #define print_crit_char(CH) printk(BIOS_CRIT, "%c", (CH))
87 #define print_err_char(CH) printk(BIOS_ERR, "%c", (CH))
88 #define print_warning_char(CH) printk(BIOS_WARNING,"%c", (CH))
89 #define print_notice_char(CH) printk(BIOS_NOTICE, "%c", (CH))
90 #define print_info_char(CH) printk(BIOS_INFO, "%c", (CH))
91 #define print_debug_char(CH) printk(BIOS_DEBUG, "%c", (CH))
92 #define print_spew_char(CH) printk(BIOS_SPEW, "%c", (CH))
94 #define print_emerg_hex8(HEX) printk(BIOS_EMERG, "%02x", (HEX))
95 #define print_alert_hex8(HEX) printk(BIOS_ALERT, "%02x", (HEX))
96 #define print_crit_hex8(HEX) printk(BIOS_CRIT, "%02x", (HEX))
97 #define print_err_hex8(HEX) printk(BIOS_ERR, "%02x", (HEX))
98 #define print_warning_hex8(HEX) printk(BIOS_WARNING,"%02x", (HEX))
99 #define print_notice_hex8(HEX) printk(BIOS_NOTICE, "%02x", (HEX))
100 #define print_info_hex8(HEX) printk(BIOS_INFO, "%02x", (HEX))
101 #define print_debug_hex8(HEX) printk(BIOS_DEBUG, "%02x", (HEX))
102 #define print_spew_hex8(HEX) printk(BIOS_SPEW, "%02x", (HEX))
104 #define print_emerg_hex16(HEX) printk(BIOS_EMERG, "%04x", (HEX))
105 #define print_alert_hex16(HEX) printk(BIOS_ALERT, "%04x", (HEX))
106 #define print_crit_hex16(HEX) printk(BIOS_CRIT, "%04x", (HEX))
107 #define print_err_hex16(HEX) printk(BIOS_ERR, "%04x", (HEX))
108 #define print_warning_hex16(HEX) printk(BIOS_WARNING,"%04x", (HEX))
109 #define print_notice_hex16(HEX) printk(BIOS_NOTICE, "%04x", (HEX))
110 #define print_info_hex16(HEX) printk(BIOS_INFO, "%04x", (HEX))
111 #define print_debug_hex16(HEX) printk(BIOS_DEBUG, "%04x", (HEX))
112 #define print_spew_hex16(HEX) printk(BIOS_SPEW, "%04x", (HEX))
114 #define print_emerg_hex32(HEX) printk(BIOS_EMERG, "%08x", (HEX))
115 #define print_alert_hex32(HEX) printk(BIOS_ALERT, "%08x", (HEX))
116 #define print_crit_hex32(HEX) printk(BIOS_CRIT, "%08x", (HEX))
117 #define print_err_hex32(HEX) printk(BIOS_ERR, "%08x", (HEX))
118 #define print_warning_hex32(HEX) printk(BIOS_WARNING,"%08x", (HEX))
119 #define print_notice_hex32(HEX) printk(BIOS_NOTICE, "%08x", (HEX))
120 #define print_info_hex32(HEX) printk(BIOS_INFO, "%08x", (HEX))
121 #define print_debug_hex32(HEX) printk(BIOS_DEBUG, "%08x", (HEX))
122 #define print_spew_hex32(HEX) printk(BIOS_SPEW, "%08x", (HEX))
125 static void __console_tx_byte(unsigned char byte)
130 static void __console_tx_nibble(unsigned nibble)
133 digit = nibble + '0';
137 __console_tx_byte(digit);
140 static void __console_tx_char(int loglevel, unsigned char byte)
142 if (ASM_CONSOLE_LOGLEVEL >= loglevel) {
147 static void __console_tx_hex8(int loglevel, unsigned char value)
149 if (ASM_CONSOLE_LOGLEVEL >= loglevel) {
150 __console_tx_nibble((value >> 4U) & 0x0fU);
151 __console_tx_nibble(value & 0x0fU);
155 static void __console_tx_hex16(int loglevel, unsigned short value)
157 if (ASM_CONSOLE_LOGLEVEL >= loglevel) {
158 __console_tx_nibble((value >> 12U) & 0x0fU);
159 __console_tx_nibble((value >> 8U) & 0x0fU);
160 __console_tx_nibble((value >> 4U) & 0x0fU);
161 __console_tx_nibble(value & 0x0fU);
165 static void __console_tx_hex32(int loglevel, unsigned int value)
167 if (ASM_CONSOLE_LOGLEVEL >= loglevel) {
168 __console_tx_nibble((value >> 28U) & 0x0fU);
169 __console_tx_nibble((value >> 24U) & 0x0fU);
170 __console_tx_nibble((value >> 20U) & 0x0fU);
171 __console_tx_nibble((value >> 16U) & 0x0fU);
172 __console_tx_nibble((value >> 12U) & 0x0fU);
173 __console_tx_nibble((value >> 8U) & 0x0fU);
174 __console_tx_nibble((value >> 4U) & 0x0fU);
175 __console_tx_nibble(value & 0x0fU);
179 static void __console_tx_string(int loglevel, const char *str)
181 if (ASM_CONSOLE_LOGLEVEL >= loglevel) {
183 while((ch = *str++) != '\0') {
185 __console_tx_byte('\r');
186 __console_tx_byte(ch);
191 #define FUNCTIONS_FOR_PRINT
192 #ifdef FUNCTIONS_FOR_PRINT
193 static void print_emerg_char(unsigned char byte) { __console_tx_char(BIOS_EMERG, byte); }
194 static void print_emerg_hex8(unsigned char value){ __console_tx_hex8(BIOS_EMERG, value); }
195 static void print_emerg_hex16(unsigned short value){ __console_tx_hex16(BIOS_EMERG, value); }
196 static void print_emerg_hex32(unsigned int value) { __console_tx_hex32(BIOS_EMERG, value); }
197 static void print_emerg(const char *str) { __console_tx_string(BIOS_EMERG, str); }
199 static void print_alert_char(unsigned char byte) { __console_tx_char(BIOS_ALERT, byte); }
200 static void print_alert_hex8(unsigned char value) { __console_tx_hex8(BIOS_ALERT, value); }
201 static void print_alert_hex16(unsigned short value){ __console_tx_hex16(BIOS_ALERT, value); }
202 static void print_alert_hex32(unsigned int value) { __console_tx_hex32(BIOS_ALERT, value); }
203 static void print_alert(const char *str) { __console_tx_string(BIOS_ALERT, str); }
205 static void print_crit_char(unsigned char byte) { __console_tx_char(BIOS_CRIT, byte); }
206 static void print_crit_hex8(unsigned char value) { __console_tx_hex8(BIOS_CRIT, value); }
207 static void print_crit_hex16(unsigned short value){ __console_tx_hex16(BIOS_CRIT, value); }
208 static void print_crit_hex32(unsigned int value) { __console_tx_hex32(BIOS_CRIT, value); }
209 static void print_crit(const char *str) { __console_tx_string(BIOS_CRIT, str); }
211 static void print_err_char(unsigned char byte) { __console_tx_char(BIOS_ERR, byte); }
212 static void print_err_hex8(unsigned char value) { __console_tx_hex8(BIOS_ERR, value); }
213 static void print_err_hex16(unsigned short value){ __console_tx_hex16(BIOS_ERR, value); }
214 static void print_err_hex32(unsigned int value) { __console_tx_hex32(BIOS_ERR, value); }
215 static void print_err(const char *str) { __console_tx_string(BIOS_ERR, str); }
217 static void print_warning_char(unsigned char byte) { __console_tx_char(BIOS_WARNING, byte); }
218 static void print_warning_hex8(unsigned char value) { __console_tx_hex8(BIOS_WARNING, value); }
219 static void print_warning_hex16(unsigned short value){ __console_tx_hex16(BIOS_WARNING, value); }
220 static void print_warning_hex32(unsigned int value) { __console_tx_hex32(BIOS_WARNING, value); }
221 static void print_warning(const char *str) { __console_tx_string(BIOS_WARNING, str); }
223 static void print_notice_char(unsigned char byte) { __console_tx_char(BIOS_NOTICE, byte); }
224 static void print_notice_hex8(unsigned char value) { __console_tx_hex8(BIOS_NOTICE, value); }
225 static void print_notice_hex16(unsigned short value){ __console_tx_hex16(BIOS_NOTICE, value); }
226 static void print_notice_hex32(unsigned int value) { __console_tx_hex32(BIOS_NOTICE, value); }
227 static void print_notice(const char *str) { __console_tx_string(BIOS_NOTICE, str); }
229 static void print_info_char(unsigned char byte) { __console_tx_char(BIOS_INFO, byte); }
230 static void print_info_hex8(unsigned char value) { __console_tx_hex8(BIOS_INFO, value); }
231 static void print_info_hex16(unsigned short value){ __console_tx_hex16(BIOS_INFO, value); }
232 static void print_info_hex32(unsigned int value) { __console_tx_hex32(BIOS_INFO, value); }
233 static void print_info(const char *str) { __console_tx_string(BIOS_INFO, str); }
235 static void print_debug_char(unsigned char byte) { __console_tx_char(BIOS_DEBUG, byte); }
236 static void print_debug_hex8(unsigned char value) { __console_tx_hex8(BIOS_DEBUG, value); }
237 static void print_debug_hex16(unsigned short value){ __console_tx_hex16(BIOS_DEBUG, value); }
238 static void print_debug_hex32(unsigned int value) { __console_tx_hex32(BIOS_DEBUG, value); }
239 static void print_debug(const char *str) { __console_tx_string(BIOS_DEBUG, str); }
241 static void print_spew_char(unsigned char byte) { __console_tx_char(BIOS_SPEW, byte); }
242 static void print_spew_hex8(unsigned char value) { __console_tx_hex8(BIOS_SPEW, value); }
243 static void print_spew_hex16(unsigned short value){ __console_tx_hex16(BIOS_SPEW, value); }
244 static void print_spew_hex32(unsigned int value) { __console_tx_hex32(BIOS_SPEW, value); }
245 static void print_spew(const char *str) { __console_tx_string(BIOS_SPEW, str); }
248 #define print_emerg(STR) __console_tx_string(BIOS_EMERG, STR)
249 #define print_alert(STR) __console_tx_string(BIOS_ALERT, STR)
250 #define print_crit(STR) __console_tx_string(BIOS_CRIT, STR)
251 #define print_err(STR) __console_tx_string(BIOS_ERR, STR)
252 #define print_warning(STR) __console_tx_string(BIOS_WARNING, STR)
253 #define print_notice(STR) __console_tx_string(BIOS_NOTICE, STR)
254 #define print_info(STR) __console_tx_string(BIOS_INFO, STR)
255 #define print_debug(STR) __console_tx_string(BIOS_DEBUG, STR)
256 #define print_spew(STR) __console_tx_string(BIOS_SPEW, STR)
258 #define print_emerg_char(CH) __console_tx_char(BIOS_EMERG, CH)
259 #define print_alert_char(CH) __console_tx_char(BIOS_ALERT, CH)
260 #define print_crit_char(CH) __console_tx_char(BIOS_CRIT, CH)
261 #define print_err_char(CH) __console_tx_char(BIOS_ERR, CH)
262 #define print_warning_char(CH) __console_tx_char(BIOS_WARNING, CH)
263 #define print_notice_char(CH) __console_tx_char(BIOS_NOTICE, CH)
264 #define print_info_char(CH) __console_tx_char(BIOS_INFO, CH)
265 #define print_debug_char(CH) __console_tx_char(BIOS_DEBUG, CH)
266 #define print_spew_char(CH) __console_tx_char(BIOS_SPEW, CH)
268 #define print_emerg_hex8(HEX) __console_tx_hex8(BIOS_EMERG, HEX)
269 #define print_alert_hex8(HEX) __console_tx_hex8(BIOS_ALERT, HEX)
270 #define print_crit_hex8(HEX) __console_tx_hex8(BIOS_CRIT, HEX)
271 #define print_err_hex8(HEX) __console_tx_hex8(BIOS_ERR, HEX)
272 #define print_warning_hex8(HEX) __console_tx_hex8(BIOS_WARNING, HEX)
273 #define print_notice_hex8(HEX) __console_tx_hex8(BIOS_NOTICE, HEX)
274 #define print_info_hex8(HEX) __console_tx_hex8(BIOS_INFO, HEX)
275 #define print_debug_hex8(HEX) __console_tx_hex8(BIOS_DEBUG, HEX)
276 #define print_spew_hex8(HEX) __console_tx_hex8(BIOS_SPEW, HEX)
278 #define print_emerg_hex16(HEX) __console_tx_hex16(BIOS_EMERG, HEX)
279 #define print_alert_hex16(HEX) __console_tx_hex16(BIOS_ALERT, HEX)
280 #define print_crit_hex16(HEX) __console_tx_hex16(BIOS_CRIT, HEX)
281 #define print_err_hex16(HEX) __console_tx_hex16(BIOS_ERR, HEX)
282 #define print_warning_hex16(HEX) __console_tx_hex16(BIOS_WARNING, HEX)
283 #define print_notice_hex16(HEX) __console_tx_hex16(BIOS_NOTICE, HEX)
284 #define print_info_hex16(HEX) __console_tx_hex16(BIOS_INFO, HEX)
285 #define print_debug_hex16(HEX) __console_tx_hex16(BIOS_DEBUG, HEX)
286 #define print_spew_hex16(HEX) __console_tx_hex16(BIOS_SPEW, HEX)
288 #define print_emerg_hex32(HEX) __console_tx_hex32(BIOS_EMERG, HEX)
289 #define print_alert_hex32(HEX) __console_tx_hex32(BIOS_ALERT, HEX)
290 #define print_crit_hex32(HEX) __console_tx_hex32(BIOS_CRIT, HEX)
291 #define print_err_hex32(HEX) __console_tx_hex32(BIOS_ERR, HEX)
292 #define print_warning_hex32(HEX) __console_tx_hex32(BIOS_WARNING, HEX)
293 #define print_notice_hex32(HEX) __console_tx_hex32(BIOS_NOTICE, HEX)
294 #define print_info_hex32(HEX) __console_tx_hex32(BIOS_INFO, HEX)
295 #define print_debug_hex32(HEX) __console_tx_hex32(BIOS_DEBUG, HEX)
296 #define print_spew_hex32(HEX) __console_tx_hex32(BIOS_SPEW, HEX)
301 #endif /* CONSOLE_CONSOLE_H_ */