]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_kprintf.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * PPC platform expert debugging output initialization.
27 #include <machine/machine_routines.h>
28 #include <pexpert/protos.h>
29 #include <pexpert/pexpert.h>
30 #include <pexpert/ppc/powermac.h>
31 #include <pexpert/device_tree.h>
32 #include <kern/debug.h>
33 #include <kern/simple_lock.h>
35 /* extern references */
36 extern void init_display_putc(unsigned char*, int, int);
37 extern void display_putc(char c
);
38 extern int scc_putc(int unit
, int line
, int c
);
39 extern void cnputc(char c
);
41 /* Internal routines -- eventually put this in serial driver */
42 void serial_putc(char c
);
45 void (*PE_kputc
)(char c
) = 0;
47 unsigned int disableSerialOuput
= TRUE
;
51 struct slock kprintf_lock
;
53 void PE_init_kprintf(boolean_t vm_initialized
)
55 unsigned int boot_arg
;
56 int32_t cnt
, size
, serial_baud
= -1;
60 if (PE_state
.initialized
== FALSE
)
61 panic("Platform Expert not initialized");
63 if (PE_parse_boot_arg("debug", &boot_arg
))
64 if(boot_arg
& DB_KPRT
) disableSerialOuput
= FALSE
;
66 if (DTLookupEntry(0, "/options", &options
) == kSuccess
) {
67 if (DTGetProperty(options
, "input-device", &str
, &size
) == kSuccess
) {
68 if ((size
> 5) && !strncmp("scca:", str
, 5)) {
72 strncpy(baud
, str
, size
);
74 gPESerialBaud
= strtol(baud
, 0, 0);
78 if (DTGetProperty(options
, "output-device", &str
, &size
) == kSuccess
) {
79 if ((size
> 5) && !strncmp("scca:", str
, 5)) {
83 strncpy(baud
, str
, size
);
85 gPESerialBaud
= strtol(baud
, 0, 0);
91 /* Check the boot-args for new serial baud. */
92 if (PE_parse_boot_arg("serialbaud", &serial_baud
))
93 if (serial_baud
!= -1) gPESerialBaud
= serial_baud
;
95 if( (scc
= PE_find_scc())) { /* See if we can find the serial port */
96 scc
= io_map_spec(scc
, 0x1000); /* Map it in */
97 initialize_serial((void *)scc
, gPESerialBaud
); /* Start up the serial driver */
98 PE_kputc
= serial_putc
;
100 simple_lock_init(&kprintf_lock
, 0);
106 * FUTURE: eventually let the boot command determine where
107 * the debug output will be, serial, video, etc.
109 switch (PE_state
.debug_video
.v_display
) {
110 case kDebugTypeSerial
:
111 PE_kputc
= serial_putc
;
114 case kDebugTypeDisplay
:
115 init_display_putc( (unsigned char*)PE_state
.debug_video
.v_baseAddr
,
116 PE_state
.debug_video
.v_rowBytes
,
117 PE_state
.debug_video
.v_height
);
118 PE_kputc
= display_putc
;
122 PE_state
.debug_video
.v_baseAddr
= 0;
127 void serial_putc(char c
)
129 (void) scc_putc(0, 1, c
);
130 if (c
== '\n') (void) scc_putc(0, 1, '\r');
133 (void) scc_putc(0, (int)PE_state
.debug_video
.v_baseAddr
, c
);
134 if (c
== '\n') (void) scc_putc(0, (int)PE_state
.debug_video
.v_baseAddr
, '\r');
138 void kprintf(const char *fmt
, ...)
143 state
= ml_set_interrupts_enabled(FALSE
);
144 simple_lock(&kprintf_lock
);
146 if (!disableSerialOuput
) {
147 va_start(listp
, fmt
);
148 _doprnt(fmt
, &listp
, PE_kputc
, 16);
152 simple_unlock(&kprintf_lock
);
153 ml_set_interrupts_enabled(state
);