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 //Azi: same as below
70{
71 char * str;
72 char * last_str;
73};
74
75static int
76sputc(int c, struct putc_info * pi) //Azi: exists on printf.c & gui.c
77{
78if (pi->last_str)
79if (pi->str == pi->last_str)
80{
81*(pi->str) = '\0';
82return 0;
83}
84*(pi->str)++ = c;
85 return c;
86}
87
88void initBooterLog(void)
89{
90msgbuf = malloc(BOOTER_LOG_SIZE);
91bzero(msgbuf, BOOTER_LOG_SIZE);
92cursor = msgbuf;
93}
94
95void msglog(const char * fmt, ...)
96{
97va_list ap;
98struct putc_info pi;
99
100if (!msgbuf)
101return;
102
103if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
104return;
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)
117return;
118
119Node *node = DT__FindNode("/", false);
120if (node)
121DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
122}
123/* Kabyl: !BooterLog */
124
125/*
126 * write one character to console
127 */
128int putchar(int c)
129{
130if ( c == '\t' )
131{
132for (c = 0; c < 8; c++) bios_putchar(' ');
133return c;
134}
135
136if ( c == '\n' )
137 {
138bios_putchar('\r');
139 }
140
141bios_putchar(c);
142
143 return c;
144}
145
146int getc()
147{
148 int c = bgetc();
149
150 if ((c & 0xff) == 0)
151 return c;
152 else
153 return (c & 0xff);
154}
155
156// Read and echo a character from console. This doesn't echo backspace
157// since that screws up higher level handling
158
159int getchar()
160{
161register int c = getc();
162
163if ( c == '\r' ) c = '\n';
164
165if ( c >= ' ' && c < 0x7f) putchar(c);
166
167return (c);
168}
169
170int printf(const char * fmt, ...)
171{
172 va_list ap;
173va_start(ap, fmt);
174if (bootArgs->Video.v_display == VGA_TEXT_MODE)
175prf(fmt, ap, putchar, 0);
176else
177vprf(fmt, ap);
178
179{
180// Kabyl: BooterLog
181struct putc_info pi;
182
183if (!msgbuf)
184return 0;
185
186if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
187return 0;
188pi.str = cursor;
189pi.last_str = 0;
190prf(fmt, ap, sputc, &pi);
191cursor += strlen((char *)cursor);
192}
193
194va_end(ap);
195 return 0;
196}
197
198int verbose(const char * fmt, ...)
199{
200 va_list ap;
201
202va_start(ap, fmt);
203 if (gVerboseMode)
204 {
205if (bootArgs->Video.v_display == VGA_TEXT_MODE)
206prf(fmt, ap, putchar, 0);
207else
208vprf(fmt, ap);
209 }
210
211{
212// Kabyl: BooterLog
213struct putc_info pi;
214
215if (!msgbuf)
216return 0;
217
218if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
219return 0;
220pi.str = cursor;
221pi.last_str = 0;
222prf(fmt, ap, sputc, &pi);
223cursor += strlen((char *)cursor);
224}
225
226 va_end(ap);
227 return(0);
228}
229
230int error(const char * fmt, ...)
231{
232 va_list ap;
233 gErrors = true;
234 va_start(ap, fmt);
235if (bootArgs->Video.v_display == VGA_TEXT_MODE)
236prf(fmt, ap, putchar, 0);
237 else
238vprf(fmt, ap);
239va_end(ap);
240 return(0);
241}
242
243void stop(const char * fmt, ...)
244{
245va_list ap;
246
247printf("\n");
248va_start(ap, fmt);
249if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
250prf(fmt, ap, putchar, 0);
251} else {
252vprf(fmt, ap);
253}
254va_end(ap);
255printf("\nThis is a non recoverable error! System HALTED!!!");
256halt();
257while (1);
258}
259
260/** Print a "Press a key to continue..." message and wait for a key press. */
261void pause()
262{
263 printf("Press a key to continue...\n");
264 getc();
265}
266

Archive Download this file

Revision: 912