]> git.saurik.com Git - apple/xnu.git/blame_incremental - pexpert/i386/pe_kprintf.c
xnu-517.tar.gz
[apple/xnu.git] / pexpert / i386 / pe_kprintf.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * file: pe_kprintf.c
27 * i386 platform expert debugging output initialization.
28 */
29#include <stdarg.h>
30#include <machine/machine_routines.h>
31#include <pexpert/pexpert.h>
32#include <kern/debug.h>
33#include <kern/simple_lock.h>
34#include <i386/mp.h>
35
36/* extern references */
37extern void cnputc(char c);
38extern int serial_init(void);
39extern void serial_putc(char c);
40
41/* Globals */
42void (*PE_kputc)(char c) = 0;
43
44unsigned int disableSerialOuput = TRUE;
45
46decl_simple_lock_data(static, kprintf_lock)
47
48void PE_init_kprintf(boolean_t vm_initialized)
49{
50 unsigned int boot_arg;
51
52 if (PE_state.initialized == FALSE)
53 panic("Platform Expert not initialized");
54
55 if (!vm_initialized)
56 {
57 simple_lock_init(&kprintf_lock, 0);
58
59 if (PE_parse_boot_arg("debug", &boot_arg))
60 if (boot_arg & DB_KPRT) disableSerialOuput = FALSE;
61
62 if (!disableSerialOuput && serial_init())
63 PE_kputc = serial_putc;
64 else
65 PE_kputc = cnputc;
66 }
67}
68
69#ifdef MP_DEBUG
70static void _kprintf(const char *format, ...)
71{
72 va_list listp;
73
74 va_start(listp, format);
75 _doprnt(format, &listp, PE_kputc, 16);
76 va_end(listp);
77}
78#define MP_DEBUG_KPRINTF(x...) _kprintf(x)
79#else /* MP_DEBUG */
80#define MP_DEBUG_KPRINTF(x...)
81#endif /* MP_DEBUG */
82
83static int cpu_last_locked = 0;
84void kprintf(const char *fmt, ...)
85{
86 va_list listp;
87 boolean_t state;
88
89 if (!disableSerialOuput) {
90 state = ml_set_interrupts_enabled(FALSE);
91 simple_lock(&kprintf_lock);
92
93 if (cpu_number() != cpu_last_locked) {
94 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
95 cpu_last_locked = cpu_number();
96 }
97
98 va_start(listp, fmt);
99 _doprnt(fmt, &listp, PE_kputc, 16);
100 va_end(listp);
101
102 simple_unlock(&kprintf_lock);
103 ml_set_interrupts_enabled(state);
104 }
105}