remove some more warnings
[coreboot.git] / src / include / console / console.h
1 #ifndef CONSOLE_CONSOLE_H_
2 #define CONSOLE_CONSOLE_H_
3
4 #include <stdint.h>
5 #include <console/loglevel.h>
6
7 #ifndef __ROMCC__
8 void console_init(void);
9 void post_code(u8 value);
10 void __attribute__ ((noreturn)) die(const char *msg);
11 #endif
12
13 #ifndef __PRE_RAM__
14 void console_tx_byte(unsigned char byte);
15 void console_tx_flush(void);
16 unsigned char console_rx_byte(void);
17 int console_tst_byte(void);
18 #if CONFIG_CONSOLE_VGA == 1
19 void vga_console_init(void);
20 #endif
21
22 struct console_driver {
23         void (*init)(void);
24         void (*tx_byte)(unsigned char byte);
25         void (*tx_flush)(void);
26         unsigned char (*rx_byte)(void);
27         int (*tst_byte)(void);
28 };
29
30 #define __console       __attribute__((used, __section__ (".rodata.console_drivers")))
31
32 /* Defined by the linker... */
33 extern struct console_driver console_drivers[];
34 extern struct console_driver econsole_drivers[];
35
36 extern int console_loglevel;
37 #else
38 /* __PRE_RAM__ */
39 /* Using a global varible can cause problems when we reset the stack 
40  * from cache as ram to ram. If we make this a define USE_SHARED_STACK
41  * we could use the same code on all architectures.
42  */
43 #define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
44 #endif
45
46 #ifndef __ROMCC__
47 void console_init(void);
48 void post_code(u8 value);
49 void __attribute__ ((noreturn)) die(const char *msg);
50 int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
51
52 #undef WE_CLEANED_UP_ALL_SIDE_EFFECTS
53 /* We saw some strange effects in the past like coreboot crashing while
54  * disabling cache as ram for a maximum console log level of 6 and above while
55  * it worked fine without. In order to catch such issues reliably we are
56  * always doing a function call to do_printk with the full number of arguments.
57  * Our favorite reason to do it this way was:
58  *   disable_car();
59  *   printk(BIOS_DEBUG, "CAR disabled\n"); // oops, garbage stack pointer
60  *   move_stack();
61  * This slightly increases the code size and some unprinted strings will end
62  * up in the final coreboot binary (most of them compressed). If you want to
63  * avoid this, do a
64  * #define WE_CLEANED_UP_ALL_SIDE_EFFECTS
65  */
66 #ifdef WE_CLEANED_UP_ALL_SIDE_EFFECTS
67
68 #define printk(LEVEL, fmt, args...)                             \
69         do {                                                    \
70                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
71                         do_printk(LEVEL, fmt, ##args);          \
72                 }                                               \
73         } while(0)
74
75 #else
76
77 #define printk(LEVEL, fmt, args...)                             \
78         do {                                                    \
79                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
80                         do_printk(LEVEL, fmt, ##args);          \
81                 } else {                                        \
82                         do_printk(BIOS_NEVER, fmt, ##args);     \
83                 }                                               \
84         } while(0)
85 #endif
86
87 #define print_emerg(STR)         printk(BIOS_EMERG,  "%s", (STR))
88 #define print_alert(STR)         printk(BIOS_ALERT,  "%s", (STR))
89 #define print_crit(STR)          printk(BIOS_CRIT,   "%s", (STR))
90 #define print_err(STR)           printk(BIOS_ERR,    "%s", (STR))
91 #define print_warning(STR)       printk(BIOS_WARNING,"%s", (STR))
92 #define print_notice(STR)        printk(BIOS_NOTICE, "%s", (STR))
93 #define print_info(STR)          printk(BIOS_INFO,   "%s", (STR))
94 #define print_debug(STR)         printk(BIOS_DEBUG,  "%s", (STR))
95 #define print_spew(STR)          printk(BIOS_SPEW,   "%s", (STR))
96
97 #define print_emerg_char(CH)     printk(BIOS_EMERG,  "%c", (CH))
98 #define print_alert_char(CH)     printk(BIOS_ALERT,  "%c", (CH))
99 #define print_crit_char(CH)      printk(BIOS_CRIT,   "%c", (CH))
100 #define print_err_char(CH)       printk(BIOS_ERR,    "%c", (CH))
101 #define print_warning_char(CH)   printk(BIOS_WARNING,"%c", (CH))
102 #define print_notice_char(CH)    printk(BIOS_NOTICE, "%c", (CH))
103 #define print_info_char(CH)      printk(BIOS_INFO,   "%c", (CH))
104 #define print_debug_char(CH)     printk(BIOS_DEBUG,  "%c", (CH))
105 #define print_spew_char(CH)      printk(BIOS_SPEW,   "%c", (CH))
106
107 #define print_emerg_hex8(HEX)    printk(BIOS_EMERG,  "%02x",  (HEX))
108 #define print_alert_hex8(HEX)    printk(BIOS_ALERT,  "%02x",  (HEX))
109 #define print_crit_hex8(HEX)     printk(BIOS_CRIT,   "%02x",  (HEX))
110 #define print_err_hex8(HEX)      printk(BIOS_ERR,    "%02x",  (HEX))
111 #define print_warning_hex8(HEX)  printk(BIOS_WARNING,"%02x",  (HEX))
112 #define print_notice_hex8(HEX)   printk(BIOS_NOTICE, "%02x",  (HEX))
113 #define print_info_hex8(HEX)     printk(BIOS_INFO,   "%02x",  (HEX))
114 #define print_debug_hex8(HEX)    printk(BIOS_DEBUG,  "%02x",  (HEX))
115 #define print_spew_hex8(HEX)     printk(BIOS_SPEW,   "%02x",  (HEX))
116
117 #define print_emerg_hex16(HEX)   printk(BIOS_EMERG,  "%04x", (HEX))
118 #define print_alert_hex16(HEX)   printk(BIOS_ALERT,  "%04x", (HEX))
119 #define print_crit_hex16(HEX)    printk(BIOS_CRIT,   "%04x", (HEX))
120 #define print_err_hex16(HEX)     printk(BIOS_ERR,    "%04x", (HEX))
121 #define print_warning_hex16(HEX) printk(BIOS_WARNING,"%04x", (HEX))
122 #define print_notice_hex16(HEX)  printk(BIOS_NOTICE, "%04x", (HEX))
123 #define print_info_hex16(HEX)    printk(BIOS_INFO,   "%04x", (HEX))
124 #define print_debug_hex16(HEX)   printk(BIOS_DEBUG,  "%04x", (HEX))
125 #define print_spew_hex16(HEX)    printk(BIOS_SPEW,   "%04x", (HEX))
126
127 #define print_emerg_hex32(HEX)   printk(BIOS_EMERG,  "%08x", (HEX))
128 #define print_alert_hex32(HEX)   printk(BIOS_ALERT,  "%08x", (HEX))
129 #define print_crit_hex32(HEX)    printk(BIOS_CRIT,   "%08x", (HEX))
130 #define print_err_hex32(HEX)     printk(BIOS_ERR,    "%08x", (HEX))
131 #define print_warning_hex32(HEX) printk(BIOS_WARNING,"%08x", (HEX))
132 #define print_notice_hex32(HEX)  printk(BIOS_NOTICE, "%08x", (HEX))
133 #define print_info_hex32(HEX)    printk(BIOS_INFO,   "%08x", (HEX))
134 #define print_debug_hex32(HEX)   printk(BIOS_DEBUG,  "%08x", (HEX))
135 #define print_spew_hex32(HEX)    printk(BIOS_SPEW,   "%08x", (HEX))
136 #else
137
138
139 /* __ROMCC__ */
140 static void __console_tx_byte(unsigned char byte)
141 {
142         uart_tx_byte(byte);
143 }
144
145 static void __console_tx_nibble(unsigned nibble)
146 {
147         unsigned char digit;
148         digit = nibble + '0';
149         if (digit > '9') {
150                 digit += 39;
151         }
152         __console_tx_byte(digit);
153 }
154
155 static void __console_tx_char(int loglevel, unsigned char byte)
156 {
157         if (console_loglevel >= loglevel) {
158                 uart_tx_byte(byte);
159         }
160 }
161
162 static void __console_tx_hex8(int loglevel, unsigned char value)
163 {
164         if (console_loglevel >= loglevel) {
165                 __console_tx_nibble((value >>  4U) & 0x0fU);
166                 __console_tx_nibble(value & 0x0fU);
167         }
168 }
169
170 static void __console_tx_hex16(int loglevel, unsigned short value)
171 {
172         if (console_loglevel >= loglevel) {
173                 __console_tx_nibble((value >> 12U) & 0x0fU);
174                 __console_tx_nibble((value >>  8U) & 0x0fU);
175                 __console_tx_nibble((value >>  4U) & 0x0fU);
176                 __console_tx_nibble(value & 0x0fU);
177         }
178 }
179
180 static void __console_tx_hex32(int loglevel, unsigned int value)
181 {
182         if (console_loglevel >= loglevel) {
183                 __console_tx_nibble((value >> 28U) & 0x0fU);
184                 __console_tx_nibble((value >> 24U) & 0x0fU);
185                 __console_tx_nibble((value >> 20U) & 0x0fU);
186                 __console_tx_nibble((value >> 16U) & 0x0fU);
187                 __console_tx_nibble((value >> 12U) & 0x0fU);
188                 __console_tx_nibble((value >>  8U) & 0x0fU);
189                 __console_tx_nibble((value >>  4U) & 0x0fU);
190                 __console_tx_nibble(value & 0x0fU);
191         }
192 }
193
194 static void __console_tx_string(int loglevel, const char *str)
195 {
196         if (console_loglevel >= loglevel) {
197                 unsigned char ch;
198                 while((ch = *str++) != '\0') {
199                         if (ch == '\n')
200                                 __console_tx_byte('\r');
201                         __console_tx_byte(ch);
202                 }
203         }
204 }
205
206 #define FUNCTIONS_FOR_PRINT
207 #ifdef  FUNCTIONS_FOR_PRINT
208 static void print_emerg_char(unsigned char byte) { __console_tx_char(BIOS_EMERG, byte); }
209 static void print_emerg_hex8(unsigned char value){ __console_tx_hex8(BIOS_EMERG, value); }
210 static void print_emerg_hex16(unsigned short value){ __console_tx_hex16(BIOS_EMERG, value); }
211 static void print_emerg_hex32(unsigned int value) { __console_tx_hex32(BIOS_EMERG, value); }
212 static void print_emerg(const char *str) { __console_tx_string(BIOS_EMERG, str); }
213
214 static void print_alert_char(unsigned char byte) { __console_tx_char(BIOS_ALERT, byte); }
215 static void print_alert_hex8(unsigned char value) { __console_tx_hex8(BIOS_ALERT, value); }
216 static void print_alert_hex16(unsigned short value){ __console_tx_hex16(BIOS_ALERT, value); }
217 static void print_alert_hex32(unsigned int value) { __console_tx_hex32(BIOS_ALERT, value); }
218 static void print_alert(const char *str) { __console_tx_string(BIOS_ALERT, str); }
219
220 static void print_crit_char(unsigned char byte) { __console_tx_char(BIOS_CRIT, byte); }
221 static void print_crit_hex8(unsigned char value) { __console_tx_hex8(BIOS_CRIT, value); }
222 static void print_crit_hex16(unsigned short value){ __console_tx_hex16(BIOS_CRIT, value); }
223 static void print_crit_hex32(unsigned int value) { __console_tx_hex32(BIOS_CRIT, value); }
224 static void print_crit(const char *str) { __console_tx_string(BIOS_CRIT, str); }
225
226 static void print_err_char(unsigned char byte) { __console_tx_char(BIOS_ERR, byte); }
227 static void print_err_hex8(unsigned char value) { __console_tx_hex8(BIOS_ERR, value); }
228 static void print_err_hex16(unsigned short value){ __console_tx_hex16(BIOS_ERR, value); }
229 static void print_err_hex32(unsigned int value) { __console_tx_hex32(BIOS_ERR, value); }
230 static void print_err(const char *str) { __console_tx_string(BIOS_ERR, str); }
231
232 static void print_warning_char(unsigned char byte) { __console_tx_char(BIOS_WARNING, byte); }
233 static void print_warning_hex8(unsigned char value) { __console_tx_hex8(BIOS_WARNING, value); }
234 static void print_warning_hex16(unsigned short value){ __console_tx_hex16(BIOS_WARNING, value); }
235 static void print_warning_hex32(unsigned int value) { __console_tx_hex32(BIOS_WARNING, value); }
236 static void print_warning(const char *str) { __console_tx_string(BIOS_WARNING, str); }
237
238 static void print_notice_char(unsigned char byte) { __console_tx_char(BIOS_NOTICE, byte); }
239 static void print_notice_hex8(unsigned char value) { __console_tx_hex8(BIOS_NOTICE, value); }
240 static void print_notice_hex16(unsigned short value){ __console_tx_hex16(BIOS_NOTICE, value); }
241 static void print_notice_hex32(unsigned int value) { __console_tx_hex32(BIOS_NOTICE, value); }
242 static void print_notice(const char *str) { __console_tx_string(BIOS_NOTICE, str); }
243
244 static void print_info_char(unsigned char byte) { __console_tx_char(BIOS_INFO, byte); }
245 static void print_info_hex8(unsigned char value) { __console_tx_hex8(BIOS_INFO, value); }
246 static void print_info_hex16(unsigned short value){ __console_tx_hex16(BIOS_INFO, value); }
247 static void print_info_hex32(unsigned int value) { __console_tx_hex32(BIOS_INFO, value); }
248 static void print_info(const char *str) { __console_tx_string(BIOS_INFO, str); }
249
250 static void print_debug_char(unsigned char byte) { __console_tx_char(BIOS_DEBUG, byte); }
251 static void print_debug_hex8(unsigned char value) { __console_tx_hex8(BIOS_DEBUG, value); }
252 static void print_debug_hex16(unsigned short value){ __console_tx_hex16(BIOS_DEBUG, value); }
253 static void print_debug_hex32(unsigned int value) { __console_tx_hex32(BIOS_DEBUG, value); }
254 static void print_debug(const char *str) { __console_tx_string(BIOS_DEBUG, str); }
255
256 static void print_spew_char(unsigned char byte) { __console_tx_char(BIOS_SPEW, byte); }
257 static void print_spew_hex8(unsigned char value) { __console_tx_hex8(BIOS_SPEW, value); }
258 static void print_spew_hex16(unsigned short value){ __console_tx_hex16(BIOS_SPEW, value); }
259 static void print_spew_hex32(unsigned int value) { __console_tx_hex32(BIOS_SPEW, value); }
260 static void print_spew(const char *str) { __console_tx_string(BIOS_SPEW, str); }
261
262 #else
263 #define print_emerg(STR)         __console_tx_string(BIOS_EMERG, STR)
264 #define print_alert(STR)         __console_tx_string(BIOS_ALERT, STR)
265 #define print_crit(STR)          __console_tx_string(BIOS_CRIT, STR)
266 #define print_err(STR)           __console_tx_string(BIOS_ERR, STR)
267 #define print_warning(STR)       __console_tx_string(BIOS_WARNING, STR)
268 #define print_notice(STR)        __console_tx_string(BIOS_NOTICE, STR)
269 #define print_info(STR)          __console_tx_string(BIOS_INFO, STR)
270 #define print_debug(STR)         __console_tx_string(BIOS_DEBUG, STR)
271 #define print_spew(STR)          __console_tx_string(BIOS_SPEW, STR)
272
273 #define print_emerg_char(CH)     __console_tx_char(BIOS_EMERG, CH)
274 #define print_alert_char(CH)     __console_tx_char(BIOS_ALERT, CH)
275 #define print_crit_char(CH)      __console_tx_char(BIOS_CRIT, CH)
276 #define print_err_char(CH)       __console_tx_char(BIOS_ERR, CH)
277 #define print_warning_char(CH)   __console_tx_char(BIOS_WARNING, CH)
278 #define print_notice_char(CH)    __console_tx_char(BIOS_NOTICE, CH)
279 #define print_info_char(CH)      __console_tx_char(BIOS_INFO, CH)
280 #define print_debug_char(CH)     __console_tx_char(BIOS_DEBUG, CH)
281 #define print_spew_char(CH)      __console_tx_char(BIOS_SPEW, CH)
282
283 #define print_emerg_hex8(HEX)    __console_tx_hex8(BIOS_EMERG, HEX)
284 #define print_alert_hex8(HEX)    __console_tx_hex8(BIOS_ALERT, HEX)
285 #define print_crit_hex8(HEX)     __console_tx_hex8(BIOS_CRIT, HEX)
286 #define print_err_hex8(HEX)      __console_tx_hex8(BIOS_ERR, HEX)
287 #define print_warning_hex8(HEX)  __console_tx_hex8(BIOS_WARNING, HEX)
288 #define print_notice_hex8(HEX)   __console_tx_hex8(BIOS_NOTICE, HEX)
289 #define print_info_hex8(HEX)     __console_tx_hex8(BIOS_INFO, HEX)
290 #define print_debug_hex8(HEX)    __console_tx_hex8(BIOS_DEBUG, HEX)
291 #define print_spew_hex8(HEX)     __console_tx_hex8(BIOS_SPEW, HEX)
292
293 #define print_emerg_hex16(HEX)   __console_tx_hex16(BIOS_EMERG, HEX)
294 #define print_alert_hex16(HEX)   __console_tx_hex16(BIOS_ALERT, HEX)
295 #define print_crit_hex16(HEX)    __console_tx_hex16(BIOS_CRIT, HEX)
296 #define print_err_hex16(HEX)     __console_tx_hex16(BIOS_ERR, HEX)
297 #define print_warning_hex16(HEX) __console_tx_hex16(BIOS_WARNING, HEX)
298 #define print_notice_hex16(HEX)  __console_tx_hex16(BIOS_NOTICE, HEX)
299 #define print_info_hex16(HEX)    __console_tx_hex16(BIOS_INFO, HEX)
300 #define print_debug_hex16(HEX)   __console_tx_hex16(BIOS_DEBUG, HEX)
301 #define print_spew_hex16(HEX)    __console_tx_hex16(BIOS_SPEW, HEX)
302
303 #define print_emerg_hex32(HEX)   __console_tx_hex32(BIOS_EMERG, HEX)
304 #define print_alert_hex32(HEX)   __console_tx_hex32(BIOS_ALERT, HEX)
305 #define print_crit_hex32(HEX)    __console_tx_hex32(BIOS_CRIT, HEX)
306 #define print_err_hex32(HEX)     __console_tx_hex32(BIOS_ERR, HEX)
307 #define print_warning_hex32(HEX) __console_tx_hex32(BIOS_WARNING, HEX)
308 #define print_notice_hex32(HEX)  __console_tx_hex32(BIOS_NOTICE, HEX)
309 #define print_info_hex32(HEX)    __console_tx_hex32(BIOS_INFO, HEX)
310 #define print_debug_hex32(HEX)   __console_tx_hex32(BIOS_DEBUG, HEX)
311 #define print_spew_hex32(HEX)    __console_tx_hex32(BIOS_SPEW, HEX)
312 #endif
313
314 #endif
315
316 #endif /* CONSOLE_CONSOLE_H_ */