Revert "CMOS: Add set_option and rework get_option."
[coreboot.git] / src / console / console.c
1 /*
2  * Bootstrap code for the INTEL 
3  */
4
5 #include <arch/io.h>
6 #include <console/console.h>
7 #include <string.h>
8 #include <pc80/mc146818rtc.h>
9
10
11 static int initialized;
12
13 /* initialize the console */
14 void console_init(void)
15 {
16         struct console_driver *driver;
17         if(get_option(&console_loglevel, "debug_level"))
18                 console_loglevel=DEFAULT_CONSOLE_LOGLEVEL;
19         
20         for(driver = console_drivers; driver < econsole_drivers; driver++) {
21                 if (!driver->init)
22                         continue;
23                 driver->init();
24         }
25         initialized = 1;
26 }
27
28 static void __console_tx_byte(unsigned char byte)
29 {
30         struct console_driver *driver;
31         for(driver = console_drivers; driver < econsole_drivers; driver++) {
32                 driver->tx_byte(byte);
33         }
34 }
35
36 void console_tx_flush(void)
37 {
38         struct console_driver *driver;
39         for(driver = console_drivers; driver < econsole_drivers; driver++) {
40                 if (!driver->tx_flush) 
41                         continue;
42                 driver->tx_flush();
43         }
44 }
45
46 void console_tx_byte(unsigned char byte)
47 {
48         if (!initialized)
49                 return;
50         if (byte == '\n')
51                 __console_tx_byte('\r');
52         __console_tx_byte(byte);
53 }
54
55 unsigned char console_rx_byte(void)
56 {
57         struct console_driver *driver;
58         if (!initialized)
59                 return 0;
60         for(driver = console_drivers; driver < econsole_drivers; driver++) {
61                 if (driver->tst_byte)
62                         break;
63         }
64         if (driver == econsole_drivers)
65                 return 0;
66         while (!driver->tst_byte());
67         return driver->rx_byte();
68 }
69
70 int console_tst_byte(void)
71 {
72         struct console_driver *driver;
73         if (!initialized)
74                 return 0;
75         for(driver = console_drivers; driver < econsole_drivers; driver++)
76                 if (driver->tst_byte)
77                         return driver->tst_byte();
78         return 0;
79 }
80
81 /*
82  *    Write POST information
83  */
84 void post_code(uint8_t value)
85 {
86 #if !defined(NO_POST) || NO_POST==0
87 #if CONFIG_SERIAL_POST==1
88         printk_emerg("POST: 0x%02x\n", value);
89 #endif
90         outb(value, 0x80);
91 #endif
92 }
93
94 /* Report a fatal error */
95 void die(const char *msg)
96 {
97         printk_emerg("%s", msg);
98         post_code(0xff);
99         while (1);              /* Halt */
100 }