Add support for the console over Ethernet (through PCI NE2000).
[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 #if CONFIG_CONSOLE_NE2K
11 #include <console/ne2k.h>
12 #endif
13
14 #ifndef __PRE_RAM__
15 #include <string.h>
16 #include <pc80/mc146818rtc.h>
17
18 /* initialize the console */
19 void console_init(void)
20 {
21         struct console_driver *driver;
22         if(get_option(&console_loglevel, "debug_level"))
23                 console_loglevel=CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
24
25         for(driver = console_drivers; driver < econsole_drivers; driver++) {
26                 if (!driver->init)
27                         continue;
28                 driver->init();
29         }
30 }
31
32 static void __console_tx_byte(unsigned char byte)
33 {
34         struct console_driver *driver;
35         for(driver = console_drivers; driver < econsole_drivers; driver++) {
36                 driver->tx_byte(byte);
37         }
38 }
39
40 void console_tx_flush(void)
41 {
42         struct console_driver *driver;
43         for(driver = console_drivers; driver < econsole_drivers; driver++) {
44                 if (!driver->tx_flush)
45                         continue;
46                 driver->tx_flush();
47         }
48 }
49
50 void console_tx_byte(unsigned char byte)
51 {
52         if (byte == '\n')
53                 __console_tx_byte('\r');
54         __console_tx_byte(byte);
55 }
56
57 unsigned char console_rx_byte(void)
58 {
59         struct console_driver *driver;
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         for(driver = console_drivers; driver < econsole_drivers; driver++)
74                 if (driver->tst_byte)
75                         return driver->tst_byte();
76         return 0;
77 }
78
79 /*
80  *    Write POST information
81  */
82 void post_code(u8 value)
83 {
84 #if !defined(CONFIG_NO_POST) || CONFIG_NO_POST==0
85 #if CONFIG_SERIAL_POST==1
86         printk(BIOS_EMERG, "POST: 0x%02x\n", value);
87 #endif
88         outb(value, 0x80);
89 #endif
90 }
91
92 /* Report a fatal error */
93 void __attribute__((noreturn)) die(const char *msg)
94 {
95         printk(BIOS_EMERG, "%s", msg);
96         //post_code(0xff);
97         for (;;)
98                 hlt();          /* Halt */
99 }
100
101 #else
102
103 void console_init(void)
104 {
105
106 #if CONFIG_CONSOLE_NE2K
107         ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT);
108 #endif
109         static const char console_test[] =
110                 "\n\ncoreboot-"
111                 COREBOOT_VERSION
112                 COREBOOT_EXTRA_VERSION
113                 " "
114                 COREBOOT_BUILD
115                 " starting...\n";
116         print_info(console_test);
117 }
118
119 void post_code(u8 value)
120 {
121 #if !defined(CONFIG_NO_POST) || CONFIG_NO_POST==0
122 #if CONFIG_SERIAL_POST==1
123         print_emerg("POST: 0x");
124         print_emerg_hex8(value);
125         print_emerg("\n");
126 #endif
127         outb(value, 0x80);
128 #endif
129 }
130
131 void die(const char *str)
132 {
133         print_emerg(str);
134         do {
135                 hlt();
136         } while(1);
137 }
138 #endif