* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: prom_printf.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* Copyright (c) 2000-2003 Sun Microsystems, Inc.
* Use is subject to license terms.
#pragma ident "@(#)prom_printf.c 1.1 00/08/07 SMI"
#include <sys/promimpl.h>
static void _doprint(const char *, va_list, char **);
static void _printn(uint64_t, int, int, int, char **);
* Emit character functions...
_pput_flush(char *start
, char *end
)
while (prom_write(prom_stdout_ihandle(), start
, end
- start
) == -1)
prom_printf(const char *fmt
, ...)
_doprint(fmt
, adx
, (char **)0);
prom_vprintf(const char *fmt
, va_list adx
)
_doprint(fmt
, adx
, (char **)0);
prom_sprintf(char *s
, const char *fmt
, ...)
prom_vsprintf(char *s
, const char *fmt
, va_list adx
)
_doprint(const char *fmt
, va_list adx
, char **bp
)
int32_t b
, c
, i
, pad
, width
, ells
;
char localbuf
[100], *lbp
;
while ((c
= *fmt
++) != '%') {
if (start
== localbuf
&& (*bp
- start
> 80)) {
for (pad
= ' '; c
== '0'; c
= *fmt
++)
for (width
= 0; c
>= '0' && c
<= '9'; c
= *fmt
++)
width
= width
* 10 + c
- '0';
for (ells
= 0; c
== 'l'; c
= *fmt
++)
l
= (int64_t)va_arg(adx
, int);
l
= (int64_t)va_arg(adx
, int64_t);
l
= (int64_t)va_arg(adx
, int64_t);
ul
= (uint64_t)va_arg(adx
, uint32_t);
ul
= (uint64_t)va_arg(adx
, uint64_t);
ul
= (uint64_t)va_arg(adx
, uint64_t);
_printn(ul
, b
, width
, pad
, bp
);
for (i
= 24; i
>= 0; i
-= 8)
if ((c
= ((b
>> i
) & 0x7f)) != 0) {
while ((c
= *s
++) != 0) {
if (start
== localbuf
&& (*bp
- start
> 80)) {
if (start
== localbuf
&& (*bp
- start
> 80)) {
if (start
== localbuf
&& (*bp
- start
> 0))
* Printn prints a number n in base b.
* We don't use recursion to avoid deep kernel stacks.
_printn(uint64_t n
, int32_t b
, int32_t width
, int32_t pad
, char **bp
)
*cp
++ = "0123456789abcdef"[n
%b
];