Kyösti Mälkki | efb0b51 | 2014-04-13 17:57:34 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 15 | * Foundation, Inc. |
Kyösti Mälkki | efb0b51 | 2014-04-13 17:57:34 +0300 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <console/streams.h> |
| 19 | |
| 20 | void console_tx_nibble(unsigned nibble) |
| 21 | { |
| 22 | unsigned char digit; |
| 23 | digit = nibble + '0'; |
| 24 | if (digit > '9') { |
| 25 | digit += 39; |
| 26 | } |
| 27 | console_tx_byte(digit); |
| 28 | } |
| 29 | |
| 30 | void console_tx_hex8(unsigned char value) |
| 31 | { |
| 32 | console_tx_nibble((value >> 4U) & 0x0fU); |
| 33 | console_tx_nibble(value & 0x0fU); |
| 34 | } |
| 35 | |
| 36 | void console_tx_hex16(unsigned short value) |
| 37 | { |
| 38 | console_tx_nibble((value >> 12U) & 0x0fU); |
| 39 | console_tx_nibble((value >> 8U) & 0x0fU); |
| 40 | console_tx_nibble((value >> 4U) & 0x0fU); |
| 41 | console_tx_nibble(value & 0x0fU); |
| 42 | } |
| 43 | |
| 44 | void console_tx_hex32(unsigned int value) |
| 45 | { |
| 46 | console_tx_nibble((value >> 28U) & 0x0fU); |
| 47 | console_tx_nibble((value >> 24U) & 0x0fU); |
| 48 | console_tx_nibble((value >> 20U) & 0x0fU); |
| 49 | console_tx_nibble((value >> 16U) & 0x0fU); |
| 50 | console_tx_nibble((value >> 12U) & 0x0fU); |
| 51 | console_tx_nibble((value >> 8U) & 0x0fU); |
| 52 | console_tx_nibble((value >> 4U) & 0x0fU); |
| 53 | console_tx_nibble(value & 0x0fU); |
| 54 | } |
| 55 | |
| 56 | void console_tx_string(const char *str) |
| 57 | { |
| 58 | unsigned char ch; |
| 59 | while((ch = *str++) != '\0') { |
| 60 | if (ch == '\n') |
| 61 | console_tx_byte('\r'); |
| 62 | console_tx_byte(ch); |
| 63 | } |
| 64 | } |