added rx support
[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         if (driver == econsole_drivers)
64                 return 0;
65         while (!driver->tst_byte());
66         return driver->rx_byte();
67 }
68
69 int console_tst_byte(void)
70 {
71         struct console_driver *driver;
72         if (!initialized)
73                 return 0;
74         for(driver = console_drivers; driver < econsole_drivers; driver++)
75                 if (driver->tst_byte)
76                         return driver->tst_byte();
77         return 0;
78 }
79
80 /*
81  *    Write POST information
82  */
83 void post_code(uint8_t value)
84 {
85 #if CONFIG_SERIAL_POST==1
86         printk_info("POST: 0x%02x\n", value);
87 #elsif !define(NO_POST)
88         outb(value, 0x80);
89 #endif
90 }
91
92 /* Report a fatal error */
93 void die(char *msg)
94 {
95         printk_emerg("%s", msg);
96         post_code(0xff);
97         while (1);              /* Halt */
98 }