1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <sys/types.h>
28 #include <sys/cmn_err.h>
29 #include <sys/varargs.h>
30 #include <sys/bootconf.h>
31 #include <sys/sysmacros.h>
32 #include <sys/kmdb.h>
33 
34 /*
35  * The boot printing interfaces don't expose anything that'll allow us
36  * to print multiple arguments at once.  That is, they expose printf-like
37  * interfaces, but these interfaces only support one format specifier per
38  * invocation.  The routines in this file allow the rest of the driver
39  * to pretend that this limitation doesn't exist.
40  */
41 
42 #include <kmdb/kctl/kctl.h>
43 
44 static void
kctl_vprintf(int code,const char * format,va_list ap)45 kctl_vprintf(int code, const char *format, va_list ap)
46 {
47 	if (kctl.kctl_boot_ops == NULL) {
48 		vcmn_err(code, format, ap);
49 
50 	} else {
51 		char buf[128];
52 
53 		if (code == CE_WARN)
54 			BOP_PUTSARG(kctl.kctl_boot_ops, "WARNING: ", NULL);
55 		else if (code == CE_NOTE)
56 			BOP_PUTSARG(kctl.kctl_boot_ops, "NOTE: ", NULL);
57 
58 		(void) vsnprintf(buf, sizeof (buf), format, ap);
59 		BOP_PUTSARG(kctl.kctl_boot_ops, "%s\n", buf);
60 	}
61 }
62 
63 void
kctl_warn(const char * format,...)64 kctl_warn(const char *format, ...)
65 {
66 	va_list ap;
67 
68 	va_start(ap, format);
69 	kctl_vprintf(CE_WARN, format, ap);
70 	va_end(ap);
71 }
72 
73 void
kctl_dprintf(const char * format,...)74 kctl_dprintf(const char *format, ...)
75 {
76 	va_list ap;
77 
78 	if (!(kctl.kctl_flags & KMDB_F_DRV_DEBUG))
79 		return;
80 
81 	va_start(ap, format);
82 	kctl_vprintf(CE_NOTE, format, ap);
83 	va_end(ap);
84 }
85