]> git.saurik.com Git - apple/xnu.git/blame - pexpert/ppc/pe_kprintf.c
xnu-344.21.73.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 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
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,
d7e50217
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
d7e50217 51vm_offset_t scc = 0;
1c79356b 52
d7e50217 53struct slock kprintf_lock;
1c79356b
A
54
55void PE_init_kprintf(boolean_t vm_initialized)
56{
1c79356b
A
57 unsigned int boot_arg;
58
59 if (PE_state.initialized == FALSE)
60 panic("Platform Expert not initialized");
61
d7e50217
A
62 if (PE_parse_boot_arg("debug", &boot_arg))
63 if(boot_arg & DB_KPRT) disableSerialOuput = FALSE;
1c79356b 64
d7e50217
A
65 if( (scc = PE_find_scc())) { /* See if we can find the serial port */
66 scc = io_map_spec(scc, 0x1000); /* Map it in */
67 initialize_serial((void *)scc); /* Start up the serial driver */
1c79356b
A
68 PE_kputc = serial_putc;
69
70 simple_lock_init(&kprintf_lock, 0);
d7e50217
A
71 } else
72 PE_kputc = cnputc;
1c79356b
A
73
74#if 0
75 /*
76 * FUTURE: eventually let the boot command determine where
77 * the debug output will be, serial, video, etc.
78 */
79 switch (PE_state.debug_video.v_display) {
80 case kDebugTypeSerial:
81 PE_kputc = serial_putc;
82 break;
83
84 case kDebugTypeDisplay:
85 init_display_putc( (unsigned char*)PE_state.debug_video.v_baseAddr,
86 PE_state.debug_video.v_rowBytes,
87 PE_state.debug_video.v_height);
88 PE_kputc = display_putc;
89 break;
90
91 default:
92 PE_state.debug_video.v_baseAddr = 0;
93 }
94#endif
95}
96
97void serial_putc(char c)
98{
99 (void) scc_putc(0, 1, c);
100 if (c == '\n') (void) scc_putc(0, 1, '\r');
101
102#if 0
103 (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, c);
104 if (c == '\n') (void) scc_putc(0, (int)PE_state.debug_video.v_baseAddr, '\r');
105#endif
106}
107
108void kprintf(const char *fmt, ...)
109{
110 va_list listp;
111 boolean_t state;
112
113 state = ml_set_interrupts_enabled(FALSE);
114 simple_lock(&kprintf_lock);
115
116 if (!disableSerialOuput) {
117 va_start(listp, fmt);
118 _doprnt(fmt, &listp, PE_kputc, 16);
119 va_end(listp);
120 }
121
122 simple_unlock(&kprintf_lock);
123 ml_set_interrupts_enabled(state);
124}
125