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 | |
| 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 |
Kyösti Mälkki | 207379d | 2014-01-31 07:38:21 +0200 | [diff] [blame^] | 38 | #include "drivers/net/ne2k.c" |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 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 |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static 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 | |
| 61 | static void __console_tx_char(int loglevel, unsigned char byte) |
| 62 | { |
| 63 | if (console_loglevel >= loglevel) { |
| 64 | #if CONFIG_CONSOLE_SERIAL8250 |
| 65 | uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); |
| 66 | #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 | |
| 74 | static 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 | |
| 85 | static 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 | |
| 98 | static 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 | |
| 115 | static 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 | |