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{
106if ( c == '\t' )
107{
108for (c = 0; c < 8; c++) putc(' ');
109return;
110}
111
112if ( c == '\n' )
113 {
114putc('\r');
115 }
116
117putc(c);
118}
119
120int getc()
121{
122 int c = bgetc();
123
124 if ((c & 0xff) == 0)
125 return c;
126 else
127return (c & 0xff);
128}
129
130// Read and echo a character from console. This doesn't echo backspace
131// since that screws up higher level handling
132
133int getchar()
134{
135register int c = getc();
136
137if ( c == '\r' ) c = '\n';
138
139if ( c >= ' ' && c < 0x7f) putchar(c);
140
141return (c);
142}
143
144int
145reallyVPrint(const char *format, va_list ap, int flag)
146{
147 if (flag & PRINT) prf(format, ap, putchar);
148
149 if (flag & LOG)
150{
151/* Kabyl: BooterLog */
152prf(format, ap, debug_putc);
153}
154 return 0;
155}
156
157int localVPrintf(const char *format, va_list ap, int flag)
158{
159 /**/
160
161 reallyVPrint(format, ap, flag);
162 return 0;
163}
164
165int printf(const char * fmt, ...)
166{
167 va_list ap;
168va_start(ap, fmt);
169
170localVPrintf(fmt, ap, LOG | PRINT);
171
172va_end(ap);
173
174 return 0;
175}
176
177void msglog(const char * fmt, ...)
178{
179 va_list ap;
180va_start(ap, fmt);
181
182 localVPrintf(fmt, ap, LOG);
183
184va_end(ap);
185}
186
187int verbose(const char * fmt, ...)
188{
189 va_list ap;
190 int flag = 0;
191va_start(ap, fmt);
192 if (get_env(envgVerboseMode))
193 {
194flag = PRINT;
195 }
196
197 localVPrintf(fmt, ap, LOG | flag);
198
199 va_end(ap);
200
201 return(0);
202}
203
204int error(const char * fmt, ...)
205{
206 va_list ap;
207int len;
208char *str = NULL;
209
210 va_start(ap, fmt);
211
212 localVPrintf(fmt, ap, 0);
213
214
215len = prf(fmt, ap, 0);
216if (len > 0)
217{
218str = newEmptyStringWithLength(len);
219if (str != NULL)
220{
221vsnprintf(str,len,fmt,ap);
222}
223
224}
225 va_end(ap);
226
227set_env_copy(envConsoleErr, str, len);
228free(str);
229
230 return(0);
231}
232
233void stop(const char * fmt, ...)
234{
235va_list ap;
236
237printf("\n");
238va_start(ap, fmt);
239
240 localVPrintf(fmt, ap, PRINT);
241
242va_end(ap);
243printf("\nThis is a non recoverable error! System HALTED!!!");
244halt();
245while (1);
246}
247
248/** Print a "Press a key to continue..." message and wait for a key press. */
249void pause(void)
250{
251 printf("Press a key to continue...");
252 getc();
253}
254
255char * newStringWithFormat(const char * fmt, ...)
256{
257 va_list ap;
258int len;
259char *str = NULL;
260
261 va_start(ap, fmt);
262len = prf(fmt, ap, 0);
263if (len > 0)
264{
265str = newEmptyStringWithLength(len);
266if (str != NULL)
267{
268vsnprintf(str,len,fmt,ap);
269}
270
271}
272 va_end(ap);
273
274return str;
275
276}

Archive Download this file

Revision: 1984