]>
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_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * i386 platform expert debugging output initialization.
27 #include <machine/machine_routines.h>
28 #include <pexpert/pexpert.h>
29 #include <kern/debug.h>
30 #include <kern/simple_lock.h>
33 /* extern references */
34 extern void cnputc(char c
);
35 extern int serial_init(void);
36 extern void serial_putc(char c
);
39 void (*PE_kputc
)(char c
) = 0;
41 unsigned int disableSerialOuput
= TRUE
;
43 decl_simple_lock_data(static, kprintf_lock
)
45 void PE_init_kprintf(boolean_t vm_initialized
)
47 unsigned int boot_arg
;
49 if (PE_state
.initialized
== FALSE
)
50 panic("Platform Expert not initialized");
54 simple_lock_init(&kprintf_lock
, 0);
56 if (PE_parse_boot_arg("debug", &boot_arg
))
57 if (boot_arg
& DB_KPRT
) disableSerialOuput
= FALSE
;
59 if (!disableSerialOuput
&& serial_init())
60 PE_kputc
= serial_putc
;
67 static void _kprintf(const char *format
, ...)
71 va_start(listp
, format
);
72 _doprnt(format
, &listp
, PE_kputc
, 16);
75 #define MP_DEBUG_KPRINTF(x...) _kprintf(x)
77 #define MP_DEBUG_KPRINTF(x...)
80 static int cpu_last_locked
= 0;
81 void kprintf(const char *fmt
, ...)
86 if (!disableSerialOuput
) {
89 * Spin to get kprintf lock but re-enable interrupts while failing.
90 * This allows interrupts to be handled while waiting but
91 * interrupts are disabled once we have the lock.
93 state
= ml_set_interrupts_enabled(FALSE
);
94 while (!simple_lock_try(&kprintf_lock
)) {
95 ml_set_interrupts_enabled(state
);
96 ml_set_interrupts_enabled(FALSE
);
99 if (cpu_number() != cpu_last_locked
) {
100 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
101 cpu_last_locked
= cpu_number();
104 va_start(listp
, fmt
);
105 _doprnt(fmt
, &listp
, PE_kputc
, 16);
108 simple_unlock(&kprintf_lock
);
109 ml_set_interrupts_enabled(state
);