Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2463