Damien Roth | 4e7e987 | 2016-01-16 18:59:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 3 | * |
Damien Roth | 4e7e987 | 2016-01-16 18:59:51 -0700 | [diff] [blame] | 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 | * vtxprintf.c, originally from linux/lib/vsprintf.c |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 16 | #include <console/vtxprintf.h> |
Joel Kitching | 393c71c | 2019-06-16 16:09:42 +0800 | [diff] [blame] | 17 | #include <ctype.h> |
Edward O'Callaghan | 0ddb826 | 2014-06-17 18:37:08 +1000 | [diff] [blame] | 18 | #include <string.h> |
Jacob Garber | c764fb2 | 2019-07-03 12:38:46 -0600 | [diff] [blame] | 19 | #include <stdint.h> |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 20 | |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 21 | #define call_tx(x) tx_byte(x, data) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 22 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 23 | #define ZEROPAD 1 /* pad with zero */ |
| 24 | #define SIGN 2 /* unsigned/signed long */ |
| 25 | #define PLUS 4 /* show plus */ |
| 26 | #define SPACE 8 /* space if plus */ |
| 27 | #define LEFT 16 /* left justified */ |
| 28 | #define SPECIAL 32 /* 0x */ |
| 29 | #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ |
| 30 | |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 31 | static int number(void (*tx_byte)(unsigned char byte, void *data), |
Vadim Bendebury | 9b058467 | 2014-11-29 22:05:09 -0800 | [diff] [blame] | 32 | unsigned long long inum, int base, int size, int precision, int type, |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 33 | void *data) |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 34 | { |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 35 | char c, sign, tmp[66]; |
Jacob Garber | b19946c | 2019-07-03 14:40:11 -0600 | [diff] [blame] | 36 | const char *digits = "0123456789abcdef"; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 37 | int i; |
| 38 | int count = 0; |
Vadim Bendebury | 9b058467 | 2014-11-29 22:05:09 -0800 | [diff] [blame] | 39 | unsigned long long num = inum; |
Julius Werner | 7c712bb | 2019-05-01 16:51:20 -0700 | [diff] [blame] | 40 | long long snum = num; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 41 | |
| 42 | if (type & LARGE) |
Jacob Garber | b19946c | 2019-07-03 14:40:11 -0600 | [diff] [blame] | 43 | digits = "0123456789ABCDEF"; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 44 | if (type & LEFT) |
| 45 | type &= ~ZEROPAD; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 46 | c = (type & ZEROPAD) ? '0' : ' '; |
| 47 | sign = 0; |
| 48 | if (type & SIGN) { |
Julius Werner | 7c712bb | 2019-05-01 16:51:20 -0700 | [diff] [blame] | 49 | if (snum < 0) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 50 | sign = '-'; |
Julius Werner | 7c712bb | 2019-05-01 16:51:20 -0700 | [diff] [blame] | 51 | num = -snum; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 52 | size--; |
| 53 | } else if (type & PLUS) { |
| 54 | sign = '+'; |
| 55 | size--; |
| 56 | } else if (type & SPACE) { |
| 57 | sign = ' '; |
| 58 | size--; |
| 59 | } |
| 60 | } |
| 61 | if (type & SPECIAL) { |
| 62 | if (base == 16) |
| 63 | size -= 2; |
| 64 | else if (base == 8) |
| 65 | size--; |
| 66 | } |
| 67 | i = 0; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 68 | if (num == 0) { |
| 69 | tmp[i++] = '0'; |
| 70 | } else { |
| 71 | while (num != 0) { |
| 72 | tmp[i++] = digits[num % base]; |
| 73 | num /= base; |
| 74 | } |
Ronald G. Minnich | 79e36d9 | 2013-01-30 14:29:34 -0800 | [diff] [blame] | 75 | } |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 76 | if (i > precision) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 77 | precision = i; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 78 | } |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 79 | size -= precision; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 80 | if (!(type&(ZEROPAD+LEFT))) { |
Elyes HAOUAS | 2e0f3d7 | 2018-05-03 09:36:28 +0200 | [diff] [blame] | 81 | while (size-- > 0) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 82 | call_tx(' '), count++; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 83 | } |
| 84 | if (sign) { |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 85 | call_tx(sign), count++; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 86 | } |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 87 | if (type & SPECIAL) { |
Elyes HAOUAS | 20767ba | 2018-04-26 10:00:35 +0200 | [diff] [blame] | 88 | if (base == 8) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 89 | call_tx('0'), count++; |
Elyes HAOUAS | 20767ba | 2018-04-26 10:00:35 +0200 | [diff] [blame] | 90 | else if (base == 16) { |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 91 | call_tx('0'), count++; |
Jacob Garber | 5b99481 | 2019-07-10 11:44:45 -0600 | [diff] [blame] | 92 | if (type & LARGE) |
| 93 | call_tx('X'), count++; |
| 94 | else |
| 95 | call_tx('x'), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 98 | if (!(type & LEFT)) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 99 | while (size-- > 0) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 100 | call_tx(c), count++; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 101 | } |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 102 | while (i < precision--) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 103 | call_tx('0'), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 104 | while (i-- > 0) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 105 | call_tx(tmp[i]), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 106 | while (size-- > 0) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 107 | call_tx(' '), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 108 | return count; |
| 109 | } |
| 110 | |
| 111 | |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 112 | int vtxprintf(void (*tx_byte)(unsigned char byte, void *data), |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 113 | const char *fmt, va_list args, void *data) |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 114 | { |
| 115 | int len; |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 116 | unsigned long long num; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 117 | int i, base; |
| 118 | const char *s; |
| 119 | |
| 120 | int flags; /* flags to number() */ |
| 121 | |
| 122 | int field_width; /* width of output field */ |
| 123 | int precision; /* min. # of digits for integers; max |
| 124 | number of chars for from string */ |
Jacob Garber | c764fb2 | 2019-07-03 12:38:46 -0600 | [diff] [blame] | 125 | int qualifier; /* 'h', 'H', 'l', 'L', 'z', or 'j' for integer fields */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 126 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 127 | int count; |
| 128 | |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 129 | for (count = 0; *fmt ; ++fmt) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 130 | if (*fmt != '%') { |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 131 | call_tx(*fmt), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 132 | continue; |
| 133 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 134 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 135 | /* process flags */ |
| 136 | flags = 0; |
Patrick Georgi | c5fc7db | 2012-03-07 15:55:47 +0100 | [diff] [blame] | 137 | repeat: |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 138 | ++fmt; /* this also skips first '%' */ |
| 139 | switch (*fmt) { |
| 140 | case '-': flags |= LEFT; goto repeat; |
| 141 | case '+': flags |= PLUS; goto repeat; |
| 142 | case ' ': flags |= SPACE; goto repeat; |
| 143 | case '#': flags |= SPECIAL; goto repeat; |
| 144 | case '0': flags |= ZEROPAD; goto repeat; |
| 145 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 146 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 147 | /* get field width */ |
| 148 | field_width = -1; |
Julius Werner | 66c77c2 | 2019-05-13 17:45:27 -0700 | [diff] [blame] | 149 | if (isdigit(*fmt)) { |
| 150 | field_width = skip_atoi((char **)&fmt); |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 151 | } else if (*fmt == '*') { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 152 | ++fmt; |
| 153 | /* it's the next argument */ |
| 154 | field_width = va_arg(args, int); |
| 155 | if (field_width < 0) { |
| 156 | field_width = -field_width; |
| 157 | flags |= LEFT; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /* get the precision */ |
| 162 | precision = -1; |
| 163 | if (*fmt == '.') { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 164 | ++fmt; |
Julius Werner | 66c77c2 | 2019-05-13 17:45:27 -0700 | [diff] [blame] | 165 | if (isdigit(*fmt)) { |
| 166 | precision = skip_atoi((char **)&fmt); |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 167 | } else if (*fmt == '*') { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 168 | ++fmt; |
| 169 | /* it's the next argument */ |
| 170 | precision = va_arg(args, int); |
| 171 | } |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 172 | if (precision < 0) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 173 | precision = 0; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 174 | } |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /* get the conversion qualifier */ |
| 178 | qualifier = -1; |
Jacob Garber | c764fb2 | 2019-07-03 12:38:46 -0600 | [diff] [blame] | 179 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'z' || *fmt == 'j') { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 180 | qualifier = *fmt; |
| 181 | ++fmt; |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 182 | if (*fmt == 'l') { |
| 183 | qualifier = 'L'; |
| 184 | ++fmt; |
| 185 | } |
Patrick Georgi | d01ed75 | 2014-01-18 16:56:36 +0100 | [diff] [blame] | 186 | if (*fmt == 'h') { |
| 187 | qualifier = 'H'; |
| 188 | ++fmt; |
| 189 | } |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* default base */ |
| 193 | base = 10; |
| 194 | |
| 195 | switch (*fmt) { |
| 196 | case 'c': |
| 197 | if (!(flags & LEFT)) |
| 198 | while (--field_width > 0) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 199 | call_tx(' '), count++; |
| 200 | call_tx((unsigned char) va_arg(args, int)), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 201 | while (--field_width > 0) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 202 | call_tx(' '), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 203 | continue; |
| 204 | |
| 205 | case 's': |
| 206 | s = va_arg(args, char *); |
| 207 | if (!s) |
| 208 | s = "<NULL>"; |
| 209 | |
Martin Roth | ad6c885 | 2016-11-18 11:35:01 -0700 | [diff] [blame] | 210 | len = strnlen(s, (size_t)precision); |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 211 | |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 212 | if (!(flags & LEFT)) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 213 | while (len < field_width--) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 214 | call_tx(' '), count++; |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 215 | } |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 216 | for (i = 0; i < len; ++i) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 217 | call_tx(*s++), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 218 | while (len < field_width--) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 219 | call_tx(' '), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 220 | continue; |
| 221 | |
| 222 | case 'p': |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 223 | /* even on 64-bit systems, coreboot only resides in the |
| 224 | low 4GB so pad pointers to 32-bit for readability. */ |
| 225 | if (field_width == -1 && precision == -1) |
| 226 | precision = 2*sizeof(uint32_t); |
| 227 | flags |= SPECIAL; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 228 | count += number(tx_byte, |
| 229 | (unsigned long) va_arg(args, void *), 16, |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 230 | field_width, precision, flags, data); |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 231 | continue; |
| 232 | |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 233 | case 'n': |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 234 | if (qualifier == 'L') { |
| 235 | long long *ip = va_arg(args, long long *); |
| 236 | *ip = count; |
| 237 | } else if (qualifier == 'l') { |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 238 | long *ip = va_arg(args, long *); |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 239 | *ip = count; |
| 240 | } else { |
Elyes HAOUAS | a418414 | 2018-05-15 20:57:01 +0200 | [diff] [blame] | 241 | int *ip = va_arg(args, int *); |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 242 | *ip = count; |
| 243 | } |
| 244 | continue; |
| 245 | |
| 246 | case '%': |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 247 | call_tx('%'), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 248 | continue; |
| 249 | |
| 250 | /* integer number formats - set up the flags and "break" */ |
| 251 | case 'o': |
| 252 | base = 8; |
| 253 | break; |
| 254 | |
| 255 | case 'X': |
| 256 | flags |= LARGE; |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 257 | /* fall through */ |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 258 | case 'x': |
| 259 | base = 16; |
| 260 | break; |
| 261 | |
| 262 | case 'd': |
| 263 | case 'i': |
| 264 | flags |= SIGN; |
| 265 | case 'u': |
| 266 | break; |
| 267 | |
| 268 | default: |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 269 | call_tx('%'), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 270 | if (*fmt) |
Vladimir Serbinenko | f421b33 | 2013-11-26 21:43:05 +0100 | [diff] [blame] | 271 | call_tx(*fmt), count++; |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 272 | else |
| 273 | --fmt; |
| 274 | continue; |
| 275 | } |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 276 | if (qualifier == 'L') { |
| 277 | num = va_arg(args, unsigned long long); |
| 278 | } else if (qualifier == 'l') { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 279 | num = va_arg(args, unsigned long); |
Stefan Reinauer | bfff6de | 2012-05-15 13:28:07 -0700 | [diff] [blame] | 280 | } else if (qualifier == 'z') { |
| 281 | num = va_arg(args, size_t); |
Jacob Garber | c764fb2 | 2019-07-03 12:38:46 -0600 | [diff] [blame] | 282 | } else if (qualifier == 'j') { |
| 283 | num = va_arg(args, uintmax_t); |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 284 | } else if (qualifier == 'h') { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 285 | num = (unsigned short) va_arg(args, int); |
| 286 | if (flags & SIGN) |
| 287 | num = (short) num; |
Patrick Georgi | d01ed75 | 2014-01-18 16:56:36 +0100 | [diff] [blame] | 288 | } else if (qualifier == 'H') { |
| 289 | num = (unsigned char) va_arg(args, int); |
| 290 | if (flags & SIGN) |
| 291 | num = (signed char) num; |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 292 | } else if (flags & SIGN) { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 293 | num = va_arg(args, int); |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 294 | } else { |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 295 | num = va_arg(args, unsigned int); |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 296 | } |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 297 | count += number(tx_byte, num, base, field_width, precision, flags, data); |
Stefan Reinauer | 34e3a14 | 2004-05-28 15:07:03 +0000 | [diff] [blame] | 298 | } |
| 299 | return count; |
| 300 | } |