Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/CleanCut/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
50extern intvprf(const char * fmt, va_list ap);
51
52bool gVerboseMode;
53bool gErrors;
54
55/* Kabyl: BooterLog */
56#define BOOTER_LOG_SIZE(64 * 1024)
57#define SAFE_LOG_SIZE80
58
59char *msgbuf = 0;
60char *cursor = 0;
61
62struct putc_info {
63 char * str;
64 char * last_str;
65};
66
67static void sputc(int c, struct putc_info * pi)
68{
69if (pi->last_str)
70if (pi->str == pi->last_str)
71{
72*(pi->str) = '\0';
73return;
74}
75*(pi->str)++ = c;
76}
77
78void initBooterLog(void)
79{
80msgbuf = malloc(BOOTER_LOG_SIZE);
81bzero(msgbuf, BOOTER_LOG_SIZE);
82cursor = msgbuf;
83}
84
85void msglog(const char * fmt, ...)
86{
87va_list ap;
88struct putc_info pi;
89
90if (!msgbuf)
91return;
92
93if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
94return;
95
96va_start(ap, fmt);
97pi.str = cursor;
98pi.last_str = 0;
99prf(fmt, ap, sputc, &pi);
100*pi.str = '\0';
101va_end(ap);
102cursor += (pi.str - cursor);
103}
104
105void setupBooterLog(void)
106{
107if (!msgbuf)
108return;
109
110Node *node = DT__FindNode("/", false);
111if (node)
112DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
113}
114/* Kabyl: !BooterLog */
115
116/*
117 * write one character to console
118 */
119void putchar(int c)
120{
121if ( c == '\t' )
122{
123for (c = 0; c < 8; c++) putc(' ');
124return;
125}
126
127if ( c == '\n' )
128 {
129putc('\r');
130 }
131
132putc(c);
133}
134
135int getc()
136{
137 int c = bgetc();
138
139 if ((c & 0xff) == 0)
140 return c;
141 else
142 return (c & 0xff);
143}
144
145// Read and echo a character from console. This doesn't echo backspace
146// since that screws up higher level handling
147
148int getchar()
149{
150register int c = getc();
151
152if ( c == '\r' ) c = '\n';
153
154if ( c >= ' ' && c < 0x7f) putchar(c);
155
156return (c);
157}
158
159int printf(const char * fmt, ...)
160{
161 va_list ap;
162va_start(ap, fmt);
163if (bootArgs->Video.v_display == VGA_TEXT_MODE)
164prf(fmt, ap, putchar, 0);
165else
166vprf(fmt, ap);
167
168{
169/* Kabyl: BooterLog */
170struct putc_info pi;
171
172if (!msgbuf)
173return 0;
174
175if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
176return 0;
177pi.str = cursor;
178pi.last_str = 0;
179prf(fmt, ap, sputc, &pi);
180*pi.str = '\0';
181cursor += (pi.str - cursor);
182}
183
184va_end(ap);
185 return 0;
186}
187
188int verbose(const char * fmt, ...)
189{
190 va_list ap;
191
192va_start(ap, fmt);
193 if (gVerboseMode)
194 {
195if (bootArgs->Video.v_display == VGA_TEXT_MODE)
196prf(fmt, ap, putchar, 0);
197else
198vprf(fmt, ap);
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);
213*pi.str = '\0';
214cursor += (pi.str - cursor);
215}
216
217 va_end(ap);
218 return(0);
219}
220
221int error(const char * fmt, ...)
222{
223 va_list ap;
224 gErrors = true;
225 va_start(ap, fmt);
226if (bootArgs->Video.v_display == VGA_TEXT_MODE)
227prf(fmt, ap, putchar, 0);
228 else
229vprf(fmt, ap);
230va_end(ap);
231 return(0);
232}
233
234void stop(const char * fmt, ...)
235{
236va_list ap;
237
238printf("\n");
239va_start(ap, fmt);
240if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
241prf(fmt, ap, putchar, 0);
242} else {
243vprf(fmt, ap);
244}
245va_end(ap);
246printf("\nThis is a non recoverable error! System HALTED!!!");
247halt();
248while (1);
249}
250
251/** Print a "Press a key to continue..." message and wait for a key press. */
252void pause()
253{
254 printf("Press a key to continue...");
255 getc();
256}
257

Archive Download this file

Revision: 400