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 (c) 1995-1996, by Sun Microsystems, Inc.
24 * All rights reserved.
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, char **);
34 static void _printn(uint64_t, int, int, int, char **);
37 * Emit character functions...
41 _pput_flush(char *start
, char *end
)
43 while (prom_write(prom_stdout_ihandle(),
44 start
, end
- start
, 0, BYTE
) == -1)
49 _sput(char c
, char **p
)
57 prom_printf(const char *fmt
, ...)
62 _doprint(fmt
, adx
, (char **)0);
67 prom_vprintf(const char *fmt
, va_list adx
)
69 _doprint(fmt
, adx
, (char **)0);
74 prom_sprintf(char *s
, const char *fmt
, ...)
80 _doprint(fmt
, adx
, &bp
);
87 prom_vsprintf(char *s
, const char *fmt
, va_list adx
)
91 _doprint(fmt
, adx
, &bp
);
97 _doprint(const char *fmt
, va_list adx
, char **bp
)
99 int b
, c
, i
, pad
, width
, ells
;
101 char localbuf
[100], *lbp
;
112 while ((c
= *fmt
++) != '%') {
118 if (start
== localbuf
) {
119 _pput_flush(start
, *bp
);
124 if (start
== localbuf
&& (*bp
- start
> 80)) {
125 _pput_flush(start
, *bp
);
131 for (pad
= ' '; c
== '0'; c
= *fmt
++)
134 for (width
= 0; c
>= '0' && c
<= '9'; c
= *fmt
++)
135 width
= width
* 10 + c
- '0';
137 for (ells
= 0; c
== 'l'; c
= *fmt
++)
145 l
= (int64_t)va_arg(adx
, int);
147 l
= (int64_t)va_arg(adx
, long);
149 l
= (int64_t)va_arg(adx
, int64_t);
175 ul
= (uint64_t)va_arg(adx
, u_int
);
177 ul
= (uint64_t)va_arg(adx
, u_long
);
179 ul
= (uint64_t)va_arg(adx
, uint64_t);
181 _printn(ul
, b
, width
, pad
, bp
);
185 b
= va_arg(adx
, int);
186 for (i
= 24; i
>= 0; i
-= 8)
187 if ((c
= ((b
>> i
) & 0x7f)) != 0) {
195 s
= va_arg(adx
, char *);
196 while ((c
= *s
++) != 0) {
200 if (start
== localbuf
&& (*bp
- start
> 80)) {
201 _pput_flush(start
, *bp
);
211 if (start
== localbuf
&& (*bp
- start
> 80)) {
212 _pput_flush(start
, *bp
);
217 if (start
== localbuf
&& (*bp
- start
> 0))
218 _pput_flush(start
, *bp
);
222 * Printn prints a number n in base b.
223 * We don't use recursion to avoid deep kernel stacks.
226 _printn(uint64_t n
, int b
, int width
, int pad
, char **bp
)
233 *cp
++ = "0123456789abcdef"[n
%b
];
241 } while (cp
> prbuf
);