]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_kprintf.c
7ac0570ffa2d7f3175460fcf4ef67bad9b168cd7
[apple/xnu.git] / pexpert / ppc / pe_kprintf.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * file: pe_kprintf.c
32 * PPC platform expert debugging output initialization.
33 */
34 #include <stdarg.h>
35 #include <machine/machine_routines.h>
36 #include <pexpert/protos.h>
37 #include <pexpert/pexpert.h>
38 #include <pexpert/ppc/powermac.h>
39 #include <pexpert/device_tree.h>
40 #include <kern/debug.h>
41 #include <kern/simple_lock.h>
42
43 /* extern references */
44 extern void init_display_putc(unsigned char*, int, int);
45 extern void display_putc(char c);
46 extern int scc_putc(int unit, int line, int c);
47 extern void cnputc(char c);
48
49 /* Internal routines -- eventually put this in serial driver */
50 void serial_putc(char c);
51
52 /* Globals */
53 void (*PE_kputc)(char c) = 0;
54
55 unsigned int disableSerialOuput = TRUE;
56
57 vm_offset_t scc = 0;
58
59 struct slock kprintf_lock;
60
61 void PE_init_kprintf(boolean_t vm_initialized)
62 {
63 unsigned int boot_arg;
64 int32_t cnt, size, serial_baud = -1;
65 DTEntry options;
66 char *str, baud[7];
67
68 if (PE_state.initialized == FALSE)
69 panic("Platform Expert not initialized");
70
71 if (PE_parse_boot_arg("debug", &boot_arg))
72 if(boot_arg & DB_KPRT) disableSerialOuput = FALSE;
73
74 if (DTLookupEntry(0, "/options", &options) == kSuccess) {
75 if (DTGetProperty(options, "input-device", &str, &size) == kSuccess) {
76 if ((size > 5) && !strncmp("scca:", str, 5)) {
77 size -= 5;
78 str += 5;
79 if (size <= 6) {
80 strncpy(baud, str, size);
81 baud[size] = '\0';
82 gPESerialBaud = strtol(baud, 0, 0);
83 }
84 }
85 }
86 if (DTGetProperty(options, "output-device", &str, &size) == kSuccess) {
87 if ((size > 5) && !strncmp("scca:", str, 5)) {
88 size -= 5;
89 str += 5;
90 if (size <= 6) {
91 strncpy(baud, str, size);
92 baud[size] = '\0';
93 gPESerialBaud = strtol(baud, 0, 0);
94 }
95 }
96 }
97 }
98
99 /* Check the boot-args for new serial baud. */
100 if (PE_parse_boot_arg("serialbaud", &serial_baud))
101 if (serial_baud != -1) gPESerialBaud = serial_baud;
102
103 if( (scc = PE_find_scc())) { /* See if we can find the serial port */
104 scc = io_map_spec(scc, 0x1000); /* Map it in */
105 initialize_serial((void *)scc, gPESerialBaud); /* Start up the serial driver */
106 PE_kputc = serial_putc;
107
108 simple_lock_init(&kprintf_lock, 0);
109 } else
110 PE_kputc = cnputc;
111
112 #if 0
113 /*
114 * FUTURE: eventually let the boot command determine where
115 * the debug output will be, serial, video, etc.
116 */
117 switch (PE_state.debug_video.v_display) {
118 case kDebugTypeSerial:
119 PE_kputc = serial_putc;
120 break;
121
122 case kDebugTypeDisplay:
123 init_display_putc( (unsigned char*)PE_state.debug_video.v_baseAddr,
124 PE_state.debug_video.v_rowBytes,
125 PE_state.debug_video.v_height);
126 PE_kputc = display_putc;
127 break;
128
129 default:
130 PE_state.debug_video.v_baseAddr = 0;
131 }
132 #endif
133 }
134
135 void serial_putc(char c)
136 {
137 (void) scc_putc(0, 1, c);
138 if (c == '\n') (void) scc_putc(0, 1, '\r');
139
140 #if 0
141 (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, c);
142 if (c == '\n') (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, '\r');
143 #endif
144 }
145
146 void kprintf(const char *fmt, ...)
147 {
148 va_list listp;
149 boolean_t state;
150
151 state = ml_set_interrupts_enabled(FALSE);
152 simple_lock(&kprintf_lock);
153
154 if (!disableSerialOuput) {
155 va_start(listp, fmt);
156 _doprnt(fmt, &listp, PE_kputc, 16);
157 va_end(listp);
158 }
159
160 simple_unlock(&kprintf_lock);
161 ml_set_interrupts_enabled(state);
162 }
163