Chameleon Applications

Chameleon Applications Svn Source Tree

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

Source at commit 214 created 13 years 5 months ago.
By ifabio, update to chameleon trunk 630, and now the pakage folder is the same as blackosx branch, also add Icon "building" into buildpkg script, and add mint theme info into the English localizable.strings.
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//Azi: Doubled log available size.
57// 64kb are not enough to hold the full log while booting with -f argument (ignore caches).
58// It also seems to fix some reported problems while booting with the mentioned argument.
59// Note: 96kb are enough to hold full log, booting with -f; even so, this depends on how much
60// we "play" at the boot prompt, with what patches we're playing and how much they print to the log,
61// kexts loaded, etc...
62// Please remove this comment when this gets checked by a "true" dev.
63#define BOOTER_LOG_SIZE(128 * 1024)
64#define SAFE_LOG_SIZE134
65
66char *msgbuf = 0;
67char *cursor = 0;
68
69struct putc_info {
70 char * str;
71 char * last_str;
72};
73
74static void sputc(int c, struct putc_info * pi)
75{
76if (pi->last_str)
77if (pi->str == pi->last_str)
78{
79*(pi->str) = '\0';
80return;
81}
82*(pi->str)++ = c;
83}
84
85void initBooterLog(void)
86{
87msgbuf = malloc(BOOTER_LOG_SIZE);
88bzero(msgbuf, BOOTER_LOG_SIZE);
89cursor = msgbuf;
90}
91
92void msglog(const char * fmt, ...)
93{
94va_list ap;
95struct putc_info pi;
96
97if (!msgbuf)
98return;
99
100if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
101return;
102
103va_start(ap, fmt);
104pi.str = cursor;
105pi.last_str = 0;
106prf(fmt, ap, sputc, &pi);
107va_end(ap);
108cursor += strlen((char *)cursor);
109}
110
111void setupBooterLog(void)
112{
113if (!msgbuf)
114return;
115
116Node *node = DT__FindNode("/", false);
117if (node)
118DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
119}
120/* Kabyl: !BooterLog */
121
122
123/*
124 * write one character to console
125 */
126void putchar(int c)
127{
128if ( c == '\t' )
129{
130for (c = 0; c < 8; c++) putc(' ');
131return;
132}
133
134if ( c == '\n' )
135 {
136putc('\r');
137 }
138
139putc(c);
140}
141
142int getc()
143{
144 int c = bgetc();
145
146 if ((c & 0xff) == 0)
147 return c;
148 else
149 return (c & 0xff);
150}
151
152// Read and echo a character from console. This doesn't echo backspace
153// since that screws up higher level handling
154
155int getchar()
156{
157register int c = getc();
158
159if ( c == '\r' ) c = '\n';
160
161if ( c >= ' ' && c < 0x7f) putchar(c);
162
163return (c);
164}
165
166int printf(const char * fmt, ...)
167{
168 va_list ap;
169va_start(ap, fmt);
170if (bootArgs->Video.v_display == VGA_TEXT_MODE)
171prf(fmt, ap, putchar, 0);
172else
173vprf(fmt, ap);
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
190va_end(ap);
191 return 0;
192}
193
194int verbose(const char * fmt, ...)
195{
196 va_list ap;
197
198va_start(ap, fmt);
199 if (gVerboseMode)
200 {
201if (bootArgs->Video.v_display == VGA_TEXT_MODE)
202prf(fmt, ap, putchar, 0);
203else
204vprf(fmt, ap);
205 }
206
207{
208/* Kabyl: BooterLog */
209struct putc_info pi;
210
211if (!msgbuf)
212return 0;
213
214if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
215return 0;
216pi.str = cursor;
217pi.last_str = 0;
218prf(fmt, ap, sputc, &pi);
219cursor += strlen((char *)cursor);
220}
221
222 va_end(ap);
223 return(0);
224}
225
226int error(const char * fmt, ...)
227{
228 va_list ap;
229 gErrors = true;
230 va_start(ap, fmt);
231if (bootArgs->Video.v_display == VGA_TEXT_MODE)
232prf(fmt, ap, putchar, 0);
233 else
234vprf(fmt, ap);
235va_end(ap);
236 return(0);
237}
238
239void stop(const char * fmt, ...)
240{
241va_list ap;
242
243printf("\n");
244va_start(ap, fmt);
245if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
246prf(fmt, ap, putchar, 0);
247} else {
248vprf(fmt, ap);
249}
250va_end(ap);
251printf("\nThis is a non recoverable error! System HALTED!!!");
252halt();
253while (1);
254}
255
256/** Print a "Press a key to continue..." message and wait for a key press. */
257void pause()
258{
259 printf("Press a key to continue...");
260 getc();
261}
262

Archive Download this file

Revision: 214