Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Partially expose some of the kernel printf internals in ...
details: https://anonhg.NetBSD.org/src/rev/b6050e6da428
branches: trunk
changeset: 541041:b6050e6da428
user: thorpej <thorpej%NetBSD.org@localhost>
date: Tue Dec 31 16:53:26 2002 +0000
description:
Partially expose some of the kernel printf internals in the new
<sys/kprintf.h> header file. This allows subsystems that need
printf semantics other than what are provided by the standard
kernel printf routines to implement exactly what they want.
diffstat:
sys/kern/subr_prf.c | 39 ++-------------------
sys/sys/kprintf.h | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+), 34 deletions(-)
diffs (193 lines):
diff -r 47cf5fdf3df0 -r b6050e6da428 sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c Tue Dec 31 16:45:52 2002 +0000
+++ b/sys/kern/subr_prf.c Tue Dec 31 16:53:26 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prf.c,v 1.86 2002/11/02 07:25:22 perry Exp $ */
+/* $NetBSD: subr_prf.c,v 1.87 2002/12/31 16:53:27 thorpej Exp $ */
/*-
* Copyright (c) 1986, 1988, 1991, 1993
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.86 2002/11/02 07:25:22 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.87 2002/12/31 16:53:27 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_ipkdb.h"
@@ -63,6 +63,7 @@
#include <sys/syslog.h>
#include <sys/malloc.h>
#include <sys/lock.h>
+#include <sys/kprintf.h>
#include <dev/cons.h>
@@ -79,26 +80,6 @@
#if defined(MULTIPROCESSOR)
struct simplelock kprintf_slock = SIMPLELOCK_INITIALIZER;
-
-/*
- * Use cpu_simple_lock() and cpu_simple_unlock(). These are the actual
- * atomic locking operations, and never attempt to print debugging
- * information.
- */
-#define KPRINTF_MUTEX_ENTER(s) \
-do { \
- (s) = splhigh(); \
- __cpu_simple_lock(&kprintf_slock.lock_data); \
-} while (/*CONSTCOND*/ 0)
-
-#define KPRINTF_MUTEX_EXIT(s) \
-do { \
- __cpu_simple_unlock(&kprintf_slock.lock_data); \
- splx((s)); \
-} while (/*CONSTCOND*/ 0)
-#else /* ! MULTIPROCESSOR */
-#define KPRINTF_MUTEX_ENTER(s) (s) = splhigh()
-#define KPRINTF_MUTEX_EXIT(s) splx((s))
#endif /* MULTIPROCESSOR */
/*
@@ -122,13 +103,6 @@
* defines
*/
-/* flags for kprintf */
-#define TOCONS 0x01 /* to the console */
-#define TOTTY 0x02 /* to the process' tty */
-#define TOLOG 0x04 /* to the kernel message buffer */
-#define TOBUFONLY 0x08 /* to the buffer (only) [for snprintf] */
-#define TODDB 0x10 /* to ddb console */
-
/* max size buffer kprintf needs to print quad_t [size in base 8 + \0] */
#define KPRINTF_BUFSIZE (sizeof(quad_t) * NBBY / 3 + 2)
@@ -137,10 +111,7 @@
* local prototypes
*/
-static int kprintf __P((const char *, int, void *,
- char *, va_list));
static void putchar __P((int, int, struct tty *));
-static void klogpri __P((int));
/*
@@ -336,7 +307,7 @@
/*
* Note: we must be in the mutex here!
*/
-static void
+void
klogpri(level)
int level;
{
@@ -960,7 +931,7 @@
/*
* Guts of kernel printf. Note, we already expect to be in a mutex!
*/
-static int
+int
kprintf(fmt0, oflags, vp, sbuf, ap)
const char *fmt0;
int oflags;
diff -r 47cf5fdf3df0 -r b6050e6da428 sys/sys/kprintf.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/sys/kprintf.h Tue Dec 31 16:53:26 2002 +0000
@@ -0,0 +1,93 @@
+/* $NetBSD: kprintf.h,v 1.1 2002/12/31 16:53:26 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1986, 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS_KPRINTF_H_
+#define _SYS_KPRINTF_H_
+
+#include <sys/lock.h>
+
+/*
+ * Implementation internals of the kernel printf. Exposing them here
+ * allows other subsystems to implement precisely the printf semantics
+ * they need.
+ */
+
+#if defined(MULTIPROCESSOR)
+
+extern struct simplelock kprintf_slock;
+
+/*
+ * Use cpu_simple_lock() and cpu_simple_unlock(). These are the actual
+ * atomic locking operations, and never attempt to print debugging
+ * information.
+ */
+#define KPRINTF_MUTEX_ENTER(s) \
+do { \
+ (s) = splhigh(); \
+ __cpu_simple_lock(&kprintf_slock.lock_data); \
+} while (/*CONSTCOND*/0)
+
+#define KPRINTF_MUTEX_EXIT(s) \
+do { \
+ __cpu_simple_unlock(&kprintf_slock.lock_data); \
+ splx((s)); \
+} while (/*CONSTCOND*/0)
+
+#else
+
+#define KPRINTF_MUTEX_ENTER(s) (s) = splhigh()
+#define KPRINTF_MUTEX_EXIT(s) splx((s))
+
+#endif /* MULTIPROCESSOR */
+
+/* flags for kprintf */
+#define TOCONS 0x01 /* to the console */
+#define TOTTY 0x02 /* to the process' tty */
+#define TOLOG 0x04 /* to the kernel message buffer */
+#define TOBUFONLY 0x08 /* to the buffer (only) [for snprintf] */
+#define TODDB 0x10 /* to ddb console */
+
+/*
+ * NOTE: the kprintf mutex must be held when these functions are called!
+ */
+int kprintf __P((const char *, int, void *, char *, _BSD_VA_LIST_));
+void klogpri __P((int));
+
+#endif /* _SYS_KPRINTF_H_ */
Home |
Main Index |
Thread Index |
Old Index