Chameleon

Chameleon Svn Source Tree

Root/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 = false;
54bool gErrors = false;
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", "Chameleon " I386BOOT_CHAMELEONVERSION " (svn-r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");
95}
96
97void msglog(const char * fmt, ...)
98{
99va_list ap;
100struct putc_info pi;
101
102if (!msgbuf) {
103return;
104}
105
106if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {
107return;
108}
109
110va_start(ap, fmt);
111pi.str = cursor;
112pi.last_str = 0;
113prf(fmt, ap, sputc, &pi);
114va_end(ap);
115cursor += strlen((char *)cursor);
116}
117
118void setupBooterLog(void)
119{
120if (!msgbuf) {
121return;
122}
123
124Node *node = DT__FindNode("/", false);
125if (node)
126DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
127}
128/* Kabyl: !BooterLog */
129
130/*
131 * write one character to console
132 */
133int putchar(int c)
134{
135if ( c == '\t' ) {
136for (c = 0; c < 8; c++) bios_putchar(' ');
137return c;
138}
139
140if ( c == '\n' ) {
141bios_putchar('\r');
142}
143
144bios_putchar(c);
145
146return c;
147}
148
149int getc()
150{
151int c = bgetc();
152
153if ((c & 0xff) == 0) {
154return c;
155} else {
156return (c & 0xff);
157}
158}
159
160// Read and echo a character from console. This doesn't echo backspace
161// since that screws up higher level handling
162
163int getchar()
164{
165register int c = getc();
166
167//if ( c == '\r' ) c = '\n';
168
169//if ( c >= ' ' && c < 0x7f) putchar(c);
170
171return (c);
172}
173
174int printf(const char * fmt, ...)
175{
176va_list ap;
177va_start(ap, fmt);
178if (bootArgs->Video.v_display == VGA_TEXT_MODE)
179{
180prf(fmt, ap, putchar, 0);
181}
182else
183{
184vprf(fmt, ap);
185}
186
187{
188// Kabyl: BooterLog
189struct putc_info pi;
190
191if (!msgbuf) {
192return 0;
193}
194
195if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {
196return 0;
197}
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{
210va_list ap;
211
212va_start(ap, fmt);
213if (gVerboseMode)
214{
215if (bootArgs->Video.v_display == VGA_TEXT_MODE)
216{
217prf(fmt, ap, putchar, 0);
218}
219else
220{
221vprf(fmt, ap);
222}
223}
224
225{
226// Kabyl: BooterLog
227struct putc_info pi;
228
229if (!msgbuf) {
230return 0;
231}
232
233if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {
234return 0;
235}
236pi.str = cursor;
237pi.last_str = 0;
238prf(fmt, ap, sputc, &pi);
239cursor += strlen((char *)cursor);
240}
241
242va_end(ap);
243return(0);
244}
245
246int error(const char * fmt, ...)
247{
248va_list ap;
249gErrors = true;
250va_start(ap, fmt);
251if (bootArgs->Video.v_display == VGA_TEXT_MODE)
252{
253prf(fmt, ap, putchar, 0);
254}
255else
256{
257vprf(fmt, ap);
258}
259
260// Kabyl: BooterLog
261struct putc_info pi;
262
263if (!msgbuf)
264{
265return 0;
266}
267
268if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
269{
270return 0;
271}
272
273pi.str = cursor;
274pi.last_str = 0;
275prf(fmt, ap, sputc, &pi);
276cursor += strlen((char *)cursor);
277
278va_end(ap);
279return(0);
280}
281
282void stop(const char * fmt, ...)
283{
284va_list ap;
285
286printf("\n");
287va_start(ap, fmt);
288if (bootArgs->Video.v_display == VGA_TEXT_MODE)
289{
290prf(fmt, ap, putchar, 0);
291}
292else
293{
294vprf(fmt, ap);
295}
296va_end(ap);
297printf("\nThis is a non recoverable error! System HALTED!!!");
298halt();
299while (1);
300}
301
302/** Print a "Press a key to continue..." message and wait for a key press. */
303void pause()
304{
305 printf("Press a key to continue...\n");
306getchar(); // replace getchar() by pause() were useful.
307}
308

Archive Download this file

Revision: 2490