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 "boot.h"␊ |
50 | ␊ |
51 | extern int␉vprf(const char * fmt, va_list ap);␊ |
52 | ␊ |
53 | bool gVerboseMode;␊ |
54 | bool gErrors;␊ |
55 | ␊ |
56 | /* Kabyl: BooterLog */␊ |
57 | //Azi: Doubled log available size.␊ |
58 | // 64kb are not enough to hold the full log while booting with -f argument (ignore caches).␊ |
59 | // It also seems to fix some reported problems while booting with the mentioned argument.␊ |
60 | // Note: 96kb are enough to hold full log, booting with -f; even so, this depends on how much␊ |
61 | // we "play" at the boot prompt, with what patches we're playing and how much they print to the log,␊ |
62 | // kexts loaded, etc...␊ |
63 | // Please remove this comment when this gets checked by a "true" dev.␊ |
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 {␊ |
71 | char * str;␊ |
72 | char * last_str;␊ |
73 | };␊ |
74 | ␊ |
75 | static void sputc(int c, struct putc_info * pi)␊ |
76 | {␊ |
77 | ␉if (pi->last_str)␊ |
78 | ␉␉if (pi->str == pi->last_str)␊ |
79 | ␉␉{␊ |
80 | ␉␉␉*(pi->str) = '\0';␊ |
81 | ␉␉␉return;␊ |
82 | ␉␉}␊ |
83 | ␉*(pi->str)++ = c;␊ |
84 | }␊ |
85 | ␊ |
86 | void initBooterLog(void)␊ |
87 | {␊ |
88 | ␉msgbuf = malloc(BOOTER_LOG_SIZE);␊ |
89 | ␉bzero(msgbuf, BOOTER_LOG_SIZE);␊ |
90 | ␉cursor = msgbuf;␊ |
91 | }␊ |
92 | ␊ |
93 | void msglog(const char * fmt, ...)␊ |
94 | {␊ |
95 | ␉va_list ap;␊ |
96 | ␉struct putc_info pi;␊ |
97 | ␉␊ |
98 | ␉if (!msgbuf)␊ |
99 | ␉␉return;␊ |
100 | ␉␊ |
101 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
102 | ␉␉return;␊ |
103 | ␉␊ |
104 | ␉va_start(ap, fmt);␊ |
105 | ␉pi.str = cursor;␊ |
106 | ␉pi.last_str = 0;␊ |
107 | ␉prf(fmt, ap, sputc, &pi);␊ |
108 | ␉va_end(ap);␊ |
109 | ␉cursor += strlen((char *)cursor);␊ |
110 | }␊ |
111 | ␊ |
112 | void setupBooterLog(void)␊ |
113 | {␊ |
114 | ␉if (!msgbuf)␊ |
115 | ␉␉return;␊ |
116 | ␉␊ |
117 | ␉Node *node = DT__FindNode("/", false);␊ |
118 | ␉if (node)␊ |
119 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
120 | }␊ |
121 | /* Kabyl: !BooterLog */␊ |
122 | ␊ |
123 | ␊ |
124 | /*␊ |
125 | * write one character to console␊ |
126 | */␊ |
127 | void putchar(int c)␊ |
128 | {␊ |
129 | ␉if ( c == '\t' )␊ |
130 | ␉{␊ |
131 | ␉␉for (c = 0; c < 8; c++) putc(' ');␊ |
132 | ␉␉return;␊ |
133 | ␉}␊ |
134 | ␉␊ |
135 | ␉if ( c == '\n' )␊ |
136 | {␊ |
137 | ␉␉putc('\r');␊ |
138 | }␊ |
139 | ␉␊ |
140 | ␉putc(c);␊ |
141 | }␊ |
142 | ␊ |
143 | int getc()␊ |
144 | {␊ |
145 | int c = bgetc();␊ |
146 | ␉␊ |
147 | if ((c & 0xff) == 0)␊ |
148 | return c;␊ |
149 | else␊ |
150 | return (c & 0xff);␊ |
151 | }␊ |
152 | ␊ |
153 | // Read and echo a character from console. This doesn't echo backspace␊ |
154 | // since that screws up higher level handling␊ |
155 | ␊ |
156 | int getchar()␊ |
157 | {␊ |
158 | ␉register int c = getc();␊ |
159 | ␉␊ |
160 | ␉if ( c == '\r' ) c = '\n';␊ |
161 | ␉␊ |
162 | ␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
163 | ␉␊ |
164 | ␉return (c);␊ |
165 | }␊ |
166 | ␊ |
167 | int printf(const char * fmt, ...)␊ |
168 | {␊ |
169 | va_list ap;␊ |
170 | ␉va_start(ap, fmt);␊ |
171 | if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))␊ |
172 | {␊ |
173 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
174 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
175 | ␉␉else␊ |
176 | ␉␉␉vprf(fmt, ap);␊ |
177 | ␉} else {␊ |
178 | ␉␉if (bootArgsSnow->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 | ␉␉␉return 0;␊ |
190 | ␉␉␊ |
191 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
192 | ␉␉␉return 0;␊ |
193 | ␉␉pi.str = cursor;␊ |
194 | ␉␉pi.last_str = 0;␊ |
195 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
196 | ␉␉cursor += strlen((char *)cursor);␊ |
197 | ␉}␊ |
198 | ␉␊ |
199 | ␉va_end(ap);␊ |
200 | return 0;␊ |
201 | }␊ |
202 | ␊ |
203 | int verbose(const char * fmt, ...)␊ |
204 | {␊ |
205 | va_list ap;␊ |
206 | ␊ |
207 | ␉va_start(ap, fmt);␊ |
208 | if (gVerboseMode)␊ |
209 | {␊ |
210 | if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))␊ |
211 | {␊ |
212 | ␉␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
213 | ␉␉␉␉prf(fmt, ap, putchar, 0);␊ |
214 | ␉␉␉else␊ |
215 | ␉␉␉␉vprf(fmt, ap);␊ |
216 | ␉␉} else {␊ |
217 | ␉␉␉if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)␊ |
218 | ␉␉␉␉prf(fmt, ap, putchar, 0);␊ |
219 | ␉␉␉else␊ |
220 | ␉␉␉␉vprf(fmt, ap);␊ |
221 | ␉␉}␊ |
222 | }␊ |
223 | ␉␊ |
224 | ␉{␊ |
225 | ␉␉/* Kabyl: BooterLog */␊ |
226 | ␉␉struct putc_info pi;␊ |
227 | ␉␉␊ |
228 | ␉␉if (!msgbuf)␊ |
229 | ␉␉␉return 0;␊ |
230 | ␉␉␊ |
231 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
232 | ␉␉␉return 0;␊ |
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 ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))␊ |
249 | {␊ |
250 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
251 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
252 | ␉␉else␊ |
253 | ␉␉␉vprf(fmt, ap);␊ |
254 | ␉} else {␊ |
255 | ␉␉if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)␊ |
256 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
257 | ␉␉else␊ |
258 | ␉␉␉vprf(fmt, ap);␊ |
259 | ␉}␊ |
260 | ␉va_end(ap);␊ |
261 | return(0);␊ |
262 | }␊ |
263 | ␊ |
264 | void stop(const char * fmt, ...)␊ |
265 | {␊ |
266 | ␉va_list ap;␊ |
267 | ␉␊ |
268 | ␉printf("\n");␊ |
269 | ␉va_start(ap, fmt);␊ |
270 | if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))␊ |
271 | {␊ |
272 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
273 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
274 | ␉␉else␊ |
275 | ␉␉␉vprf(fmt, ap);␊ |
276 | ␉} else {␊ |
277 | ␉␉if (bootArgsSnow->Video.v_display == VGA_TEXT_MODE)␊ |
278 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
279 | ␉␉else␊ |
280 | ␉␉␉vprf(fmt, ap);␊ |
281 | ␉}␊ |
282 | ␉va_end(ap);␊ |
283 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
284 | ␉halt();␊ |
285 | ␉while (1);␊ |
286 | }␊ |
287 | ␊ |
288 | /** Print a "Press a key to continue..." message and wait for a key press. */␊ |
289 | void pause() ␊ |
290 | {␊ |
291 | printf("Press a key to continue...");␊ |
292 | getc();␊ |
293 | }␊ |
294 | |