blob: 66c81db36f16f1c53a2f13383cf6e010b0847eb9 [file] [log] [blame]
Stefan Reinauerbbd2f212011-04-20 21:11:22 +00001/*
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>
Kyösti Mälkki47707492014-02-15 07:53:18 +020023#include <console/uart.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020024#include <console/ne2k.h>
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000025
26/* __PRE_RAM__ */
27/* Using a global varible can cause problems when we reset the stack
28 * from cache as ram to ram. If we make this a define USE_SHARED_STACK
29 * we could use the same code on all architectures.
30 */
31#define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000032
33#if CONFIG_CONSOLE_SERIAL8250
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020034#include "drivers/uart/util.c"
Kyösti Mälkkibea6bf02014-01-30 15:45:16 +020035#include "drivers/uart/uart8250io.c"
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000036#endif
37#if CONFIG_CONSOLE_NE2K
Kyösti Mälkki207379d2014-01-31 07:38:21 +020038#include "drivers/net/ne2k.c"
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000039#endif
40
41static void __console_tx_byte(unsigned char byte)
42{
43#if CONFIG_CONSOLE_SERIAL8250
Kyösti Mälkki47707492014-02-15 07:53:18 +020044 uart_tx_byte(byte);
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000045#endif
46#if CONFIG_CONSOLE_NE2K
47 ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
48#endif
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000049}
50
51static void __console_tx_nibble(unsigned nibble)
52{
53 unsigned char digit;
54 digit = nibble + '0';
55 if (digit > '9') {
56 digit += 39;
57 }
58 __console_tx_byte(digit);
59}
60
61static void __console_tx_char(int loglevel, unsigned char byte)
62{
63 if (console_loglevel >= loglevel) {
64#if CONFIG_CONSOLE_SERIAL8250
Kyösti Mälkki47707492014-02-15 07:53:18 +020065 uart_tx_byte(byte);
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000066#endif
67#if CONFIG_CONSOLE_NE2K
68 ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
69 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
70#endif
71 }
72}
73
74static void __console_tx_hex8(int loglevel, unsigned char value)
75{
76 if (console_loglevel >= loglevel) {
77 __console_tx_nibble((value >> 4U) & 0x0fU);
78 __console_tx_nibble(value & 0x0fU);
79 }
80#if CONFIG_CONSOLE_NE2K
81 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
82#endif
83}
84
85static void __console_tx_hex16(int loglevel, unsigned short value)
86{
87 if (console_loglevel >= loglevel) {
88 __console_tx_nibble((value >> 12U) & 0x0fU);
89 __console_tx_nibble((value >> 8U) & 0x0fU);
90 __console_tx_nibble((value >> 4U) & 0x0fU);
91 __console_tx_nibble(value & 0x0fU);
92 }
93#if CONFIG_CONSOLE_NE2K
94 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
95#endif
96}
97
98static void __console_tx_hex32(int loglevel, unsigned int value)
99{
100 if (console_loglevel >= loglevel) {
101 __console_tx_nibble((value >> 28U) & 0x0fU);
102 __console_tx_nibble((value >> 24U) & 0x0fU);
103 __console_tx_nibble((value >> 20U) & 0x0fU);
104 __console_tx_nibble((value >> 16U) & 0x0fU);
105 __console_tx_nibble((value >> 12U) & 0x0fU);
106 __console_tx_nibble((value >> 8U) & 0x0fU);
107 __console_tx_nibble((value >> 4U) & 0x0fU);
108 __console_tx_nibble(value & 0x0fU);
109 }
110#if CONFIG_CONSOLE_NE2K
111 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
112#endif
113}
114
115static void __console_tx_string(int loglevel, const char *str)
116{
117 if (console_loglevel >= loglevel) {
118 unsigned char ch;
119 while((ch = *str++) != '\0') {
120 if (ch == '\n')
121 __console_tx_byte('\r');
122 __console_tx_byte(ch);
123 }
124#if CONFIG_CONSOLE_NE2K
125 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
126#endif
127 }
128}
129
130/* if included by romcc, include the sources, too. romcc can't use prototypes */
131#include <console/console.c>
132#include <console/post.c>
133#include <console/die.c>
134
135