4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
31 #include <sys/varargs.h>
33 static void _doprint(const char *, va_list, void (*)(char, char **), char **);
34 static void _printn(uint64_t, int, int, int, void (*)(char, char **), char **);
37 * Emit character functions...
42 _pput(char c
, char **p
)
44 (void) prom_putchar(c
);
48 _sput(char c
, char **p
)
56 prom_printf(const char *fmt
, ...)
61 (void) _doprint(fmt
, adx
, _pput
, (char **)0);
66 prom_vprintf(const char *fmt
, va_list adx
)
71 (void) _doprint(fmt
, tadx
, _pput
, (char **)0);
77 prom_sprintf(char *s
, const char *fmt
, ...)
83 (void) _doprint(fmt
, adx
, _sput
, &bp
);
90 prom_vsprintf(char *s
, const char *fmt
, va_list adx
)
94 (void) _doprint(fmt
, adx
, _sput
, &bp
);
100 _doprint(const char *fmt
, va_list adx
, void (*emit
)(char, char **), char **bp
)
102 int b
, c
, i
, pad
, width
, ells
;
109 while ((c
= *fmt
++) != '%') {
119 for (pad
= ' '; c
== '0'; c
= *fmt
++)
122 for (width
= 0; c
>= '0' && c
<= '9'; c
= *fmt
++)
123 width
= (width
* 10) + (c
- '0');
125 for (ells
= 0; c
== 'l'; c
= *fmt
++)
134 l
= (int64_t)va_arg(adx
, int);
136 l
= (int64_t)va_arg(adx
, long);
138 l
= (int64_t)va_arg(adx
, int64_t);
164 ul
= (uint64_t)va_arg(adx
, uint_t
);
166 ul
= (uint64_t)va_arg(adx
, ulong_t
);
168 ul
= (uint64_t)va_arg(adx
, uint64_t);
170 _printn(ul
, b
, width
, pad
, emit
, bp
);
174 b
= va_arg(adx
, int);
175 for (i
= 24; i
>= 0; i
-= 8)
176 if ((c
= ((b
>> i
) & 0x7f)) != 0) {
183 s
= va_arg(adx
, char *);
184 while ((c
= *s
++) != 0) {
199 * Printn prints a number n in base b.
200 * We don't use recursion to avoid deep kernel stacks.
203 _printn(uint64_t n
, int b
, int width
, int pad
, void (*emit
)(char, char **),
211 *cp
++ = "0123456789abcdef"[n
%b
];
219 } while (cp
> prbuf
);