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 "modules.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
86void msglog(const char * fmt, ...)
87{
88va_list ap;
89struct putc_info pi;
90
91if (!msgbuf)
92return;
93
94if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
95return;
96
97va_start(ap, fmt);
98pi.str = cursor;
99pi.last_str = 0;
100prf(fmt, ap, sputc, &pi);
101va_end(ap);
102cursor += strlen((char *)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/*
118 * write one character to console
119 */
120void putchar(int c)
121{
122if ( c == '\t' )
123{
124for (c = 0; c < 8; c++) putc(' ');
125return;
126}
127
128if ( c == '\n' )
129 {
130putc('\r');
131 }
132
133putc(c);
134}
135
136int getc()
137{
138 int c = bgetc();
139
140//execute_hook("Keymapper", &c, NULL, NULL, NULL, NULL, NULL);
141
142 if ((c & 0xff) == 0)
143 return c;
144 else
145return (c & 0xff);
146}
147
148// Read and echo a character from console. This doesn't echo backspace
149// since that screws up higher level handling
150
151int getchar()
152{
153register int c = getc();
154
155if ( c == '\r' ) c = '\n';
156
157if ( c >= ' ' && c < 0x7f) putchar(c);
158
159return (c);
160}
161
162int printf(const char * fmt, ...)
163{
164 va_list ap;
165va_start(ap, fmt);
166
167prf(fmt, ap, putchar, 0);
168
169{
170/* Kabyl: BooterLog */
171struct putc_info pi;
172
173if (!msgbuf)
174return 0;
175
176if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
177return 0;
178pi.str = cursor;
179pi.last_str = 0;
180prf(fmt, ap, sputc, &pi);
181cursor += strlen((char *)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 {
195prf(fmt, ap, putchar, 0);
196 }
197
198{
199/* Kabyl: BooterLog */
200struct putc_info pi;
201
202if (!msgbuf)
203return 0;
204
205if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
206return 0;
207pi.str = cursor;
208pi.last_str = 0;
209prf(fmt, ap, sputc, &pi);
210cursor += strlen((char *)cursor);
211}
212
213 va_end(ap);
214 return(0);
215}
216
217int error(const char * fmt, ...)
218{
219 va_list ap;
220 gErrors = true;
221 va_start(ap, fmt);
222
223prf(fmt, ap, putchar, 0);
224
225va_end(ap);
226 return(0);
227}
228
229void stop(const char * fmt, ...)
230{
231va_list ap;
232
233printf("\n");
234va_start(ap, fmt);
235
236prf(fmt, ap, putchar, 0);
237
238va_end(ap);
239printf("\nThis is a non recoverable error! System HALTED!!!");
240halt();
241while (1);
242}
243
244/** Print a "Press a key to continue..." message and wait for a key press. */
245void pause()
246{
247 printf("Press a key to continue...");
248 getc();
249}
250

Archive Download this file

Revision: 1525