]> git.saurik.com Git - apple/xnu.git/blame - pexpert/i386/pe_kprintf.c
xnu-792.6.22.tar.gz
[apple/xnu.git] / pexpert / i386 / pe_kprintf.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
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.
1c79356b 11 *
e5568f75
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * file: pe_kprintf.c
24 * i386 platform expert debugging output initialization.
25 */
26#include <stdarg.h>
55e303ae 27#include <machine/machine_routines.h>
1c79356b
A
28#include <pexpert/pexpert.h>
29#include <kern/debug.h>
55e303ae
A
30#include <kern/simple_lock.h>
31#include <i386/mp.h>
1c79356b
A
32
33/* extern references */
34extern void cnputc(char c);
55e303ae
A
35extern int serial_init(void);
36extern void serial_putc(char c);
1c79356b
A
37
38/* Globals */
39void (*PE_kputc)(char c) = 0;
40
41unsigned int disableSerialOuput = TRUE;
42
55e303ae
A
43decl_simple_lock_data(static, kprintf_lock)
44
1c79356b
A
45void PE_init_kprintf(boolean_t vm_initialized)
46{
47 unsigned int boot_arg;
48
49 if (PE_state.initialized == FALSE)
50 panic("Platform Expert not initialized");
51
52 if (!vm_initialized)
53 {
55e303ae
A
54 simple_lock_init(&kprintf_lock, 0);
55
1c79356b
A
56 if (PE_parse_boot_arg("debug", &boot_arg))
57 if (boot_arg & DB_KPRT) disableSerialOuput = FALSE;
55e303ae
A
58
59 if (!disableSerialOuput && serial_init())
60 PE_kputc = serial_putc;
61 else
62 PE_kputc = cnputc;
1c79356b
A
63 }
64}
65
55e303ae
A
66#ifdef MP_DEBUG
67static void _kprintf(const char *format, ...)
68{
69 va_list listp;
70
71 va_start(listp, format);
72 _doprnt(format, &listp, PE_kputc, 16);
73 va_end(listp);
74}
75#define MP_DEBUG_KPRINTF(x...) _kprintf(x)
76#else /* MP_DEBUG */
77#define MP_DEBUG_KPRINTF(x...)
78#endif /* MP_DEBUG */
79
80static int cpu_last_locked = 0;
1c79356b
A
81void kprintf(const char *fmt, ...)
82{
55e303ae
A
83 va_list listp;
84 boolean_t state;
1c79356b
A
85
86 if (!disableSerialOuput) {
91447636
A
87
88 /*
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.
92 */
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);
97 }
55e303ae
A
98
99 if (cpu_number() != cpu_last_locked) {
100 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
101 cpu_last_locked = cpu_number();
102 }
103
1c79356b
A
104 va_start(listp, fmt);
105 _doprnt(fmt, &listp, PE_kputc, 16);
106 va_end(listp);
55e303ae
A
107
108 simple_unlock(&kprintf_lock);
109 ml_set_interrupts_enabled(state);
1c79356b
A
110 }
111}