Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1899