d50876d750d628840d840bdfdbc5a1d3de5b444a
2 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
12 #define get_num_va_args(_args, _lcount) \
13 (((_lcount) > 1) ? va_arg(_args, long long int) : \
14 (((_lcount) == 1) ? va_arg(_args, long int) : \
17 #define get_unum_va_args(_args, _lcount) \
18 (((_lcount) > 1) ? va_arg(_args, unsigned long long int) : \
19 (((_lcount) == 1) ? va_arg(_args, unsigned long int) : \
20 va_arg(_args, unsigned int)))
22 static int string_print(const char *str
)
28 for ( ; *str
!= '\0'; str
++) {
36 static int unsigned_num_print(unsigned long long int unum
, unsigned int radix
,
39 /* Just need enough space to store 64 bit decimal integer */
47 num_buf
[i
] = '0' + rem
;
49 num_buf
[i
] = 'a' + (rem
- 0xa);
63 (void)putchar(num_buf
[i
]);
70 /*******************************************************************
71 * Reduced format print for Trusted firmware.
72 * The following type specifiers are supported by this print
73 * %x - hexadecimal format
75 * %d or %i - signed decimal format
76 * %u - unsigned decimal format
79 * The following length specifiers are supported by this print
80 * %l - long int (64-bit on AArch64)
81 * %ll - long long int (64-bit on AArch64)
82 * %z - size_t sized integer formats (64 bit on AArch64)
84 * The following padding specifiers are supported by this print
85 * %0NN - Left-pad the number with 0s (NN is a decimal number)
87 * The print exits on all other formats specifiers other than valid
88 * combinations of the above specifiers.
89 *******************************************************************/
90 int vprintf(const char *fmt
, va_list args
)
94 unsigned long long int unum
;
96 char padc
= '\0'; /* Padding character */
97 int padn
; /* Number of characters to pad */
98 int count
= 0; /* Number of printed characters */
100 while (*fmt
!= '\0') {
106 /* Check the format specifier */
109 case 'i': /* Fall through to next one */
111 num
= get_num_va_args(args
, l_count
);
114 unum
= (unsigned long long int)-num
;
117 unum
= (unsigned long long int)num
;
119 count
+= unsigned_num_print(unum
, 10,
123 str
= va_arg(args
, char *);
124 count
+= string_print(str
);
127 unum
= (uintptr_t)va_arg(args
, void *);
129 count
+= string_print("0x");
133 count
+= unsigned_num_print(unum
, 16,
137 unum
= get_unum_va_args(args
, l_count
);
138 count
+= unsigned_num_print(unum
, 16,
142 if (sizeof(size_t) == 8U)
152 unum
= get_unum_va_args(args
, l_count
);
153 count
+= unsigned_num_print(unum
, 10,
163 if ((ch
< '0') || (ch
> '9')) {
166 padn
= (padn
* 10) + (ch
- '0');
169 assert(0); /* Unreachable */
171 /* Exit on any other format specifier */
185 int printf(const char *fmt
, ...)
191 count
= vprintf(fmt
, va
);