Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 899