Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 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 | |
Kyösti Mälkki | 4770749 | 2014-02-15 07:53:18 +0200 | [diff] [blame] | 20 | #include <console/uart.h> |
Kyösti Mälkki | 1d7541f | 2014-02-17 21:34:42 +0200 | [diff] [blame] | 21 | #include <console/ne2k.h> |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 22 | |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 23 | /* While in romstage, console loglevel is built-time constant. */ |
| 24 | #define console_log_level(msg_level) (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= msg_level) |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 25 | |
Kyösti Mälkki | afa7b13 | 2014-02-13 17:16:22 +0200 | [diff] [blame] | 26 | #if CONFIG_CONSOLE_SERIAL && CONFIG_DRIVERS_UART_8250IO |
Kyösti Mälkki | 3ee1668 | 2014-02-17 19:37:52 +0200 | [diff] [blame] | 27 | #include "drivers/uart/util.c" |
Kyösti Mälkki | bea6bf0 | 2014-01-30 15:45:16 +0200 | [diff] [blame] | 28 | #include "drivers/uart/uart8250io.c" |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 29 | #endif |
| 30 | #if CONFIG_CONSOLE_NE2K |
Kyösti Mälkki | 207379d | 2014-01-31 07:38:21 +0200 | [diff] [blame] | 31 | #include "drivers/net/ne2k.c" |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
| 34 | static void __console_tx_byte(unsigned char byte) |
| 35 | { |
Kyösti Mälkki | afa7b13 | 2014-02-13 17:16:22 +0200 | [diff] [blame] | 36 | #if CONFIG_CONSOLE_SERIAL |
Kyösti Mälkki | 4770749 | 2014-02-15 07:53:18 +0200 | [diff] [blame] | 37 | uart_tx_byte(byte); |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 38 | #endif |
| 39 | #if CONFIG_CONSOLE_NE2K |
| 40 | ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT); |
| 41 | #endif |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Kyösti Mälkki | dbc7bd9 | 2014-01-28 11:34:38 +0200 | [diff] [blame^] | 44 | static 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 Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 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 | { |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 66 | if (console_log_level(loglevel)) { |
Kyösti Mälkki | dbc7bd9 | 2014-01-28 11:34:38 +0200 | [diff] [blame^] | 67 | __console_tx_byte(byte); |
| 68 | __console_tx_flush(); |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | static void __console_tx_hex8(int loglevel, unsigned char value) |
| 73 | { |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 74 | if (console_log_level(loglevel)) { |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 75 | __console_tx_nibble((value >> 4U) & 0x0fU); |
| 76 | __console_tx_nibble(value & 0x0fU); |
Kyösti Mälkki | dbc7bd9 | 2014-01-28 11:34:38 +0200 | [diff] [blame^] | 77 | __console_tx_flush(); |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 78 | } |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void __console_tx_hex16(int loglevel, unsigned short value) |
| 82 | { |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 83 | if (console_log_level(loglevel)) { |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 84 | __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älkki | dbc7bd9 | 2014-01-28 11:34:38 +0200 | [diff] [blame^] | 88 | __console_tx_flush(); |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 89 | } |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static void __console_tx_hex32(int loglevel, unsigned int value) |
| 93 | { |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 94 | if (console_log_level(loglevel)) { |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 95 | __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älkki | dbc7bd9 | 2014-01-28 11:34:38 +0200 | [diff] [blame^] | 103 | __console_tx_flush(); |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 104 | } |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void __console_tx_string(int loglevel, const char *str) |
| 108 | { |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 109 | if (console_log_level(loglevel)) { |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 110 | 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älkki | dbc7bd9 | 2014-01-28 11:34:38 +0200 | [diff] [blame^] | 116 | __console_tx_flush(); |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | /* if included by romcc, include the sources, too. romcc can't use prototypes */ |
| 121 | #include <console/console.c> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 122 | #include <console/init.c> |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 123 | #include <console/post.c> |
| 124 | #include <console/die.c> |