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