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", "Chimera 4.1.0 Branch of Chameleon" " [" 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 | ␉␉return;␊ |
104 | ␉}␊ |
105 | ␊ |
106 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {␊ |
107 | ␉␉return;␊ |
108 | ␉}␊ |
109 | ␊ |
110 | ␉va_start(ap, fmt);␊ |
111 | ␉pi.str = cursor;␊ |
112 | ␉pi.last_str = 0;␊ |
113 | ␉prf(fmt, ap, sputc, &pi);␊ |
114 | ␉va_end(ap);␊ |
115 | ␉cursor += strlen((char *)cursor);␊ |
116 | }␊ |
117 | ␊ |
118 | void setupBooterLog(void)␊ |
119 | {␊ |
120 | ␉if (!msgbuf) {␊ |
121 | ␉␉return;␊ |
122 | ␉}␊ |
123 | ␊ |
124 | ␉Node *node = DT__FindNode("/", false);␊ |
125 | ␉if (node)␊ |
126 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
127 | }␊ |
128 | /* Kabyl: !BooterLog */␊ |
129 | ␊ |
130 | /*␊ |
131 | * write one character to console␊ |
132 | */␊ |
133 | int putchar(int c)␊ |
134 | {␊ |
135 | ␉if ( c == '\t' ) {␊ |
136 | ␉␉for (c = 0; c < 8; c++) bios_putchar(' ');␊ |
137 | ␉␉return c;␊ |
138 | ␉}␊ |
139 | ␊ |
140 | ␉if ( c == '\n' ) {␊ |
141 | ␉␉bios_putchar('\r');␊ |
142 | ␉}␊ |
143 | ␊ |
144 | ␉bios_putchar(c);␊ |
145 | ␊ |
146 | ␉return c;␊ |
147 | }␊ |
148 | ␊ |
149 | int getc()␊ |
150 | {␊ |
151 | ␉int c = bgetc();␊ |
152 | ␊ |
153 | ␉if ((c & 0xff) == 0) {␊ |
154 | ␉␉return c;␊ |
155 | ␉} else {␊ |
156 | ␉␉return (c & 0xff);␊ |
157 | ␉}␊ |
158 | }␊ |
159 | ␊ |
160 | // Read and echo a character from console. This doesn't echo backspace␊ |
161 | // since that screws up higher level handling␊ |
162 | ␊ |
163 | int getchar()␊ |
164 | {␊ |
165 | ␉register int c = getc();␊ |
166 | ␊ |
167 | //␉if ( c == '\r' ) c = '\n';␊ |
168 | ␊ |
169 | //␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
170 | ␊ |
171 | ␉return (c);␊ |
172 | }␊ |
173 | ␊ |
174 | int printf(const char * fmt, ...)␊ |
175 | {␊ |
176 | ␉va_list ap;␊ |
177 | ␉va_start(ap, fmt);␊ |
178 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
179 | ␉␉prf(fmt, ap, putchar, 0);␊ |
180 | ␉} else {␊ |
181 | ␉␉vprf(fmt, ap);␊ |
182 | ␉}␊ |
183 | ␊ |
184 | ␉{␊ |
185 | ␉␉// Kabyl: BooterLog␊ |
186 | ␉␉struct putc_info pi;␊ |
187 | ␊ |
188 | ␉␉if (!msgbuf)␊ |
189 | {␊ |
190 | ␉␉␉return 0;␊ |
191 | ␉␉}␊ |
192 | ␊ |
193 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
194 | {␊ |
195 | ␉␉␉return 0;␊ |
196 | ␉␉}␊ |
197 | ␉␉pi.str = cursor;␊ |
198 | ␉␉pi.last_str = 0;␊ |
199 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
200 | ␉␉cursor += strlen((char *)cursor);␊ |
201 | ␉}␊ |
202 | ␊ |
203 | ␉va_end(ap);␊ |
204 | ␉return 0;␊ |
205 | }␊ |
206 | ␊ |
207 | int verbose(const char * fmt, ...)␊ |
208 | {␊ |
209 | ␉va_list ap;␊ |
210 | ␊ |
211 | ␉va_start(ap, fmt);␊ |
212 | ␉if (gVerboseMode) {␊ |
213 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
214 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
215 | ␉␉} else {␊ |
216 | ␉␉␉vprf(fmt, ap);␊ |
217 | ␉␉}␊ |
218 | ␉}␊ |
219 | ␊ |
220 | ␉{␊ |
221 | ␉␉// Kabyl: BooterLog␊ |
222 | ␉␉struct putc_info pi;␊ |
223 | ␊ |
224 | ␉␉if (!msgbuf)␊ |
225 | {␊ |
226 | ␉␉␉return 0;␊ |
227 | ␉␉}␊ |
228 | ␊ |
229 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
230 | {␊ |
231 | ␉␉␉return 0;␊ |
232 | ␉␉}␊ |
233 | ␉␉pi.str = cursor;␊ |
234 | ␉␉pi.last_str = 0;␊ |
235 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
236 | ␉␉cursor += strlen((char *)cursor);␊ |
237 | ␉}␊ |
238 | ␊ |
239 | ␉va_end(ap);␊ |
240 | ␉return(0);␊ |
241 | }␊ |
242 | ␊ |
243 | int error(const char * fmt, ...)␊ |
244 | {␊ |
245 | ␉va_list ap;␊ |
246 | ␉gErrors = true;␊ |
247 | ␉va_start(ap, fmt);␊ |
248 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
249 | ␉␉prf(fmt, ap, putchar, 0);␊ |
250 | ␉} else {␊ |
251 | ␉␉vprf(fmt, ap);␊ |
252 | ␉}␊ |
253 | ␊ |
254 | {␊ |
255 | // Kabyl: BooterLog␊ |
256 | struct putc_info pi;␊ |
257 | ␊ |
258 | if (!msgbuf) {␊ |
259 | return 0;␊ |
260 | }␊ |
261 | ␊ |
262 | if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {␊ |
263 | return 0;␊ |
264 | }␊ |
265 | ␊ |
266 | pi.str = cursor;␊ |
267 | pi.last_str = 0;␊ |
268 | prf(fmt, ap, sputc, &pi);␊ |
269 | cursor += strlen((char *)cursor);␊ |
270 | }␊ |
271 | ␊ |
272 | ␉va_end(ap);␊ |
273 | ␉return(0);␊ |
274 | }␊ |
275 | ␊ |
276 | void stop(const char * fmt, ...)␊ |
277 | {␊ |
278 | ␉va_list ap;␊ |
279 | ␊ |
280 | ␉printf("\n");␊ |
281 | ␉va_start(ap, fmt);␊ |
282 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
283 | ␉␉prf(fmt, ap, putchar, 0);␊ |
284 | ␉} else {␊ |
285 | ␉␉vprf(fmt, ap);␊ |
286 | ␉}␊ |
287 | ␉va_end(ap);␊ |
288 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
289 | ␉halt();␊ |
290 | ␉while (1);␊ |
291 | }␊ |
292 | ␊ |
293 | /** Print a "Press a key to continue..." message and wait for a key press. */␊ |
294 | void pause() ␊ |
295 | {␊ |
296 | printf("Press a key to continue...\n");␊ |
297 | ␉getchar(); // replace getchar() by pause() were useful.␊ |
298 | }␊ |
299 | |