Drop console/console.c and pc80/serial.c from mainboards'
[coreboot.git] / src / console / console.c
1 /*
2  * Bootstrap code for the INTEL
3  */
4
5 #include <console/console.h>
6 #include <build.h>
7 #include <arch/hlt.h>
8 #include <arch/io.h>
9
10 #ifndef __PRE_RAM__
11 #include <string.h>
12 #include <pc80/mc146818rtc.h>
13
14
15 /* initialize the console */
16 void console_init(void)
17 {
18         struct console_driver *driver;
19         if(get_option(&console_loglevel, "debug_level"))
20                 console_loglevel=CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
21
22         for(driver = console_drivers; driver < econsole_drivers; driver++) {
23                 if (!driver->init)
24                         continue;
25                 driver->init();
26         }
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 (byte == '\n')
50                 __console_tx_byte('\r');
51         __console_tx_byte(byte);
52 }
53
54 unsigned char console_rx_byte(void)
55 {
56         struct console_driver *driver;
57         for(driver = console_drivers; driver < econsole_drivers; driver++) {
58                 if (driver->tst_byte)
59                         break;
60         }
61         if (driver == econsole_drivers)
62                 return 0;
63         while (!driver->tst_byte());
64         return driver->rx_byte();
65 }
66
67 int console_tst_byte(void)
68 {
69         struct console_driver *driver;
70         for(driver = console_drivers; driver < econsole_drivers; driver++)
71                 if (driver->tst_byte)
72                         return driver->tst_byte();
73         return 0;
74 }
75
76 /*
77  *    Write POST information
78  */
79 void post_code(u8 value)
80 {
81 #if !defined(CONFIG_NO_POST) || CONFIG_NO_POST==0
82 #if CONFIG_SERIAL_POST==1
83         printk(BIOS_EMERG, "POST: 0x%02x\n", value);
84 #endif
85         outb(value, 0x80);
86 #endif
87 }
88
89 /* Report a fatal error */
90 void __attribute__((noreturn)) die(const char *msg)
91 {
92         printk(BIOS_EMERG, "%s", msg);
93         //post_code(0xff);
94         for (;;)
95                 hlt();          /* Halt */
96 }
97
98 #else
99
100 void console_init(void)
101 {
102         static const char console_test[] =
103                 "\n\ncoreboot-"
104                 COREBOOT_VERSION
105                 COREBOOT_EXTRA_VERSION
106                 " "
107                 COREBOOT_BUILD
108                 " starting...\n";
109         print_info(console_test);
110 }
111
112 void post_code(u8 value)
113 {
114 #if !defined(CONFIG_NO_POST) || CONFIG_NO_POST==0
115 #if CONFIG_SERIAL_POST==1
116         print_emerg("POST: 0x");
117         print_emerg_hex8(value);
118         print_emerg("\n");
119 #endif
120         outb(value, 0x80);
121 #endif
122 }
123
124 void die(const char *str)
125 {
126         print_emerg(str);
127         do {
128                 hlt();
129         } while(1);
130 }
131 #endif