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