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

Archive Download this file

Revision: 1986