Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1050