Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/i386/libsaio/console.c

Source at commit 296 created 12 years 10 months ago.
By ifabio, add i386 folder
1/*
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 2.0 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Mach Operating System
26 * Copyright (c) 1990 Carnegie-Mellon University
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * All rights reserved. The CMU software License Agreement specifies
29 * the terms and conditions for use and redistribution.
30 */
31
32/*
33 * INTEL CORPORATION PROPRIETARY INFORMATION
34 *
35 *This software is supplied under the terms of a license agreement or
36 *nondisclosure agreement with Intel Corporation and may not be copied
37 *nor disclosed except in accordance with the terms of that agreement.
38 *
39 *Copyright 1988, 1989 Intel Corporation
40 */
41
42/*
43 * Copyright 1993 NeXT, Inc.
44 * All rights reserved.
45 */
46
47#include "libsaio.h"
48#include "bootstruct.h"
49
50extern intvprf(const char * fmt, va_list ap);
51
52bool gVerboseMode;
53bool gErrors;
54
55/* Kabyl: BooterLog */
56//Azi: Doubled log available size.
57// 64kb are not enough to hold the full log while booting with -f argument (ignore caches).
58// It also seems to fix some reported problems while booting with the mentioned argument.
59// Note: 96kb are enough to hold full log, booting with -f; even so, this depends on how much
60// we "play" at the boot prompt, with what patches we're playing and how much they print to the log,
61// kexts loaded, etc...
62// Please remove this comment when this gets checked by a "true" dev.
63#define BOOTER_LOG_SIZE(128 * 1024)
64#define SAFE_LOG_SIZE134
65
66char *msgbuf = 0;
67char *cursor = 0;
68
69struct putc_info {
70 char * str;
71 char * last_str;
72};
73
74static void sputc(int c, struct putc_info * pi)
75{
76 if (pi->last_str)
77if (pi->str == pi->last_str)
78{
79*(pi->str) = '\0';
80return;
81}
82 *(pi->str)++ = c;
83}
84
85void initBooterLog(void)
86{
87msgbuf = malloc(BOOTER_LOG_SIZE);
88bzero(msgbuf, BOOTER_LOG_SIZE);
89cursor = msgbuf;
90}
91
92void msglog(const char * fmt, ...)
93{
94va_list ap;
95struct putc_info pi;
96
97if (!msgbuf)
98return;
99
100if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
101return;
102
103va_start(ap, fmt);
104pi.str = cursor;
105pi.last_str = 0;
106prf(fmt, ap, sputc, &pi);
107va_end(ap);
108cursor += strlen((char *)cursor);
109}
110
111void setupBooterLog(void)
112{
113if (!msgbuf)
114return;
115
116Node *node = DT__FindNode("/", false);
117if (node)
118DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
119}
120/* Kabyl: !BooterLog */
121
122/*
123 * write one character to console
124 */
125void putchar(int c)
126{
127if ( c == '\t' )
128{
129for (c = 0; c < 8; c++) putc(' ');
130return;
131}
132
133if ( c == '\n' )
134 {
135putc('\r');
136 }
137
138putc(c);
139}
140
141int getc()
142{
143 int c = bgetc();
144
145 if ((c & 0xff) == 0)
146 return c;
147 else
148 return (c & 0xff);
149}
150
151// Read and echo a character from console. This doesn't echo backspace
152// since that screws up higher level handling
153
154int getchar()
155{
156register int c = getc();
157
158if ( c == '\r' ) c = '\n';
159
160if ( c >= ' ' && c < 0x7f) putchar(c);
161
162return (c);
163}
164
165int printf(const char * fmt, ...)
166{
167 va_list ap;
168va_start(ap, fmt);
169if (bootArgs->Video.v_display == VGA_TEXT_MODE)
170prf(fmt, ap, putchar, 0);
171else
172vprf(fmt, ap);
173
174{
175/* Kabyl: BooterLog */
176struct putc_info pi;
177
178if (!msgbuf)
179return 0;
180
181if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
182return 0;
183pi.str = cursor;
184pi.last_str = 0;
185prf(fmt, ap, sputc, &pi);
186cursor += strlen((char *)cursor);
187}
188
189va_end(ap);
190 return 0;
191}
192
193int verbose(const char * fmt, ...)
194{
195 va_list ap;
196
197va_start(ap, fmt);
198 if (gVerboseMode)
199 {
200if (bootArgs->Video.v_display == VGA_TEXT_MODE)
201prf(fmt, ap, putchar, 0);
202else
203vprf(fmt, ap);
204 }
205
206{
207/* Kabyl: BooterLog */
208struct putc_info pi;
209
210if (!msgbuf)
211return 0;
212
213if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
214return 0;
215pi.str = cursor;
216pi.last_str = 0;
217prf(fmt, ap, sputc, &pi);
218cursor += strlen((char *)cursor);
219}
220
221 va_end(ap);
222 return(0);
223}
224
225int error(const char * fmt, ...)
226{
227 va_list ap;
228 gErrors = true;
229 va_start(ap, fmt);
230if (bootArgs->Video.v_display == VGA_TEXT_MODE)
231prf(fmt, ap, putchar, 0);
232 else
233vprf(fmt, ap);
234va_end(ap);
235 return(0);
236}
237
238void stop(const char * fmt, ...)
239{
240va_list ap;
241
242printf("\n");
243va_start(ap, fmt);
244if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
245prf(fmt, ap, putchar, 0);
246} else {
247vprf(fmt, ap);
248}
249va_end(ap);
250printf("\nThis is a non recoverable error! System HALTED!!!");
251halt();
252while (1);
253}
254
255/** Print a "Press a key to continue..." message and wait for a key press. */
256void pause()
257{
258 printf("Press a key to continue...\n");
259 getc();
260}
261

Archive Download this file

Revision: 296