Chameleon

Chameleon Svn Source Tree

Root/branches/xZen/src/arch/i386/libsaio/console.c

Source at commit 1263 created 9 years 8 months ago.
By meklort, Update i386 makefiles
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
49bool gVerboseMode;
50bool gErrors;
51
52/*
53 * Azi: Doubled available log size; this seems to fix some hangs and instant reboots caused by
54 * booting with -f (ignore caches). 96kb are enough to hold full log, booting with -f; even so,
55 * this depends on how much we "play" at the boot prompt and with what patches we're playing,
56 * depending on how much they print to the log.
57 *
58 * Kabyl: BooterLog
59 */
60#define BOOTER_LOG_SIZE(128 * 1024)
61#define SAFE_LOG_SIZE134
62
63char *msgbuf = 0;
64char *cursor = 0;
65
66struct putc_info //Azi: exists on gui.c & printf.c
67{
68 char * str;
69 char * last_str;
70};
71
72static int
73sputc(int c, struct putc_info * pi) //Azi: same as above
74{
75if (pi->last_str)
76if (pi->str == pi->last_str)
77{
78*(pi->str) = '\0';
79return 0;
80}
81*(pi->str)++ = c;
82 return c;
83}
84
85void initBooterLog(void)
86{
87msgbuf = malloc(BOOTER_LOG_SIZE);
88bzero(msgbuf, BOOTER_LOG_SIZE);
89cursor = msgbuf;
90}
91
92void msglog(const char * fmt, ...)
93{
94va_list ap;
95struct putc_info pi;
96
97if (!msgbuf)
98return;
99
100if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
101return;
102
103va_start(ap, fmt);
104pi.str = cursor;
105pi.last_str = 0;
106prf(fmt, ap, sputc, &pi);
107va_end(ap);
108cursor += strlen((char *)cursor);
109}
110
111void setupBooterLog(void)
112{
113if (!msgbuf)
114return;
115}
116/* Kabyl: !BooterLog */
117
118/*
119 * write one character to console
120 */
121int putchar(int c)
122{
123if ( c == '\t' )
124{
125for (c = 0; c < 8; c++) bios_putchar(' ');
126return c;
127}
128
129if ( c == '\n' )
130 {
131bios_putchar('\r');
132 }
133
134bios_putchar(c);
135
136 return c;
137}
138
139int getc()
140{
141 int c = bgetc();
142
143 if ((c & 0xff) == 0)
144 return c;
145 else
146 return (c & 0xff);
147}
148
149// Read and echo a character from console. This doesn't echo backspace
150// since that screws up higher level handling
151
152int getchar()
153{
154register int c = getc();
155
156//if ( c == '\r' ) c = '\n';
157
158//if ( c >= ' ' && c < 0x7f) putchar(c);
159
160return (c);
161}
162
163int verbose(const char * fmt, ...)
164{
165 va_list ap;
166
167va_start(ap, fmt);
168 if (gVerboseMode)
169 {
170 prf(fmt, ap, putchar, 0);
171 }
172
173{
174// Kabyl: BooterLog
175struct putc_info pi;
176
177if (!msgbuf)
178return 0;
179
180if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
181return 0;
182pi.str = cursor;
183pi.last_str = 0;
184prf(fmt, ap, sputc, &pi);
185cursor += strlen((char *)cursor);
186}
187
188 va_end(ap);
189 return(0);
190}
191
192int error(const char * fmt, ...)
193{
194 va_list ap;
195 gErrors = true;
196 va_start(ap, fmt);
197 prf(fmt, ap, putchar, 0);
198va_end(ap);
199 return(0);
200}
201
202void stop(const char * fmt, ...)
203{
204va_list ap;
205
206printf("\n");
207va_start(ap, fmt);
208 prf(fmt, ap, putchar, 0);
209va_end(ap);
210printf("\nThis is a non recoverable error! System HALTED!!!");
211halt();
212while (1);
213}
214
215/** Print a "Press a key to continue..." message and wait for a key press. */
216void pause()
217{
218 printf("Press a key to continue...\n");
219getchar(); // replace getchar() by pause() ?? were useful...?
220}
221

Archive Download this file

Revision: 1263