Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/libsaio/console.c

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

Archive Download this file

Revision: 2045