Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch_Modules/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 = false;
48bool gErrors = false;
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 (Modules) (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)
194{
195return 0;
196}
197
198if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
199return 0;
200pi.str = cursor;
201pi.last_str = 0;
202prf(fmt, ap, sputc, &pi);
203cursor += strlen((char *)cursor);
204}
205
206va_end(ap);
207return 0;
208}
209
210int verbose(const char * fmt, ...)
211{
212va_list ap;
213
214va_start(ap, fmt);
215if (gVerboseMode)
216{
217if (bootArgs->Video.v_display == VGA_TEXT_MODE)
218{
219prf(fmt, ap, putchar, 0);
220}
221else
222{
223vprf(fmt, ap);
224}
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: 2238