]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_kprintf.c
922291fa068deff07357a38e6778e9a5bec50fbc
[apple/xnu.git] / pexpert / ppc / pe_kprintf.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * file: pe_kprintf.c
30 * PPC platform expert debugging output initialization.
31 */
32 #include <stdarg.h>
33 #include <machine/machine_routines.h>
34 #include <pexpert/protos.h>
35 #include <pexpert/pexpert.h>
36 #include <pexpert/ppc/powermac.h>
37 #include <pexpert/device_tree.h>
38 #include <kern/debug.h>
39 #include <kern/simple_lock.h>
40 #include <vm/pmap.h>
41
42 /* extern references */
43 extern void init_display_putc(unsigned char*, int, int);
44 extern void display_putc(char c);
45 extern int scc_putc(int unit, int line, int c);
46 extern void cnputc(char c);
47
48 /* Internal routines -- eventually put this in serial driver */
49 void serial_putc(char c);
50
51 /* Globals */
52 void (*PE_kputc)(char c) = 0;
53
54 unsigned int disableSerialOuput = TRUE;
55
56 vm_offset_t scc = 0;
57
58 struct slock kprintf_lock;
59
60 void PE_init_kprintf(boolean_t vm_initialized)
61 {
62 unsigned int boot_arg;
63 int32_t cnt, size, serial_baud = -1;
64 DTEntry options;
65 char *str, baud[7];
66
67 if (PE_state.initialized == FALSE)
68 panic("Platform Expert not initialized");
69
70 if (PE_parse_boot_arg("debug", &boot_arg))
71 if(boot_arg & DB_KPRT) disableSerialOuput = FALSE;
72
73 if (DTLookupEntry(0, "/options", &options) == kSuccess) {
74 if (DTGetProperty(options, "input-device", &str, &size) == kSuccess) {
75 if ((size > 5) && !strncmp("scca:", str, 5)) {
76 size -= 5;
77 str += 5;
78 if (size <= 6) {
79 strncpy(baud, str, size);
80 baud[size] = '\0';
81 gPESerialBaud = strtol(baud, 0, 0);
82 }
83 }
84 }
85 if (DTGetProperty(options, "output-device", &str, &size) == kSuccess) {
86 if ((size > 5) && !strncmp("scca:", str, 5)) {
87 size -= 5;
88 str += 5;
89 if (size <= 6) {
90 strncpy(baud, str, size);
91 baud[size] = '\0';
92 gPESerialBaud = strtol(baud, 0, 0);
93 }
94 }
95 }
96 }
97
98 /* Check the boot-args for new serial baud. */
99 if (PE_parse_boot_arg("serialbaud", &serial_baud))
100 if (serial_baud != -1) gPESerialBaud = serial_baud;
101
102 if( (scc = PE_find_scc())) { /* See if we can find the serial port */
103 scc = io_map_spec(scc, 0x1000, VM_WIMG_IO); /* Map it in */
104 initialize_serial((void *)scc, gPESerialBaud); /* Start up the serial driver */
105 PE_kputc = serial_putc;
106
107 simple_lock_init(&kprintf_lock, 0);
108 } else
109 PE_kputc = cnputc;
110
111 #if 0
112 /*
113 * FUTURE: eventually let the boot command determine where
114 * the debug output will be, serial, video, etc.
115 */
116 switch (PE_state.debug_video.v_display) {
117 case kDebugTypeSerial:
118 PE_kputc = serial_putc;
119 break;
120
121 case kDebugTypeDisplay:
122 init_display_putc( (unsigned char*)PE_state.debug_video.v_baseAddr,
123 PE_state.debug_video.v_rowBytes,
124 PE_state.debug_video.v_height);
125 PE_kputc = display_putc;
126 break;
127
128 default:
129 PE_state.debug_video.v_baseAddr = 0;
130 }
131 #endif
132 }
133
134 void serial_putc(char c)
135 {
136 (void) scc_putc(0, 1, c);
137 if (c == '\n') (void) scc_putc(0, 1, '\r');
138
139 #if 0
140 (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, c);
141 if (c == '\n') (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, '\r');
142 #endif
143 }
144
145 void kprintf(const char *fmt, ...)
146 {
147 va_list listp;
148 boolean_t state;
149
150 state = ml_set_interrupts_enabled(FALSE);
151 simple_lock(&kprintf_lock);
152
153 if (!disableSerialOuput) {
154 va_start(listp, fmt);
155 _doprnt(fmt, &listp, PE_kputc, 16);
156 va_end(listp);
157 }
158
159 simple_unlock(&kprintf_lock);
160 ml_set_interrupts_enabled(state);
161 }
162