]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/pe_kprintf.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * i386 platform expert debugging output initialization.
33 #include <machine/machine_routines.h>
34 #include <pexpert/pexpert.h>
35 #include <kern/debug.h>
36 #include <kern/simple_lock.h>
39 /* extern references */
40 extern void cnputc(char c
);
41 extern int serial_init(void);
42 extern void serial_putc(char c
);
45 void (*PE_kputc
)(char c
) = 0;
47 unsigned int disableSerialOuput
= TRUE
;
49 decl_simple_lock_data(static, kprintf_lock
)
51 void PE_init_kprintf(boolean_t vm_initialized
)
53 unsigned int boot_arg
;
55 if (PE_state
.initialized
== FALSE
)
56 panic("Platform Expert not initialized");
60 simple_lock_init(&kprintf_lock
, 0);
62 if (PE_parse_boot_arg("debug", &boot_arg
))
63 if (boot_arg
& DB_KPRT
) disableSerialOuput
= FALSE
;
65 if (!disableSerialOuput
&& serial_init())
66 PE_kputc
= serial_putc
;
73 static void _kprintf(const char *format
, ...)
77 va_start(listp
, format
);
78 _doprnt(format
, &listp
, PE_kputc
, 16);
81 #define MP_DEBUG_KPRINTF(x...) _kprintf(x)
83 #define MP_DEBUG_KPRINTF(x...)
86 static int cpu_last_locked
= 0;
87 void kprintf(const char *fmt
, ...)
92 if (!disableSerialOuput
) {
95 * Spin to get kprintf lock but re-enable interrupts while failing.
96 * This allows interrupts to be handled while waiting but
97 * interrupts are disabled once we have the lock.
99 state
= ml_set_interrupts_enabled(FALSE
);
100 while (!simple_lock_try(&kprintf_lock
)) {
101 ml_set_interrupts_enabled(state
);
102 ml_set_interrupts_enabled(FALSE
);
105 if (cpu_number() != cpu_last_locked
) {
106 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
107 cpu_last_locked
= cpu_number();
110 va_start(listp
, fmt
);
111 _doprnt(fmt
, &listp
, PE_kputc
, 16);
114 simple_unlock(&kprintf_lock
);
115 ml_set_interrupts_enabled(state
);