]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 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. 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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * file: pe_kprintf.c | |
30 | * i386 platform expert debugging output initialization. | |
31 | */ | |
32 | #include <stdarg.h> | |
55e303ae | 33 | #include <machine/machine_routines.h> |
1c79356b A |
34 | #include <pexpert/pexpert.h> |
35 | #include <kern/debug.h> | |
55e303ae A |
36 | #include <kern/simple_lock.h> |
37 | #include <i386/mp.h> | |
1c79356b | 38 | |
1c79356b | 39 | /* Globals */ |
2d21ac55 | 40 | void (*PE_kputc)(char c); |
1c79356b | 41 | |
b0d623f7 A |
42 | #if DEBUG |
43 | /* DEBUG kernel starts with true serial, but | |
44 | * may later disable or switch to video | |
45 | * console */ | |
46 | unsigned int disable_serial_output = FALSE; | |
47 | #else | |
2d21ac55 | 48 | unsigned int disable_serial_output = TRUE; |
b0d623f7 | 49 | #endif |
1c79356b | 50 | |
55e303ae A |
51 | decl_simple_lock_data(static, kprintf_lock) |
52 | ||
1c79356b A |
53 | void PE_init_kprintf(boolean_t vm_initialized) |
54 | { | |
55 | unsigned int boot_arg; | |
56 | ||
57 | if (PE_state.initialized == FALSE) | |
58 | panic("Platform Expert not initialized"); | |
59 | ||
2d21ac55 | 60 | if (!vm_initialized) { |
b0d623f7 A |
61 | unsigned int new_disable_serial_output = TRUE; |
62 | ||
2d21ac55 | 63 | simple_lock_init(&kprintf_lock, 0); |
55e303ae | 64 | |
593a1d5f | 65 | if (PE_parse_boot_argn("debug", &boot_arg, sizeof (boot_arg))) |
2d21ac55 | 66 | if (boot_arg & DB_KPRT) |
b0d623f7 | 67 | new_disable_serial_output = FALSE; |
55e303ae | 68 | |
b0d623f7 A |
69 | /* If we are newly enabling serial, make sure we only call serial_init() |
70 | * if our previous state was not enabled */ | |
71 | if (!new_disable_serial_output && (!disable_serial_output || serial_init())) | |
2d21ac55 A |
72 | PE_kputc = serial_putc; |
73 | else | |
74 | PE_kputc = cnputc; | |
b0d623f7 A |
75 | |
76 | disable_serial_output = new_disable_serial_output; | |
2d21ac55 | 77 | } |
1c79356b A |
78 | } |
79 | ||
b0d623f7 A |
80 | #if CONFIG_NO_KPRINTF_STRINGS |
81 | /* Prevent CPP from breaking the definition below */ | |
82 | #undef kprintf | |
83 | #endif | |
84 | ||
55e303ae A |
85 | #ifdef MP_DEBUG |
86 | static void _kprintf(const char *format, ...) | |
87 | { | |
88 | va_list listp; | |
89 | ||
90 | va_start(listp, format); | |
91 | _doprnt(format, &listp, PE_kputc, 16); | |
92 | va_end(listp); | |
93 | } | |
94 | #define MP_DEBUG_KPRINTF(x...) _kprintf(x) | |
95 | #else /* MP_DEBUG */ | |
96 | #define MP_DEBUG_KPRINTF(x...) | |
97 | #endif /* MP_DEBUG */ | |
98 | ||
99 | static int cpu_last_locked = 0; | |
1c79356b A |
100 | void kprintf(const char *fmt, ...) |
101 | { | |
55e303ae | 102 | va_list listp; |
2d21ac55 A |
103 | boolean_t state; |
104 | ||
105 | if (!disable_serial_output) { | |
106 | ||
b0d623f7 A |
107 | /* If PE_kputc has not yet been initialized, don't |
108 | * take any locks, just dump to serial */ | |
109 | if (!PE_kputc) { | |
110 | va_start(listp, fmt); | |
111 | _doprnt(fmt, &listp, serial_putc, 16); | |
112 | va_end(listp); | |
113 | return; | |
114 | } | |
115 | ||
2d21ac55 A |
116 | /* |
117 | * Spin to get kprintf lock but re-enable interrupts while | |
118 | * failing. | |
119 | * This allows interrupts to be handled while waiting but | |
120 | * interrupts are disabled once we have the lock. | |
121 | */ | |
122 | state = ml_set_interrupts_enabled(FALSE); | |
123 | while (!simple_lock_try(&kprintf_lock)) { | |
124 | ml_set_interrupts_enabled(state); | |
125 | ml_set_interrupts_enabled(FALSE); | |
126 | } | |
127 | ||
128 | if (cpu_number() != cpu_last_locked) { | |
129 | MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number()); | |
130 | cpu_last_locked = cpu_number(); | |
131 | } | |
132 | ||
133 | va_start(listp, fmt); | |
134 | _doprnt(fmt, &listp, PE_kputc, 16); | |
135 | va_end(listp); | |
136 | ||
137 | simple_unlock(&kprintf_lock); | |
138 | ml_set_interrupts_enabled(state); | |
55e303ae | 139 | } |
1c79356b | 140 | } |
0c530ab8 A |
141 | |
142 | extern void kprintf_break_lock(void); | |
143 | void | |
144 | kprintf_break_lock(void) | |
145 | { | |
146 | simple_lock_init(&kprintf_lock, 0); | |
147 | } |