Add 2 missing license headers based on svn logs and remove an unneeded #include
[coreboot.git] / src / console / console.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003 Eric Biederman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <build.h>
22 #include <arch/hlt.h>
23 #include <arch/io.h>
24
25 #if CONFIG_CONSOLE_NE2K
26 #include <console/ne2k.h>
27 #endif
28
29 #ifndef __PRE_RAM__
30 #include <string.h>
31 #include <pc80/mc146818rtc.h>
32
33 /* initialize the console */
34 void console_init(void)
35 {
36         struct console_driver *driver;
37         if(get_option(&console_loglevel, "debug_level"))
38                 console_loglevel=CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
39
40         for(driver = console_drivers; driver < econsole_drivers; driver++) {
41                 if (!driver->init)
42                         continue;
43                 driver->init();
44         }
45 }
46
47 static void __console_tx_byte(unsigned char byte)
48 {
49         struct console_driver *driver;
50         for(driver = console_drivers; driver < econsole_drivers; driver++) {
51                 driver->tx_byte(byte);
52         }
53 }
54
55 void console_tx_flush(void)
56 {
57         struct console_driver *driver;
58         for(driver = console_drivers; driver < econsole_drivers; driver++) {
59                 if (!driver->tx_flush)
60                         continue;
61                 driver->tx_flush();
62         }
63 }
64
65 void console_tx_byte(unsigned char byte)
66 {
67         if (byte == '\n')
68                 __console_tx_byte('\r');
69         __console_tx_byte(byte);
70 }
71
72 unsigned char console_rx_byte(void)
73 {
74         struct console_driver *driver;
75         for(driver = console_drivers; driver < econsole_drivers; driver++) {
76                 if (driver->tst_byte)
77                         break;
78         }
79         if (driver == econsole_drivers)
80                 return 0;
81         while (!driver->tst_byte());
82         return driver->rx_byte();
83 }
84
85 int console_tst_byte(void)
86 {
87         struct console_driver *driver;
88         for(driver = console_drivers; driver < econsole_drivers; driver++)
89                 if (driver->tst_byte)
90                         return driver->tst_byte();
91         return 0;
92 }
93
94 /*
95  *    Write POST information
96  */
97 void post_code(u8 value)
98 {
99 #if !defined(CONFIG_NO_POST) || CONFIG_NO_POST==0
100 #if CONFIG_SERIAL_POST==1
101         printk(BIOS_EMERG, "POST: 0x%02x\n", value);
102 #endif
103         outb(value, 0x80);
104 #endif
105 }
106
107 /* Report a fatal error */
108 void __attribute__((noreturn)) die(const char *msg)
109 {
110         printk(BIOS_EMERG, "%s", msg);
111         //post_code(0xff);
112         for (;;)
113                 hlt();          /* Halt */
114 }
115
116 #else
117
118 void console_init(void)
119 {
120 #if CONFIG_CONSOLE_NE2K
121         ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT);
122 #endif
123         static const char console_test[] =
124                 "\n\ncoreboot-"
125                 COREBOOT_VERSION
126                 COREBOOT_EXTRA_VERSION
127                 " "
128                 COREBOOT_BUILD
129                 " starting...\n";
130         print_info(console_test);
131 }
132
133 void post_code(u8 value)
134 {
135 #if !defined(CONFIG_NO_POST) || CONFIG_NO_POST==0
136 #if CONFIG_SERIAL_POST==1
137         print_emerg("POST: 0x");
138         print_emerg_hex8(value);
139         print_emerg("\n");
140 #endif
141         outb(value, 0x80);
142 #endif
143 }
144
145 void die(const char *str)
146 {
147         print_emerg(str);
148         do {
149                 hlt();
150         } while(1);
151 }
152 #endif