1201_ht_bus0_dev0_fidvid_core.diff
[coreboot.git] / src / arch / i386 / lib / console.c
1 #include <console/loglevel.h>
2
3 #if CONFIG_USE_INIT == 0
4 static void __console_tx_byte(unsigned char byte)
5 {
6         uart_tx_byte(byte);
7 }
8
9 static void __console_tx_nibble(unsigned nibble)
10 {
11         unsigned char digit;
12         digit = nibble + '0';
13         if (digit > '9') {
14                 digit += 39;
15         }
16         __console_tx_byte(digit);
17 }
18
19 static void __console_tx_char(int loglevel, unsigned char byte)
20 {
21         if (ASM_CONSOLE_LOGLEVEL > loglevel) {
22                 uart_tx_byte(byte);
23         }
24 }
25
26 static void __console_tx_hex8(int loglevel, unsigned char value)
27 {
28         if (ASM_CONSOLE_LOGLEVEL > loglevel) {
29                 __console_tx_nibble((value >>  4U) & 0x0fU);
30                 __console_tx_nibble(value & 0x0fU);
31         }
32 }
33
34 static void __console_tx_hex16(int loglevel, unsigned short value)
35 {
36         if (ASM_CONSOLE_LOGLEVEL > loglevel) {
37                 __console_tx_nibble((value >> 12U) & 0x0fU);
38                 __console_tx_nibble((value >>  8U) & 0x0fU);
39                 __console_tx_nibble((value >>  4U) & 0x0fU);
40                 __console_tx_nibble(value & 0x0fU);
41         }
42 }
43
44 static void __console_tx_hex32(int loglevel, unsigned int value)
45 {
46         if (ASM_CONSOLE_LOGLEVEL > loglevel) {
47                 __console_tx_nibble((value >> 28U) & 0x0fU);
48                 __console_tx_nibble((value >> 24U) & 0x0fU);
49                 __console_tx_nibble((value >> 20U) & 0x0fU);
50                 __console_tx_nibble((value >> 16U) & 0x0fU);
51                 __console_tx_nibble((value >> 12U) & 0x0fU);
52                 __console_tx_nibble((value >>  8U) & 0x0fU);
53                 __console_tx_nibble((value >>  4U) & 0x0fU);
54                 __console_tx_nibble(value & 0x0fU);
55         }
56 }
57
58 static void __console_tx_string(int loglevel, const char *str)
59 {
60         if (ASM_CONSOLE_LOGLEVEL > loglevel) {
61                 unsigned char ch;
62                 while((ch = *str++) != '\0') {
63                         __console_tx_byte(ch);
64                 }
65         }
66 }
67
68 #define NOINLINE __attribute__((noinline))
69 static void print_emerg_char(unsigned char byte) { __console_tx_char(BIOS_EMERG, byte); }
70 static void print_emerg_hex8(unsigned char value){ __console_tx_hex8(BIOS_EMERG, value); }
71 static void print_emerg_hex16(unsigned short value){ __console_tx_hex16(BIOS_EMERG, value); }
72 static void print_emerg_hex32(unsigned int value) { __console_tx_hex32(BIOS_EMERG, value); }
73 static void print_emerg(const char *str) { __console_tx_string(BIOS_EMERG, str); }
74
75 static void print_alert_char(unsigned char byte) { __console_tx_char(BIOS_ALERT, byte); }
76 static void print_alert_hex8(unsigned char value) { __console_tx_hex8(BIOS_ALERT, value); }
77 static void print_alert_hex16(unsigned short value){ __console_tx_hex16(BIOS_ALERT, value); }
78 static void print_alert_hex32(unsigned int value) { __console_tx_hex32(BIOS_ALERT, value); }
79 static void print_alert(const char *str) { __console_tx_string(BIOS_ALERT, str); }
80
81 static void print_crit_char(unsigned char byte) { __console_tx_char(BIOS_CRIT, byte); }
82 static void print_crit_hex8(unsigned char value) { __console_tx_hex8(BIOS_CRIT, value); }
83 static void print_crit_hex16(unsigned short value){ __console_tx_hex16(BIOS_CRIT, value); }
84 static void print_crit_hex32(unsigned int value) { __console_tx_hex32(BIOS_CRIT, value); }
85 static void print_crit(const char *str) { __console_tx_string(BIOS_CRIT, str); }
86
87 static void print_err_char(unsigned char byte) { __console_tx_char(BIOS_ERR, byte); }
88 static void print_err_hex8(unsigned char value) { __console_tx_hex8(BIOS_ERR, value); }
89 static void print_err_hex16(unsigned short value){ __console_tx_hex16(BIOS_ERR, value); }
90 static void print_err_hex32(unsigned int value) { __console_tx_hex32(BIOS_ERR, value); }
91 static void print_err(const char *str) { __console_tx_string(BIOS_ERR, str); }
92
93 static void print_warning_char(unsigned char byte) { __console_tx_char(BIOS_WARNING, byte); }
94 static void print_warning_hex8(unsigned char value) { __console_tx_hex8(BIOS_WARNING, value); }
95 static void print_warning_hex16(unsigned short value){ __console_tx_hex16(BIOS_WARNING, value); }
96 static void print_warning_hex32(unsigned int value) { __console_tx_hex32(BIOS_WARNING, value); }
97 static void print_warning(const char *str) { __console_tx_string(BIOS_WARNING, str); }
98
99 static void print_notice_char(unsigned char byte) { __console_tx_char(BIOS_NOTICE, byte); }
100 static void print_notice_hex8(unsigned char value) { __console_tx_hex8(BIOS_NOTICE, value); }
101 static void print_notice_hex16(unsigned short value){ __console_tx_hex16(BIOS_NOTICE, value); }
102 static void print_notice_hex32(unsigned int value) { __console_tx_hex32(BIOS_NOTICE, value); }
103 static void print_notice(const char *str) { __console_tx_string(BIOS_NOTICE, str); }
104
105 static void print_info_char(unsigned char byte) { __console_tx_char(BIOS_INFO, byte); }
106 static void print_info_hex8(unsigned char value) { __console_tx_hex8(BIOS_INFO, value); }
107 static void print_info_hex16(unsigned short value){ __console_tx_hex16(BIOS_INFO, value); }
108 static void print_info_hex32(unsigned int value) { __console_tx_hex32(BIOS_INFO, value); }
109 static void print_info(const char *str) { __console_tx_string(BIOS_INFO, str); }
110
111 static void print_debug_char(unsigned char byte) { __console_tx_char(BIOS_DEBUG, byte); }
112 static void print_debug_hex8(unsigned char value) { __console_tx_hex8(BIOS_DEBUG, value); }
113 static void print_debug_hex16(unsigned short value){ __console_tx_hex16(BIOS_DEBUG, value); }
114 static void print_debug_hex32(unsigned int value) { __console_tx_hex32(BIOS_DEBUG, value); }
115 static void print_debug(const char *str) { __console_tx_string(BIOS_DEBUG, str); }
116
117 static void print_spew_char(unsigned char byte) { __console_tx_char(BIOS_SPEW, byte); }
118 static void print_spew_hex8(unsigned char value) { __console_tx_hex8(BIOS_SPEW, value); }
119 static void print_spew_hex16(unsigned short value){ __console_tx_hex16(BIOS_SPEW, value); }
120 static void print_spew_hex32(unsigned int value) { __console_tx_hex32(BIOS_SPEW, value); }
121 static void print_spew(const char *str) { __console_tx_string(BIOS_SPEW, str); }
122
123 #else  
124 /* CONFIG_USE_INIT == 1 */
125
126 extern int do_printk(int msg_level, const char *fmt, ...);
127
128 #define printk_emerg(fmt, arg...)   do_printk(BIOS_EMERG   ,fmt, ##arg)
129 #define printk_alert(fmt, arg...)   do_printk(BIOS_ALERT   ,fmt, ##arg)
130 #define printk_crit(fmt, arg...)    do_printk(BIOS_CRIT    ,fmt, ##arg)
131 #define printk_err(fmt, arg...)     do_printk(BIOS_ERR     ,fmt, ##arg)
132 #define printk_warning(fmt, arg...) do_printk(BIOS_WARNING ,fmt, ##arg)
133 #define printk_notice(fmt, arg...)  do_printk(BIOS_NOTICE  ,fmt, ##arg)
134 #define printk_info(fmt, arg...)    do_printk(BIOS_INFO    ,fmt, ##arg)
135 #define printk_debug(fmt, arg...)   do_printk(BIOS_DEBUG   ,fmt, ##arg)
136 #define printk_spew(fmt, arg...)    do_printk(BIOS_SPEW    ,fmt, ##arg)
137
138 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_EMERG
139 #undef  printk_emerg
140 #define printk_emerg(fmt, arg...)   do {} while(0)
141 #endif
142 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_ALERT
143 #undef  printk_alert
144 #define printk_alert(fmt, arg...)   do {} while(0)
145 #endif
146 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_CRIT
147 #undef  printk_crit
148 #define printk_crit(fmt, arg...)    do {} while(0)
149 #endif
150 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_ERR
151 #undef  printk_err
152 #define printk_err(fmt, arg...)     do {} while(0)
153 #endif
154 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_WARNING
155 #undef  printk_warning
156 #define printk_warning(fmt, arg...) do {} while(0)
157 #endif
158 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_NOTICE
159 #undef  printk_notice
160 #define printk_notice(fmt, arg...)  do {} while(0)
161 #endif
162 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_INFO
163 #undef  printk_info
164 #define printk_info(fmt, arg...)    do {} while(0)
165 #endif
166 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_DEBUG
167 #undef  printk_debug
168 #define printk_debug(fmt, arg...)   do {} while(0)
169 #endif
170 #if MAXIMUM_CONSOLE_LOGLEVEL <= BIOS_SPEW
171 #undef  printk_spew
172 #define printk_spew(fmt, arg...)    do {} while(0)
173 #endif
174
175 #define print_emerg(STR)   printk_emerg  ("%s", (STR))
176 #define print_alert(STR)   printk_alert  ("%s", (STR))
177 #define print_crit(STR)    printk_crit   ("%s", (STR))
178 #define print_err(STR)     printk_err    ("%s", (STR))
179 #define print_warning(STR) printk_warning("%s", (STR))
180 #define print_notice(STR)  printk_notice ("%s", (STR))
181 #define print_info(STR)    printk_info   ("%s", (STR))
182 #define print_debug(STR)   printk_debug  ("%s", (STR))
183 #define print_spew(STR)    printk_spew   ("%s", (STR))
184
185 #define print_emerg_char(CH)   printk_emerg  ("%c", (CH))
186 #define print_alert_char(CH)   printk_alert  ("%c", (CH))
187 #define print_crit_char(CH)    printk_crit   ("%c", (CH))
188 #define print_err_char(CH)     printk_err    ("%c", (CH))
189 #define print_warning_char(CH) printk_warning("%c", (CH))
190 #define print_notice_char(CH)  printk_notice ("%c", (CH))
191 #define print_info_char(CH)    printk_info   ("%c", (CH))
192 #define print_debug_char(CH)   printk_debug  ("%c", (CH))
193 #define print_spew_char(CH)    printk_spew   ("%c", (CH))
194
195 #define print_emerg_hex8(HEX)   printk_emerg  ("%02x",  (HEX))
196 #define print_alert_hex8(HEX)   printk_alert  ("%02x",  (HEX))
197 #define print_crit_hex8(HEX)    printk_crit   ("%02x",  (HEX))
198 #define print_err_hex8(HEX)     printk_err    ("%02x",  (HEX))
199 #define print_warning_hex8(HEX) printk_warning("%02x",  (HEX))
200 #define print_notice_hex8(HEX)  printk_notice ("%02x",  (HEX))
201 #define print_info_hex8(HEX)    printk_info   ("%02x",  (HEX))
202 #define print_debug_hex8(HEX)   printk_debug  ("%02x",  (HEX))
203 #define print_spew_hex8(HEX)    printk_spew   ("%02x",  (HEX))
204
205 #define print_emerg_hex16(HEX)   printk_emerg  ("%04x", (HEX))
206 #define print_alert_hex16(HEX)   printk_alert  ("%04x", (HEX))
207 #define print_crit_hex16(HEX)    printk_crit   ("%04x", (HEX))
208 #define print_err_hex16(HEX)     printk_err    ("%04x", (HEX))
209 #define print_warning_hex16(HEX) printk_warning("%04x", (HEX))
210 #define print_notice_hex16(HEX)  printk_notice ("%04x", (HEX))
211 #define print_info_hex16(HEX)    printk_info   ("%04x", (HEX))
212 #define print_debug_hex16(HEX)   printk_debug  ("%04x", (HEX))
213 #define print_spew_hex16(HEX)    printk_spew   ("%04x", (HEX))
214
215 #define print_emerg_hex32(HEX)   printk_emerg  ("%08x", (HEX))
216 #define print_alert_hex32(HEX)   printk_alert  ("%08x", (HEX))
217 #define print_crit_hex32(HEX)    printk_crit   ("%08x", (HEX))
218 #define print_err_hex32(HEX)     printk_err    ("%08x", (HEX))
219 #define print_warning_hex32(HEX) printk_warning("%08x", (HEX))
220 #define print_notice_hex32(HEX)  printk_notice ("%08x", (HEX))
221 #define print_info_hex32(HEX)    printk_info   ("%08x", (HEX))
222 #define print_debug_hex32(HEX)   printk_debug  ("%08x", (HEX))
223 #define print_spew_hex32(HEX)    printk_spew   ("%08x", (HEX))
224
225
226 #endif /* CONFIG_USE_INIT */
227
228 #ifndef LINUXBIOS_EXTRA_VERSION
229 #define LINUXBIOS_EXTRA_VERSION ""
230 #endif
231
232
233 static void console_init(void)
234 {
235         static const char console_test[] = 
236                 "\r\n\r\nLinuxBIOS-"
237                 LINUXBIOS_VERSION
238                 LINUXBIOS_EXTRA_VERSION
239                 " "
240                 LINUXBIOS_BUILD
241                 " starting...\r\n";
242         print_info(console_test);
243 }
244
245
246 static void die(const char *str)
247 {
248         print_emerg(str);
249         do {
250                 hlt();
251         } while(1);
252 }