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
18         if (get_option("debug_level", &console_loglevel))
19                 console_loglevel = DEFAULT_CONSOLE_LOGLEVEL;
20
21         for(driver = console_drivers; driver < econsole_drivers; driver++) {
22                 if (!driver->init)
23                         continue;
24                 driver->init();
25         }
26         initialized = 1;
27 }
28
29 static void __console_tx_byte(unsigned char byte)
30 {
31         struct console_driver *driver;
32         for(driver = console_drivers; driver < econsole_drivers; driver++) {
33                 driver->tx_byte(byte);
34         }
35 }
36
37 void console_tx_flush(void)
38 {
39         struct console_driver *driver;
40         for(driver = console_drivers; driver < econsole_drivers; driver++) {
41                 if (!driver->tx_flush) 
42                         continue;
43                 driver->tx_flush();
44         }
45 }
46
47 void console_tx_byte(unsigned char byte)
48 {
49         if (!initialized)
50                 return;
51         if (byte == '\n')
52                 __console_tx_byte('\r');
53         __console_tx_byte(byte);
54 }
55
56 unsigned char console_rx_byte(void)
57 {
58         struct console_driver *driver;
59         if (!initialized)
60                 return 0;
61         for(driver = console_drivers; driver < econsole_drivers; driver++) {
62                 if (driver->tst_byte)
63                         break;
64         }
65         if (driver == econsole_drivers)
66                 return 0;
67         while (!driver->tst_byte());
68         return driver->rx_byte();
69 }
70
71 int console_tst_byte(void)
72 {
73         struct console_driver *driver;
74         if (!initialized)
75                 return 0;
76         for(driver = console_drivers; driver < econsole_drivers; driver++)
77                 if (driver->tst_byte)
78                         return driver->tst_byte();
79         return 0;
80 }
81
82 /*
83  *    Write POST information
84  */
85 void post_code(uint8_t value)
86 {
87 #if !defined(NO_POST) || NO_POST==0
88 #if CONFIG_SERIAL_POST==1
89         printk_emerg("POST: 0x%02x\n", value);
90 #endif
91         outb(value, 0x80);
92 #endif
93 }
94
95 /* Report a fatal error */
96 void die(const char *msg)
97 {
98         printk_emerg("%s", msg);
99         post_code(0xff);
100         while (1);              /* Halt */
101 }