]> git.saurik.com Git - apple/xnu.git/blame - pexpert/ppc/pe_kprintf.c
xnu-344.49.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 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * file: pe_kprintf.c
27 * PPC platform expert debugging output initialization.
28 */
29#include <stdarg.h>
30#include <machine/machine_routines.h>
31#include <pexpert/protos.h>
32#include <pexpert/pexpert.h>
33#include <pexpert/ppc/powermac.h>
34#include <kern/debug.h>
35#include <kern/simple_lock.h>
36
37/* extern references */
38extern void init_display_putc(unsigned char*, int, int);
39extern void display_putc(char c);
40extern int scc_putc(int unit, int line, int c);
41extern void cnputc(char c);
42
43/* Internal routines -- eventually put this in serial driver */
44void serial_putc(char c);
45
46/* Globals */
47void (*PE_kputc)(char c) = 0;
48
49unsigned int disableSerialOuput = TRUE;
50
51
de355530 52static struct slock kprintf_lock;
1c79356b
A
53
54void PE_init_kprintf(boolean_t vm_initialized)
55{
de355530 56 static vm_offset_t scc;
1c79356b
A
57 unsigned int boot_arg;
58
59 if (PE_state.initialized == FALSE)
60 panic("Platform Expert not initialized");
61
de355530
A
62 if (!vm_initialized)
63 {
64 if (PE_parse_boot_arg("debug", &boot_arg))
65 if(boot_arg & DB_KPRT) disableSerialOuput = FALSE;
1c79356b 66
de355530
A
67 if( (scc = PE_find_scc()))
68 {
69 initialize_serial( (void *) scc );
1c79356b
A
70 PE_kputc = serial_putc;
71
72 simple_lock_init(&kprintf_lock, 0);
de355530
A
73 } else
74 PE_kputc = cnputc;
75
76 } else if( scc){
77 initialize_serial( (void *) io_map( scc, 0x1000) );
78 }
1c79356b
A
79
80#if 0
81 /*
82 * FUTURE: eventually let the boot command determine where
83 * the debug output will be, serial, video, etc.
84 */
85 switch (PE_state.debug_video.v_display) {
86 case kDebugTypeSerial:
87 PE_kputc = serial_putc;
88 break;
89
90 case kDebugTypeDisplay:
91 init_display_putc( (unsigned char*)PE_state.debug_video.v_baseAddr,
92 PE_state.debug_video.v_rowBytes,
93 PE_state.debug_video.v_height);
94 PE_kputc = display_putc;
95 break;
96
97 default:
98 PE_state.debug_video.v_baseAddr = 0;
99 }
100#endif
101}
102
103void serial_putc(char c)
104{
105 (void) scc_putc(0, 1, c);
106 if (c == '\n') (void) scc_putc(0, 1, '\r');
107
108#if 0
109 (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, c);
110 if (c == '\n') (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, '\r');
111#endif
112}
113
114void kprintf(const char *fmt, ...)
115{
116 va_list listp;
117 boolean_t state;
118
119 state = ml_set_interrupts_enabled(FALSE);
120 simple_lock(&kprintf_lock);
121
122 if (!disableSerialOuput) {
123 va_start(listp, fmt);
124 _doprnt(fmt, &listp, PE_kputc, 16);
125 va_end(listp);
126 }
127
128 simple_unlock(&kprintf_lock);
129 ml_set_interrupts_enabled(state);
130}
131