]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_kprintf.c
7ac0570ffa2d7f3175460fcf4ef67bad9b168cd7
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * PPC platform expert debugging output initialization.
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>
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
);
49 /* Internal routines -- eventually put this in serial driver */
50 void serial_putc(char c
);
53 void (*PE_kputc
)(char c
) = 0;
55 unsigned int disableSerialOuput
= TRUE
;
59 struct slock kprintf_lock
;
61 void PE_init_kprintf(boolean_t vm_initialized
)
63 unsigned int boot_arg
;
64 int32_t cnt
, size
, serial_baud
= -1;
68 if (PE_state
.initialized
== FALSE
)
69 panic("Platform Expert not initialized");
71 if (PE_parse_boot_arg("debug", &boot_arg
))
72 if(boot_arg
& DB_KPRT
) disableSerialOuput
= FALSE
;
74 if (DTLookupEntry(0, "/options", &options
) == kSuccess
) {
75 if (DTGetProperty(options
, "input-device", &str
, &size
) == kSuccess
) {
76 if ((size
> 5) && !strncmp("scca:", str
, 5)) {
80 strncpy(baud
, str
, size
);
82 gPESerialBaud
= strtol(baud
, 0, 0);
86 if (DTGetProperty(options
, "output-device", &str
, &size
) == kSuccess
) {
87 if ((size
> 5) && !strncmp("scca:", str
, 5)) {
91 strncpy(baud
, str
, size
);
93 gPESerialBaud
= strtol(baud
, 0, 0);
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
;
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
;
108 simple_lock_init(&kprintf_lock
, 0);
114 * FUTURE: eventually let the boot command determine where
115 * the debug output will be, serial, video, etc.
117 switch (PE_state
.debug_video
.v_display
) {
118 case kDebugTypeSerial
:
119 PE_kputc
= serial_putc
;
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
;
130 PE_state
.debug_video
.v_baseAddr
= 0;
135 void serial_putc(char c
)
137 (void) scc_putc(0, 1, c
);
138 if (c
== '\n') (void) scc_putc(0, 1, '\r');
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');
146 void kprintf(const char *fmt
, ...)
151 state
= ml_set_interrupts_enabled(FALSE
);
152 simple_lock(&kprintf_lock
);
154 if (!disableSerialOuput
) {
155 va_start(listp
, fmt
);
156 _doprnt(fmt
, &listp
, PE_kputc
, 16);
160 simple_unlock(&kprintf_lock
);
161 ml_set_interrupts_enabled(state
);