4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2012 Gary Mills
25 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/machparam.h>
32 #include <sys/archsystm.h>
33 #include <sys/boot_console.h>
34 #include <sys/varargs.h>
35 #include "dboot_asm.h"
36 #include "dboot_printf.h"
37 #include "dboot_xboot.h"
40 #include <sys/hypervisor.h>
44 * This file provides simple output formatting via dboot_printf()
47 static void do_dboot_printf(char *fmt
, va_list args
);
49 static char digits
[] = "0123456789abcdef";
52 * Primitive version of panic, prints a message then resets the system
55 dboot_panic(char *fmt
, ...)
60 do_dboot_printf(fmt
, args
);
62 if (boot_console_type(NULL
) == CONS_SCREEN_TEXT
) {
63 dboot_printf("Press any key to reboot\n");
64 (void) bcons_getchar();
66 outb(0x64, 0xfe); /* this resets the system, see pc_reset() */
67 dboot_halt(); /* just in case */
71 * printf for boot code
74 dboot_printf(char *fmt
, ...)
79 do_dboot_printf(fmt
, args
);
96 dboot_putnum(uint64_t x
, uint_t is_signed
, uint8_t base
)
98 char buffer
[64]; /* digits in reverse order */
101 if (is_signed
&& (int64_t)x
< 0) {
106 for (i
= -1; x
!= 0 && i
<= 63; x
/= base
)
107 buffer
[++i
] = digits
[x
- ((x
/ base
) * base
)];
113 bcons_putchar(buffer
[i
--]);
117 * very primitive printf - only does %s, %d, %x, %lx, or %%
120 do_dboot_printf(char *fmt
, va_list args
)
126 uint_t is_signed
= 1;
129 dboot_puts("dboot_printf(): 1st arg is NULL\n");
132 for (; *fmt
; ++fmt
) {
148 x
= va_arg(args
, int);
153 s
= va_arg(args
, char *);
155 dboot_puts("*NULL*");
161 x
= va_arg(args
, ulong_t
);
162 dboot_putnum(x
, !is_signed
, 16);
167 size
= sizeof (long);
168 else if (size
== sizeof (long))
169 size
= sizeof (long long);
174 x
= va_arg(args
, int);
175 else if (size
== sizeof (long))
176 x
= va_arg(args
, long);
178 x
= va_arg(args
, long long);
179 dboot_putnum(x
, is_signed
, 10);
194 x
= va_arg(args
, uint_t
);
195 else if (size
== sizeof (long))
196 x
= va_arg(args
, ulong_t
);
198 x
= va_arg(args
, unsigned long long);
199 dboot_putnum(x
, !is_signed
, base
);
203 dboot_puts("dboot_printf(): unknown % escape\n");