Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/i386/libsaio/console.c

Source at commit 1066 created 12 years 9 months ago.
By meklort, Removing even more code...
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 <vers.h>
49
50bool gVerboseMode;
51bool gErrors;
52
53/*
54 * Azi: Doubled available log size; this seems to fix some hangs and instant reboots caused by
55 * booting with -f (ignore caches). 96kb are enough to hold full log, booting with -f; even so,
56 * this depends on how much we "play" at the boot prompt and with what patches we're playing,
57 * depending on how much they print to the log.
58 *
59 * Kabyl: BooterLog
60 */
61#define BOOTER_LOG_SIZE(128 * 1024)
62#define SAFE_LOG_SIZE134
63
64char *msgbuf = 0;
65char *cursor = 0;
66
67struct putc_info //Azi: exists on gui.c & printf.c
68{
69 char * str;
70 char * last_str;
71};
72
73static int
74sputc(int c, struct putc_info * pi) //Azi: same as above
75{
76if (pi->last_str)
77if (pi->str == pi->last_str)
78{
79*(pi->str) = '\0';
80return 0;
81}
82*(pi->str)++ = c;
83 return c;
84}
85
86void initBooterLog(void)
87{
88msgbuf = malloc(BOOTER_LOG_SIZE);
89bzero(msgbuf, BOOTER_LOG_SIZE);
90cursor = msgbuf;
91msglog("%s\n", "Chameleon " I386BOOT_CHAMELEONVERSION " (svn-r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");
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}
118/* Kabyl: !BooterLog */
119
120/*
121 * write one character to console
122 */
123int putchar(int c)
124{
125if ( c == '\t' )
126{
127for (c = 0; c < 8; c++) bios_putchar(' ');
128return c;
129}
130
131if ( c == '\n' )
132 {
133bios_putchar('\r');
134 }
135
136bios_putchar(c);
137
138 return c;
139}
140
141int getc()
142{
143 int c = bgetc();
144
145 if ((c & 0xff) == 0)
146 return c;
147 else
148 return (c & 0xff);
149}
150
151// Read and echo a character from console. This doesn't echo backspace
152// since that screws up higher level handling
153
154int getchar()
155{
156register int c = getc();
157
158//if ( c == '\r' ) c = '\n';
159
160//if ( c >= ' ' && c < 0x7f) putchar(c);
161
162return (c);
163}
164
165int printf(const char * fmt, ...)
166{
167 va_list ap;
168va_start(ap, fmt);
169
170 prf(fmt, ap, putchar, 0);
171
172{
173// Kabyl: BooterLog
174struct putc_info pi;
175
176if (!msgbuf)
177return 0;
178
179if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
180return 0;
181pi.str = cursor;
182pi.last_str = 0;
183prf(fmt, ap, sputc, &pi);
184cursor += strlen((char *)cursor);
185}
186
187va_end(ap);
188 return 0;
189}
190
191int verbose(const char * fmt, ...)
192{
193 va_list ap;
194
195va_start(ap, fmt);
196 if (gVerboseMode)
197 {
198 prf(fmt, ap, putchar, 0);
199 }
200
201{
202// Kabyl: BooterLog
203struct putc_info pi;
204
205if (!msgbuf)
206return 0;
207
208if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
209return 0;
210pi.str = cursor;
211pi.last_str = 0;
212prf(fmt, ap, sputc, &pi);
213cursor += strlen((char *)cursor);
214}
215
216 va_end(ap);
217 return(0);
218}
219
220int error(const char * fmt, ...)
221{
222 va_list ap;
223 gErrors = true;
224 va_start(ap, fmt);
225 prf(fmt, ap, putchar, 0);
226va_end(ap);
227 return(0);
228}
229
230void stop(const char * fmt, ...)
231{
232va_list ap;
233
234printf("\n");
235va_start(ap, fmt);
236 prf(fmt, ap, putchar, 0);
237va_end(ap);
238printf("\nThis is a non recoverable error! System HALTED!!!");
239halt();
240while (1);
241}
242
243/** Print a "Press a key to continue..." message and wait for a key press. */
244void pause()
245{
246 printf("Press a key to continue...\n");
247getchar(); // replace getchar() by pause() ?? were useful...?
248}
249

Archive Download this file

Revision: 1066