]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/pe_kprintf.c
deb7faee2cfbc7b353fb63d4f8b3df3905b29748
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * i386 platform expert debugging output initialization.
35 #include <machine/machine_routines.h>
36 #include <pexpert/pexpert.h>
37 #include <kern/debug.h>
38 #include <kern/simple_lock.h>
41 /* extern references */
42 extern void cnputc(char c
);
43 extern int serial_init(void);
44 extern void serial_putc(char c
);
47 void (*PE_kputc
)(char c
) = 0;
49 unsigned int disableSerialOuput
= TRUE
;
51 decl_simple_lock_data(static, kprintf_lock
)
53 void PE_init_kprintf(boolean_t vm_initialized
)
55 unsigned int boot_arg
;
57 if (PE_state
.initialized
== FALSE
)
58 panic("Platform Expert not initialized");
62 simple_lock_init(&kprintf_lock
, 0);
64 if (PE_parse_boot_arg("debug", &boot_arg
))
65 if (boot_arg
& DB_KPRT
) disableSerialOuput
= FALSE
;
67 if (!disableSerialOuput
&& serial_init())
68 PE_kputc
= serial_putc
;
75 static void _kprintf(const char *format
, ...)
79 va_start(listp
, format
);
80 _doprnt(format
, &listp
, PE_kputc
, 16);
83 #define MP_DEBUG_KPRINTF(x...) _kprintf(x)
85 #define MP_DEBUG_KPRINTF(x...)
88 static int cpu_last_locked
= 0;
89 void kprintf(const char *fmt
, ...)
94 if (!disableSerialOuput
) {
97 * Spin to get kprintf lock but re-enable interrupts while failing.
98 * This allows interrupts to be handled while waiting but
99 * interrupts are disabled once we have the lock.
101 state
= ml_set_interrupts_enabled(FALSE
);
102 while (!simple_lock_try(&kprintf_lock
)) {
103 ml_set_interrupts_enabled(state
);
104 ml_set_interrupts_enabled(FALSE
);
107 if (cpu_number() != cpu_last_locked
) {
108 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
109 cpu_last_locked
= cpu_number();
112 va_start(listp
, fmt
);
113 _doprnt(fmt
, &listp
, PE_kputc
, 16);
116 simple_unlock(&kprintf_lock
);
117 ml_set_interrupts_enabled(state
);
121 extern void kprintf_break_lock(void);
123 kprintf_break_lock(void)
125 simple_lock_init(&kprintf_lock
, 0);