blob: 900dd5d7a3b577a180e0ec619789563b51d7bf83 [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.
Kyösti Mälkkiefb0b512014-04-13 17:57:34 +030012 */
13
14#include <console/streams.h>
15
16void console_tx_nibble(unsigned nibble)
17{
18 unsigned char digit;
19 digit = nibble + '0';
20 if (digit > '9') {
21 digit += 39;
22 }
23 console_tx_byte(digit);
24}
25
26void console_tx_hex8(unsigned char value)
27{
28 console_tx_nibble((value >> 4U) & 0x0fU);
29 console_tx_nibble(value & 0x0fU);
30}
31
32void console_tx_hex16(unsigned short value)
33{
34 console_tx_nibble((value >> 12U) & 0x0fU);
35 console_tx_nibble((value >> 8U) & 0x0fU);
36 console_tx_nibble((value >> 4U) & 0x0fU);
37 console_tx_nibble(value & 0x0fU);
38}
39
40void console_tx_hex32(unsigned int value)
41{
42 console_tx_nibble((value >> 28U) & 0x0fU);
43 console_tx_nibble((value >> 24U) & 0x0fU);
44 console_tx_nibble((value >> 20U) & 0x0fU);
45 console_tx_nibble((value >> 16U) & 0x0fU);
46 console_tx_nibble((value >> 12U) & 0x0fU);
47 console_tx_nibble((value >> 8U) & 0x0fU);
48 console_tx_nibble((value >> 4U) & 0x0fU);
49 console_tx_nibble(value & 0x0fU);
50}
51
52void console_tx_string(const char *str)
53{
54 unsigned char ch;
55 while((ch = *str++) != '\0') {
56 if (ch == '\n')
57 console_tx_byte('\r');
58 console_tx_byte(ch);
59 }
60}