CBMEM CONSOLE: Add code using the new console driver.
[coreboot.git] / src / arch / x86 / lib / romcc_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 <stdint.h>
21 #include <console/loglevel.h>
22 #include <console/post_codes.h>
23
24 /* __PRE_RAM__ */
25 /* Using a global varible can cause problems when we reset the stack
26  * from cache as ram to ram. If we make this a define USE_SHARED_STACK
27  * we could use the same code on all architectures.
28  */
29 #define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
30 #if CONFIG_CONSOLE_SERIAL8250
31 #include <uart8250.h>
32 #endif
33
34 #if CONFIG_CONSOLE_SERIAL8250
35 #include "lib/uart8250.c"
36 #endif
37 #if CONFIG_CONSOLE_NE2K
38 #include "lib/ne2k.c"
39 #endif
40
41 static void __console_tx_byte(unsigned char byte)
42 {
43 #if CONFIG_CONSOLE_SERIAL8250
44         uart8250_tx_byte(CONFIG_TTYS0_BASE, byte);
45 #endif
46 #if CONFIG_CONSOLE_NE2K
47         ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
48 #endif
49 #if CONFIG_CONSOLE_CBMEM
50         cbmemc_tx_byte(byte);
51 #endif
52 }
53
54 static void __console_tx_nibble(unsigned nibble)
55 {
56         unsigned char digit;
57         digit = nibble + '0';
58         if (digit > '9') {
59                 digit += 39;
60         }
61         __console_tx_byte(digit);
62 }
63
64 static void __console_tx_char(int loglevel, unsigned char byte)
65 {
66         if (console_loglevel >= loglevel) {
67 #if CONFIG_CONSOLE_SERIAL8250
68                 uart8250_tx_byte(CONFIG_TTYS0_BASE, byte);
69 #endif
70 #if CONFIG_CONSOLE_NE2K
71                 ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
72                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
73 #endif
74         }
75 }
76
77 static void __console_tx_hex8(int loglevel, unsigned char value)
78 {
79         if (console_loglevel >= loglevel) {
80                 __console_tx_nibble((value >>  4U) & 0x0fU);
81                 __console_tx_nibble(value & 0x0fU);
82         }
83 #if CONFIG_CONSOLE_NE2K
84                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
85 #endif
86 }
87
88 static void __console_tx_hex16(int loglevel, unsigned short value)
89 {
90         if (console_loglevel >= loglevel) {
91                 __console_tx_nibble((value >> 12U) & 0x0fU);
92                 __console_tx_nibble((value >>  8U) & 0x0fU);
93                 __console_tx_nibble((value >>  4U) & 0x0fU);
94                 __console_tx_nibble(value & 0x0fU);
95         }
96 #if CONFIG_CONSOLE_NE2K
97                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
98 #endif
99 }
100
101 static void __console_tx_hex32(int loglevel, unsigned int value)
102 {
103         if (console_loglevel >= loglevel) {
104                 __console_tx_nibble((value >> 28U) & 0x0fU);
105                 __console_tx_nibble((value >> 24U) & 0x0fU);
106                 __console_tx_nibble((value >> 20U) & 0x0fU);
107                 __console_tx_nibble((value >> 16U) & 0x0fU);
108                 __console_tx_nibble((value >> 12U) & 0x0fU);
109                 __console_tx_nibble((value >>  8U) & 0x0fU);
110                 __console_tx_nibble((value >>  4U) & 0x0fU);
111                 __console_tx_nibble(value & 0x0fU);
112         }
113 #if CONFIG_CONSOLE_NE2K
114                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
115 #endif
116 }
117
118 static void __console_tx_string(int loglevel, const char *str)
119 {
120         if (console_loglevel >= loglevel) {
121                 unsigned char ch;
122                 while((ch = *str++) != '\0') {
123                         if (ch == '\n')
124                                 __console_tx_byte('\r');
125                         __console_tx_byte(ch);
126                 }
127 #if CONFIG_CONSOLE_NE2K
128                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
129 #endif
130         }
131 }
132
133 /* if included by romcc, include the sources, too. romcc can't use prototypes */
134 #include <console/console.c>
135 #include <console/post.c>
136 #include <console/die.c>
137
138