]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * file: pe_kprintf.c | |
27 | * i386 platform expert debugging output initialization. | |
28 | */ | |
29 | #include <stdarg.h> | |
55e303ae | 30 | #include <machine/machine_routines.h> |
1c79356b A |
31 | #include <pexpert/pexpert.h> |
32 | #include <kern/debug.h> | |
55e303ae A |
33 | #include <kern/simple_lock.h> |
34 | #include <i386/mp.h> | |
1c79356b A |
35 | |
36 | /* extern references */ | |
37 | extern void cnputc(char c); | |
55e303ae A |
38 | extern int serial_init(void); |
39 | extern void serial_putc(char c); | |
1c79356b A |
40 | |
41 | /* Globals */ | |
42 | void (*PE_kputc)(char c) = 0; | |
43 | ||
44 | unsigned int disableSerialOuput = TRUE; | |
45 | ||
55e303ae A |
46 | decl_simple_lock_data(static, kprintf_lock) |
47 | ||
1c79356b A |
48 | void PE_init_kprintf(boolean_t vm_initialized) |
49 | { | |
50 | unsigned int boot_arg; | |
51 | ||
52 | if (PE_state.initialized == FALSE) | |
53 | panic("Platform Expert not initialized"); | |
54 | ||
55 | if (!vm_initialized) | |
56 | { | |
55e303ae A |
57 | simple_lock_init(&kprintf_lock, 0); |
58 | ||
1c79356b A |
59 | if (PE_parse_boot_arg("debug", &boot_arg)) |
60 | if (boot_arg & DB_KPRT) disableSerialOuput = FALSE; | |
55e303ae A |
61 | |
62 | if (!disableSerialOuput && serial_init()) | |
63 | PE_kputc = serial_putc; | |
64 | else | |
65 | PE_kputc = cnputc; | |
1c79356b A |
66 | } |
67 | } | |
68 | ||
55e303ae A |
69 | #ifdef MP_DEBUG |
70 | static void _kprintf(const char *format, ...) | |
71 | { | |
72 | va_list listp; | |
73 | ||
74 | va_start(listp, format); | |
75 | _doprnt(format, &listp, PE_kputc, 16); | |
76 | va_end(listp); | |
77 | } | |
78 | #define MP_DEBUG_KPRINTF(x...) _kprintf(x) | |
79 | #else /* MP_DEBUG */ | |
80 | #define MP_DEBUG_KPRINTF(x...) | |
81 | #endif /* MP_DEBUG */ | |
82 | ||
83 | static int cpu_last_locked = 0; | |
1c79356b A |
84 | void kprintf(const char *fmt, ...) |
85 | { | |
55e303ae A |
86 | va_list listp; |
87 | boolean_t state; | |
1c79356b A |
88 | |
89 | if (!disableSerialOuput) { | |
55e303ae A |
90 | state = ml_set_interrupts_enabled(FALSE); |
91 | simple_lock(&kprintf_lock); | |
92 | ||
93 | if (cpu_number() != cpu_last_locked) { | |
94 | MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number()); | |
95 | cpu_last_locked = cpu_number(); | |
96 | } | |
97 | ||
1c79356b A |
98 | va_start(listp, fmt); |
99 | _doprnt(fmt, &listp, PE_kputc, 16); | |
100 | va_end(listp); | |
55e303ae A |
101 | |
102 | simple_unlock(&kprintf_lock); | |
103 | ml_set_interrupts_enabled(state); | |
1c79356b A |
104 | } |
105 | } |