blob: 0557a52e5c6162f1e566512b1abe2891da3fa2e4 [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
Kyösti Mälkki47707492014-02-15 07:53:18 +020020#include <console/uart.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020021#include <console/ne2k.h>
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000022
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020023/* While in romstage, console loglevel is built-time constant. */
24#define console_log_level(msg_level) (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= msg_level)
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000025
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020026#if CONFIG_CONSOLE_SERIAL && CONFIG_DRIVERS_UART_8250IO
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020027#include "drivers/uart/util.c"
Kyösti Mälkkibea6bf02014-01-30 15:45:16 +020028#include "drivers/uart/uart8250io.c"
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000029#endif
30#if CONFIG_CONSOLE_NE2K
Kyösti Mälkki207379d2014-01-31 07:38:21 +020031#include "drivers/net/ne2k.c"
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000032#endif
33
34static void __console_tx_byte(unsigned char byte)
35{
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020036#if CONFIG_CONSOLE_SERIAL
Kyösti Mälkki47707492014-02-15 07:53:18 +020037 uart_tx_byte(byte);
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000038#endif
39#if CONFIG_CONSOLE_NE2K
40 ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
41#endif
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000042}
43
Kyösti Mälkkidbc7bd92014-01-28 11:34:38 +020044static void __console_tx_flush(void)
45{
46#if CONFIG_CONSOLE_SERIAL
47 uart_tx_flush();
48#endif
49#if CONFIG_CONSOLE_NE2K
50 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
51#endif
52}
53
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000054static 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
64static void __console_tx_char(int loglevel, unsigned char byte)
65{
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020066 if (console_log_level(loglevel)) {
Kyösti Mälkkidbc7bd92014-01-28 11:34:38 +020067 __console_tx_byte(byte);
68 __console_tx_flush();
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000069 }
70}
71
72static void __console_tx_hex8(int loglevel, unsigned char value)
73{
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020074 if (console_log_level(loglevel)) {
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000075 __console_tx_nibble((value >> 4U) & 0x0fU);
76 __console_tx_nibble(value & 0x0fU);
Kyösti Mälkkidbc7bd92014-01-28 11:34:38 +020077 __console_tx_flush();
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000078 }
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000079}
80
81static void __console_tx_hex16(int loglevel, unsigned short value)
82{
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020083 if (console_log_level(loglevel)) {
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000084 __console_tx_nibble((value >> 12U) & 0x0fU);
85 __console_tx_nibble((value >> 8U) & 0x0fU);
86 __console_tx_nibble((value >> 4U) & 0x0fU);
87 __console_tx_nibble(value & 0x0fU);
Kyösti Mälkkidbc7bd92014-01-28 11:34:38 +020088 __console_tx_flush();
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000089 }
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000090}
91
92static void __console_tx_hex32(int loglevel, unsigned int value)
93{
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020094 if (console_log_level(loglevel)) {
Stefan Reinauerbbd2f212011-04-20 21:11:22 +000095 __console_tx_nibble((value >> 28U) & 0x0fU);
96 __console_tx_nibble((value >> 24U) & 0x0fU);
97 __console_tx_nibble((value >> 20U) & 0x0fU);
98 __console_tx_nibble((value >> 16U) & 0x0fU);
99 __console_tx_nibble((value >> 12U) & 0x0fU);
100 __console_tx_nibble((value >> 8U) & 0x0fU);
101 __console_tx_nibble((value >> 4U) & 0x0fU);
102 __console_tx_nibble(value & 0x0fU);
Kyösti Mälkkidbc7bd92014-01-28 11:34:38 +0200103 __console_tx_flush();
Stefan Reinauerbbd2f212011-04-20 21:11:22 +0000104 }
Stefan Reinauerbbd2f212011-04-20 21:11:22 +0000105}
106
107static void __console_tx_string(int loglevel, const char *str)
108{
Kyösti Mälkki56ae1392014-02-28 14:37:27 +0200109 if (console_log_level(loglevel)) {
Stefan Reinauerbbd2f212011-04-20 21:11:22 +0000110 unsigned char ch;
111 while((ch = *str++) != '\0') {
112 if (ch == '\n')
113 __console_tx_byte('\r');
114 __console_tx_byte(ch);
115 }
Kyösti Mälkkidbc7bd92014-01-28 11:34:38 +0200116 __console_tx_flush();
Stefan Reinauerbbd2f212011-04-20 21:11:22 +0000117 }
118}
119
120/* if included by romcc, include the sources, too. romcc can't use prototypes */
121#include <console/console.c>
Kyösti Mälkki21333f92014-02-14 10:04:31 +0200122#include <console/init.c>
Stefan Reinauerbbd2f212011-04-20 21:11:22 +0000123#include <console/post.c>
124#include <console/die.c>