blob: da6532f0fb882c376efbe1dab2fb14d1964c3bbd [file] [log] [blame]
Kyösti Mälkkiefb0b512014-04-13 17:57:34 +03001/*
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
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#include <console/streams.h>
19
20void 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
30void console_tx_hex8(unsigned char value)
31{
32 console_tx_nibble((value >> 4U) & 0x0fU);
33 console_tx_nibble(value & 0x0fU);
34}
35
36void 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
44void 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
56void 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}