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

Archive Download this file

Revision: 2037