]> git.saurik.com Git - apple/xnu.git/blame - pexpert/i386/pe_kprintf.c
xnu-792.6.56.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 *
ff6e181a
A
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
1c79356b 12 *
ff6e181a
A
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * file: pe_kprintf.c
25 * i386 platform expert debugging output initialization.
26 */
27#include <stdarg.h>
55e303ae 28#include <machine/machine_routines.h>
1c79356b
A
29#include <pexpert/pexpert.h>
30#include <kern/debug.h>
55e303ae
A
31#include <kern/simple_lock.h>
32#include <i386/mp.h>
1c79356b
A
33
34/* extern references */
35extern void cnputc(char c);
55e303ae
A
36extern int serial_init(void);
37extern void serial_putc(char c);
1c79356b
A
38
39/* Globals */
40void (*PE_kputc)(char c) = 0;
41
42unsigned int disableSerialOuput = TRUE;
43
55e303ae
A
44decl_simple_lock_data(static, kprintf_lock)
45
1c79356b
A
46void PE_init_kprintf(boolean_t vm_initialized)
47{
48 unsigned int boot_arg;
49
50 if (PE_state.initialized == FALSE)
51 panic("Platform Expert not initialized");
52
53 if (!vm_initialized)
54 {
55e303ae
A
55 simple_lock_init(&kprintf_lock, 0);
56
1c79356b
A
57 if (PE_parse_boot_arg("debug", &boot_arg))
58 if (boot_arg & DB_KPRT) disableSerialOuput = FALSE;
55e303ae
A
59
60 if (!disableSerialOuput && serial_init())
61 PE_kputc = serial_putc;
62 else
63 PE_kputc = cnputc;
1c79356b
A
64 }
65}
66
55e303ae
A
67#ifdef MP_DEBUG
68static void _kprintf(const char *format, ...)
69{
70 va_list listp;
71
72 va_start(listp, format);
73 _doprnt(format, &listp, PE_kputc, 16);
74 va_end(listp);
75}
76#define MP_DEBUG_KPRINTF(x...) _kprintf(x)
77#else /* MP_DEBUG */
78#define MP_DEBUG_KPRINTF(x...)
79#endif /* MP_DEBUG */
80
81static int cpu_last_locked = 0;
1c79356b
A
82void kprintf(const char *fmt, ...)
83{
55e303ae
A
84 va_list listp;
85 boolean_t state;
1c79356b
A
86
87 if (!disableSerialOuput) {
91447636
A
88
89 /*
90 * Spin to get kprintf lock but re-enable interrupts while failing.
91 * This allows interrupts to be handled while waiting but
92 * interrupts are disabled once we have the lock.
93 */
94 state = ml_set_interrupts_enabled(FALSE);
95 while (!simple_lock_try(&kprintf_lock)) {
96 ml_set_interrupts_enabled(state);
97 ml_set_interrupts_enabled(FALSE);
98 }
55e303ae
A
99
100 if (cpu_number() != cpu_last_locked) {
101 MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
102 cpu_last_locked = cpu_number();
103 }
104
1c79356b
A
105 va_start(listp, fmt);
106 _doprnt(fmt, &listp, PE_kputc, 16);
107 va_end(listp);
55e303ae
A
108
109 simple_unlock(&kprintf_lock);
110 ml_set_interrupts_enabled(state);
1c79356b
A
111 }
112}