Chameleon

Chameleon Svn Source Tree

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

Source at commit 1209 created 12 years 8 months ago.
By meklort, Use printf from klibc instead of from 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 <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 verbose(const char * fmt, ...)
166{
167 va_list ap;
168
169va_start(ap, fmt);
170 if (gVerboseMode)
171 {
172 prf(fmt, ap, putchar, 0);
173 }
174
175{
176// Kabyl: BooterLog
177struct putc_info pi;
178
179if (!msgbuf)
180return 0;
181
182if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
183return 0;
184pi.str = cursor;
185pi.last_str = 0;
186prf(fmt, ap, sputc, &pi);
187cursor += strlen((char *)cursor);
188}
189
190 va_end(ap);
191 return(0);
192}
193
194int error(const char * fmt, ...)
195{
196 va_list ap;
197 gErrors = true;
198 va_start(ap, fmt);
199 prf(fmt, ap, putchar, 0);
200va_end(ap);
201 return(0);
202}
203
204void stop(const char * fmt, ...)
205{
206va_list ap;
207
208printf("\n");
209va_start(ap, fmt);
210 prf(fmt, ap, putchar, 0);
211va_end(ap);
212printf("\nThis is a non recoverable error! System HALTED!!!");
213halt();
214while (1);
215}
216
217/** Print a "Press a key to continue..." message and wait for a key press. */
218void pause()
219{
220 printf("Press a key to continue...\n");
221getchar(); // replace getchar() by pause() ?? were useful...?
222}
223

Archive Download this file

Revision: 1209