Chameleon

Chameleon Svn Source Tree

Root/branches/mozodojo/i386/libsaio/console.c

  • Property svn:eol-style set to native
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#include "boot.h"
50
51extern intvprf(const char * fmt, va_list ap);
52
53bool gVerboseMode;
54bool gErrors;
55
56/* Kabyl: BooterLog */
57//Azi: Doubled log available size.
58// 64kb are not enough to hold the full log while booting with -f argument (ignore caches).
59// It also seems to fix some reported problems while booting with the mentioned argument.
60// Note: 96kb are enough to hold full log, booting with -f; even so, this depends on how much
61// we "play" at the boot prompt, with what patches we're playing and how much they print to the log,
62// kexts loaded, etc...
63// Please remove this comment when this gets checked by a "true" dev.
64#define BOOTER_LOG_SIZE(128 * 1024)
65#define SAFE_LOG_SIZE134
66
67char *msgbuf = 0;
68char *cursor = 0;
69
70struct putc_info {
71 char * str;
72 char * last_str;
73};
74
75static void sputc(int c, struct putc_info * pi)
76{
77if (pi->last_str)
78if (pi->str == pi->last_str)
79{
80*(pi->str) = '\0';
81return;
82}
83*(pi->str)++ = c;
84}
85
86void initBooterLog(void)
87{
88msgbuf = malloc(BOOTER_LOG_SIZE);
89bzero(msgbuf, BOOTER_LOG_SIZE);
90cursor = msgbuf;
91}
92
93void msglog(const char * fmt, ...)
94{
95va_list ap;
96struct putc_info pi;
97
98if (!msgbuf)
99return;
100
101if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
102return;
103
104va_start(ap, fmt);
105pi.str = cursor;
106pi.last_str = 0;
107prf(fmt, ap, sputc, &pi);
108va_end(ap);
109cursor += strlen((char *)cursor);
110}
111
112void setupBooterLog(void)
113{
114if (!msgbuf)
115return;
116
117Node *node = DT__FindNode("/", false);
118if (node)
119DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
120}
121/* Kabyl: !BooterLog */
122
123
124/*
125 * write one character to console
126 */
127void putchar(int c)
128{
129if ( c == '\t' )
130{
131for (c = 0; c < 8; c++) putc(' ');
132return;
133}
134
135if ( c == '\n' )
136 {
137putc('\r');
138 }
139
140putc(c);
141}
142
143int getc()
144{
145 int c = bgetc();
146
147 if ((c & 0xff) == 0)
148 return c;
149 else
150 return (c & 0xff);
151}
152
153// Read and echo a character from console. This doesn't echo backspace
154// since that screws up higher level handling
155
156int getchar()
157{
158register int c = getc();
159
160if ( c == '\r' ) c = '\n';
161
162if ( c >= ' ' && c < 0x7f) putchar(c);
163
164return (c);
165}
166
167int printf(const char * fmt, ...)
168{
169 va_list ap;
170va_start(ap, fmt);
171 if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))
172 {
173if (bootArgs->Video.v_display == VGA_TEXT_MODE)
174prf(fmt, ap, putchar, 0);
175else
176vprf(fmt, ap);
177} else {
178if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)
179prf(fmt, ap, putchar, 0);
180else
181vprf(fmt, ap);
182}
183
184{
185/* Kabyl: BooterLog */
186struct putc_info pi;
187
188if (!msgbuf)
189return 0;
190
191if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
192return 0;
193pi.str = cursor;
194pi.last_str = 0;
195prf(fmt, ap, sputc, &pi);
196cursor += strlen((char *)cursor);
197}
198
199va_end(ap);
200 return 0;
201}
202
203int verbose(const char * fmt, ...)
204{
205 va_list ap;
206
207va_start(ap, fmt);
208 if (gVerboseMode)
209 {
210 if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))
211 {
212if (bootArgs->Video.v_display == VGA_TEXT_MODE)
213prf(fmt, ap, putchar, 0);
214else
215vprf(fmt, ap);
216} else {
217if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)
218prf(fmt, ap, putchar, 0);
219else
220vprf(fmt, ap);
221}
222 }
223
224{
225/* Kabyl: BooterLog */
226struct putc_info pi;
227
228if (!msgbuf)
229return 0;
230
231if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
232return 0;
233pi.str = cursor;
234pi.last_str = 0;
235prf(fmt, ap, sputc, &pi);
236cursor += strlen((char *)cursor);
237}
238
239 va_end(ap);
240 return(0);
241}
242
243int error(const char * fmt, ...)
244{
245 va_list ap;
246 gErrors = true;
247 va_start(ap, fmt);
248 if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))
249 {
250if (bootArgs->Video.v_display == VGA_TEXT_MODE)
251prf(fmt, ap, putchar, 0);
252else
253vprf(fmt, ap);
254} else {
255if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)
256prf(fmt, ap, putchar, 0);
257else
258vprf(fmt, ap);
259}
260va_end(ap);
261 return(0);
262}
263
264void stop(const char * fmt, ...)
265{
266va_list ap;
267
268printf("\n");
269va_start(ap, fmt);
270 if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))
271 {
272if (bootArgs->Video.v_display == VGA_TEXT_MODE)
273prf(fmt, ap, putchar, 0);
274else
275vprf(fmt, ap);
276} else {
277if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)
278prf(fmt, ap, putchar, 0);
279else
280vprf(fmt, ap);
281}
282va_end(ap);
283printf("\nThis is a non recoverable error! System HALTED!!!");
284halt();
285while (1);
286}
287
288/** Print a "Press a key to continue..." message and wait for a key press. */
289void pause()
290{
291 printf("Press a key to continue...");
292 getc();
293}
294

Archive Download this file

Revision: 755