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