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 <vers.h>␊ |
50 | ␊ |
51 | extern int␉vprf(const char * fmt, va_list ap);␊ |
52 | ␊ |
53 | bool gVerboseMode = false;␊ |
54 | bool gErrors = false;␊ |
55 | ␊ |
56 | /*␊ |
57 | * Azi: Doubled available log size; this seems to fix some hangs and instant reboots caused by␊ |
58 | * booting with -f (ignore caches). 96kb are enough to hold full log, booting with -f; even so,␊ |
59 | * this depends on how much we "play" at the boot prompt and with what patches we're playing,␊ |
60 | * depending on how much they print to the log.␊ |
61 | *␉␊ |
62 | * Kabyl: BooterLog␊ |
63 | */␊ |
64 | #define BOOTER_LOG_SIZE␉(128 * 1024)␊ |
65 | #define SAFE_LOG_SIZE␉134␊ |
66 | ␊ |
67 | char *msgbuf = 0;␊ |
68 | char *cursor = 0;␊ |
69 | ␊ |
70 | struct putc_info //Azi: exists on gui.c & printf.c␊ |
71 | {␊ |
72 | ␉char * str;␊ |
73 | ␉char * last_str;␊ |
74 | };␊ |
75 | ␊ |
76 | static int␊ |
77 | sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
78 | {␊ |
79 | ␉if (pi->last_str)␊ |
80 | ␉if (pi->str == pi->last_str)␊ |
81 | ␉{␊ |
82 | ␉␉*(pi->str) = '\0';␊ |
83 | ␉␉return 0;␊ |
84 | ␉}␊ |
85 | ␉*(pi->str)++ = c;␊ |
86 | ␉return c;␊ |
87 | }␊ |
88 | ␊ |
89 | void initBooterLog(void)␊ |
90 | {␊ |
91 | ␉msgbuf = malloc(BOOTER_LOG_SIZE);␊ |
92 | ␉bzero(msgbuf, BOOTER_LOG_SIZE);␊ |
93 | ␉cursor = msgbuf;␊ |
94 | ␉msglog("%s\n", "Chameleon " I386BOOT_CHAMELEONVERSION " (svn-r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");␊ |
95 | }␊ |
96 | ␊ |
97 | void msglog(const char * fmt, ...)␊ |
98 | {␊ |
99 | ␉va_list ap;␊ |
100 | ␉struct putc_info pi;␊ |
101 | ␊ |
102 | ␉if (!msgbuf)␊ |
103 | ␉{␊ |
104 | ␉␉return;␊ |
105 | ␉}␊ |
106 | ␊ |
107 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
108 | ␉{␊ |
109 | ␉␉return;␊ |
110 | ␉}␊ |
111 | ␊ |
112 | ␉va_start(ap, fmt);␊ |
113 | ␉pi.str = cursor;␊ |
114 | ␉pi.last_str = 0;␊ |
115 | ␉prf(fmt, ap, sputc, &pi);␊ |
116 | ␉va_end(ap);␊ |
117 | ␉cursor += strlen((char *)cursor);␊ |
118 | }␊ |
119 | ␊ |
120 | void setupBooterLog(void)␊ |
121 | {␊ |
122 | ␉if (!msgbuf)␊ |
123 | ␉{␊ |
124 | ␉␉return;␊ |
125 | ␉}␊ |
126 | ␊ |
127 | ␉Node *node = DT__FindNode("/", false);␊ |
128 | ␉if (node)␊ |
129 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
130 | }␊ |
131 | /* Kabyl: !BooterLog */␊ |
132 | ␊ |
133 | /*␊ |
134 | * write one character to console␊ |
135 | */␊ |
136 | int putchar(int c)␊ |
137 | {␊ |
138 | ␉if ( c == '\t' ) {␊ |
139 | ␉␉for (c = 0; c < 8; c++) bios_putchar(' ');␊ |
140 | ␉␉return c;␊ |
141 | ␉}␊ |
142 | ␊ |
143 | ␉if ( c == '\n' ) {␊ |
144 | ␉␉bios_putchar('\r');␊ |
145 | ␉}␊ |
146 | ␊ |
147 | ␉bios_putchar(c);␊ |
148 | ␊ |
149 | ␉return c;␊ |
150 | }␊ |
151 | ␊ |
152 | int getc()␊ |
153 | {␊ |
154 | ␉int c = bgetc();␊ |
155 | ␊ |
156 | ␉if ((c & 0xff) == 0) {␊ |
157 | ␉␉return c;␊ |
158 | ␉} else {␊ |
159 | ␉␉return (c & 0xff);␊ |
160 | ␉}␊ |
161 | }␊ |
162 | ␊ |
163 | // Read and echo a character from console. This doesn't echo backspace␊ |
164 | // since that screws up higher level handling␊ |
165 | ␊ |
166 | int getchar()␊ |
167 | {␊ |
168 | ␉register int c = getc();␊ |
169 | ␊ |
170 | //␉if ( c == '\r' ) c = '\n';␊ |
171 | ␊ |
172 | //␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
173 | ␊ |
174 | ␉return (c);␊ |
175 | }␊ |
176 | ␊ |
177 | int printf(const char * fmt, ...)␊ |
178 | {␊ |
179 | ␉va_list ap;␊ |
180 | ␊ |
181 | ␉va_start(ap, fmt);␊ |
182 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
183 | ␉{␊ |
184 | ␉␉prf(fmt, ap, putchar, 0);␊ |
185 | ␉}␊ |
186 | ␉else␊ |
187 | ␉{␊ |
188 | ␉␉vprf(fmt, ap);␊ |
189 | ␉}␊ |
190 | ␊ |
191 | ␉{␊ |
192 | ␉␉// Kabyl: BooterLog␊ |
193 | ␉␉struct putc_info pi;␊ |
194 | ␊ |
195 | ␉␉if (!msgbuf) {␊ |
196 | ␉␉␉return 0;␊ |
197 | ␉␉}␊ |
198 | ␊ |
199 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {␊ |
200 | ␉␉␉return 0;␊ |
201 | ␉␉}␊ |
202 | ␉␉pi.str = cursor;␊ |
203 | ␉␉pi.last_str = 0;␊ |
204 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
205 | ␉␉cursor += strlen((char *)cursor);␊ |
206 | ␉}␊ |
207 | ␊ |
208 | ␉va_end(ap);␊ |
209 | ␉return 0;␊ |
210 | }␊ |
211 | ␊ |
212 | int verbose(const char * fmt, ...)␊ |
213 | {␊ |
214 | ␉va_list ap;␊ |
215 | ␊ |
216 | ␉va_start(ap, fmt);␊ |
217 | ␉if (gVerboseMode)␊ |
218 | ␉{␊ |
219 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
220 | ␉␉{␊ |
221 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
222 | ␉␉}␊ |
223 | ␉␉else␊ |
224 | ␉␉{␊ |
225 | ␉␉␉vprf(fmt, ap);␊ |
226 | ␉␉}␊ |
227 | ␉}␊ |
228 | ␊ |
229 | ␉{␊ |
230 | ␉␉// Kabyl: BooterLog␊ |
231 | ␉␉struct putc_info pi;␊ |
232 | ␊ |
233 | ␉␉if (!msgbuf) {␊ |
234 | ␉␉␉return 0;␊ |
235 | ␉␉}␊ |
236 | ␊ |
237 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {␊ |
238 | ␉␉␉return 0;␊ |
239 | ␉␉}␊ |
240 | ␉␉pi.str = cursor;␊ |
241 | ␉␉pi.last_str = 0;␊ |
242 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
243 | ␉␉cursor += strlen((char *)cursor);␊ |
244 | ␉}␊ |
245 | ␊ |
246 | ␉va_end(ap);␊ |
247 | ␉return(0);␊ |
248 | }␊ |
249 | ␊ |
250 | int error(const char * fmt, ...)␊ |
251 | {␊ |
252 | ␉va_list ap;␊ |
253 | ␉gErrors = true;␊ |
254 | ␉va_start(ap, fmt);␊ |
255 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
256 | ␉{␊ |
257 | ␉␉prf(fmt, ap, putchar, 0);␊ |
258 | ␉}␊ |
259 | ␉else␊ |
260 | ␉{␊ |
261 | ␉␉vprf(fmt, ap);␊ |
262 | ␉}␊ |
263 | ␊ |
264 | ␉// Kabyl: BooterLog␊ |
265 | ␉struct putc_info pi;␊ |
266 | ␊ |
267 | ␉if (!msgbuf)␊ |
268 | ␉{␊ |
269 | ␉␉return 0;␊ |
270 | ␉}␊ |
271 | ␊ |
272 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
273 | ␉{␊ |
274 | ␉␉return 0;␊ |
275 | ␉}␊ |
276 | ␊ |
277 | ␉pi.str = cursor;␊ |
278 | ␉pi.last_str = 0;␊ |
279 | ␉prf(fmt, ap, sputc, &pi);␊ |
280 | ␉cursor += strlen((char *)cursor);␊ |
281 | ␊ |
282 | ␉va_end(ap);␊ |
283 | ␉return(0);␊ |
284 | }␊ |
285 | ␊ |
286 | void stop(const char * fmt, ...)␊ |
287 | {␊ |
288 | ␉va_list ap;␊ |
289 | ␊ |
290 | ␉printf("\n");␊ |
291 | ␉va_start(ap, fmt);␊ |
292 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
293 | ␉{␊ |
294 | ␉␉prf(fmt, ap, putchar, 0);␊ |
295 | ␉}␊ |
296 | ␉else␊ |
297 | ␉{␊ |
298 | ␉␉vprf(fmt, ap);␊ |
299 | ␉}␊ |
300 | ␉va_end(ap);␊ |
301 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
302 | ␉halt();␊ |
303 | ␉while (1);␊ |
304 | }␊ |
305 | ␊ |
306 | /** Print a "Press a key to continue..." message and wait for a key press. */␊ |
307 | void pause()␊ |
308 | {␊ |
309 | ␉printf("Press a key to continue...\n");␊ |
310 | ␉getchar(); // replace getchar() by pause() were useful.␊ |
311 | }␊ |
312 | |