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 | // Bungo:␊ |
71 | typedef struct {␊ |
72 | uint16_t year;␊ |
73 | uint8_t mon;␊ |
74 | uint8_t day;␊ |
75 | uint8_t hour;␊ |
76 | uint8_t mins;␊ |
77 | uint8_t secs;␊ |
78 | uint8_t dlight;␊ |
79 | } datetime_t;␊ |
80 | static datetime_t datetime;␊ |
81 | ␊ |
82 | struct putc_info //Azi: exists on gui.c & printf.c␊ |
83 | {␊ |
84 | ␉char * str;␊ |
85 | ␉char * last_str;␊ |
86 | };␊ |
87 | ␊ |
88 | static int␊ |
89 | sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
90 | {␊ |
91 | ␉if (pi->last_str)␊ |
92 | ␉if (pi->str == pi->last_str)␊ |
93 | ␉{␊ |
94 | ␉␉*(pi->str) = '\0';␊ |
95 | ␉␉return 0;␊ |
96 | ␉}␊ |
97 | ␉*(pi->str)++ = c;␊ |
98 | ␉return c;␊ |
99 | }␊ |
100 | ␊ |
101 | uint64_t getRTCdatetime() // 0xYYYYMMDDHHMMSS0L in decimal␊ |
102 | {␊ |
103 | biosBuf_t bb;␊ |
104 | ␊ |
105 | bb.intno = 0x1a;␊ |
106 | ␉bb.eax.r.h = 0x04; // get RTC date␊ |
107 | //bb.flags.cf = 0;␊ |
108 | bios(&bb);␊ |
109 | if (bb.flags.cf) return 0;␊ |
110 | datetime.year = (bb.ecx.r.h >> 4) * 1000 + (bb.ecx.r.h & 0x0F) * 100 + (bb.ecx.r.l >> 4) * 10 + (bb.ecx.r.l & 0x0F) * 1;␊ |
111 | datetime.mon = (bb.edx.r.h >> 4) * 10 + (bb.edx.r.h & 0x0F) * 1;␊ |
112 | datetime.day = (bb.edx.r.l >> 4) * 10 + (bb.edx.r.l & 0x0F) * 1;␊ |
113 | ␊ |
114 | bb.intno = 0x1a;␊ |
115 | ␉bb.eax.r.h = 0x02; // get RTC time␊ |
116 | //bb.flags.cf = 0;␊ |
117 | ␉bios(&bb);␊ |
118 | if (bb.flags.cf) return 0;␊ |
119 | datetime.dlight = bb.edx.r.l & 0x0F;␊ |
120 | datetime.hour = (bb.ecx.r.h >> 4) * 10 + (bb.ecx.r.h & 0x0F) * 1;␊ |
121 | datetime.mins = (bb.ecx.r.l >> 4) * 10 + (bb.ecx.r.l & 0x0F) * 1;␊ |
122 | datetime.secs = (bb.edx.r.h >> 4) * 10 + (bb.edx.r.h & 0x0F) * 1;␊ |
123 | return *(uint64_t *)&datetime;␊ |
124 | }␊ |
125 | ␊ |
126 | void initBooterLog(void)␊ |
127 | {␊ |
128 | ␉msgbuf = malloc(BOOTER_LOG_SIZE);␊ |
129 | ␉bzero(msgbuf, BOOTER_LOG_SIZE);␊ |
130 | ␉cursor = msgbuf;␊ |
131 | ␉verbose("%s\n", "Chameleon v" I386BOOT_CHAMELEONVERSION " (Bungo branch) r" I386BOOT_CHAMELEONREVISION " [" I386BOOT_BUILDDATE "]");␊ |
132 | getRTCdatetime();␊ |
133 | verbose("Logging started: %04d/%02d/%02d, %02d:%02d:%02d (+/- offset)\n", datetime.year, datetime.mon, datetime.day, datetime.hour, datetime.mins, datetime.secs);␊ |
134 | }␊ |
135 | ␊ |
136 | int msglog(const char * fmt, ...)␊ |
137 | {␊ |
138 | ␉va_list ap;␊ |
139 | ␉struct putc_info pi;␊ |
140 | ␊ |
141 | ␉if (!msgbuf) {␊ |
142 | ␉␉return 0;␊ |
143 | ␉}␊ |
144 | ␊ |
145 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {␊ |
146 | ␉␉return 0;␊ |
147 | ␉}␊ |
148 | ␊ |
149 | ␉va_start(ap, fmt);␊ |
150 | ␉pi.str = cursor;␊ |
151 | ␉pi.last_str = 0;␊ |
152 | ␉prf(fmt, ap, sputc, &pi);␊ |
153 | ␉va_end(ap);␊ |
154 | ␉cursor += strlen((char *)cursor);␊ |
155 | ␊ |
156 | return 0;␊ |
157 | }␊ |
158 | ␊ |
159 | void setupBooterLog(void)␊ |
160 | {␊ |
161 | ␉if (!msgbuf) {␊ |
162 | ␉␉return;␊ |
163 | ␉}␊ |
164 | ␊ |
165 | ␉Node *node = DT__FindNode("/", false);␊ |
166 | ␉if (node)␊ |
167 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
168 | }␊ |
169 | /* Kabyl: !BooterLog */␊ |
170 | ␊ |
171 | /*␊ |
172 | * write one character to console␊ |
173 | */␊ |
174 | int putchar(int c)␊ |
175 | {␊ |
176 | ␉if ( c == '\t' ) {␊ |
177 | ␉␉for (c = 0; c < 8; c++) bios_putchar(' ');␊ |
178 | ␉␉return c;␊ |
179 | ␉}␊ |
180 | ␊ |
181 | ␉if ( c == '\n' ) {␊ |
182 | ␉␉bios_putchar('\r');␊ |
183 | ␉}␊ |
184 | ␊ |
185 | ␉bios_putchar(c);␊ |
186 | ␊ |
187 | ␉return c;␊ |
188 | }␊ |
189 | ␊ |
190 | int getc()␊ |
191 | {␊ |
192 | ␉int c = bgetc();␊ |
193 | ␊ |
194 | ␉if ((c & 0xff) == 0) {␊ |
195 | ␉␉return c;␊ |
196 | ␉} else {␊ |
197 | ␉␉return (c & 0xff);␊ |
198 | ␉}␊ |
199 | }␊ |
200 | ␊ |
201 | // Read and echo a character from console. This doesn't echo backspace␊ |
202 | // since that screws up higher level handling␊ |
203 | ␊ |
204 | int getchar()␊ |
205 | {␊ |
206 | ␉register int c = getc();␊ |
207 | ␊ |
208 | //␉if ( c == '\r' ) c = '\n';␊ |
209 | ␊ |
210 | //␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
211 | ␊ |
212 | ␉return (c);␊ |
213 | }␊ |
214 | ␊ |
215 | int printf(const char * fmt, ...)␊ |
216 | {␊ |
217 | ␉va_list ap;␊ |
218 | ␊ |
219 | ␉va_start(ap, fmt);␊ |
220 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
221 | ␉{␊ |
222 | ␉␉prf(fmt, ap, putchar, 0);␊ |
223 | ␉}␊ |
224 | ␉else␊ |
225 | ␉{␊ |
226 | ␉␉vprf(fmt, ap);␊ |
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 verbose(const char * fmt, ...)␊ |
251 | {␊ |
252 | ␉va_list ap;␊ |
253 | ␊ |
254 | ␉va_start(ap, fmt);␊ |
255 | ␉if (gVerboseMode)␊ |
256 | ␉{␊ |
257 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
258 | ␉␉{␊ |
259 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
260 | ␉␉}␊ |
261 | ␉␉else␊ |
262 | ␉␉{␊ |
263 | ␉␉␉vprf(fmt, ap);␊ |
264 | ␉␉}␊ |
265 | ␉}␊ |
266 | ␊ |
267 | ␉{␊ |
268 | ␉␉// Kabyl: BooterLog␊ |
269 | ␉␉struct putc_info pi;␊ |
270 | ␊ |
271 | ␉␉if (!msgbuf) {␊ |
272 | ␉␉␉return 0;␊ |
273 | ␉␉}␊ |
274 | ␊ |
275 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {␊ |
276 | ␉␉␉return 0;␊ |
277 | ␉␉}␊ |
278 | ␉␉pi.str = cursor;␊ |
279 | ␉␉pi.last_str = 0;␊ |
280 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
281 | ␉␉cursor += strlen((char *)cursor);␊ |
282 | ␉}␊ |
283 | ␊ |
284 | ␉va_end(ap);␊ |
285 | ␉return(0);␊ |
286 | }␊ |
287 | ␊ |
288 | int error(const char * fmt, ...)␊ |
289 | {␊ |
290 | ␉va_list ap;␊ |
291 | ␉gErrors = true;␊ |
292 | ␉va_start(ap, fmt);␊ |
293 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
294 | ␉{␊ |
295 | ␉␉prf(fmt, ap, putchar, 0);␊ |
296 | ␉}␊ |
297 | ␉else␊ |
298 | ␉{␊ |
299 | ␉␉vprf(fmt, ap);␊ |
300 | ␉}␊ |
301 | ␊ |
302 | ␉␉// Kabyl: BooterLog␊ |
303 | ␉␉struct putc_info pi;␊ |
304 | ␊ |
305 | ␉if (!msgbuf)␊ |
306 | ␉{␊ |
307 | ␉␉␉return 0;␊ |
308 | ␉␉}␊ |
309 | ␊ |
310 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
311 | ␉{␊ |
312 | ␉␉␉return 0;␊ |
313 | ␉␉}␊ |
314 | ␊ |
315 | ␉␉pi.str = cursor;␊ |
316 | ␉␉pi.last_str = 0;␊ |
317 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
318 | ␉␉cursor += strlen((char *)cursor);␊ |
319 | ␊ |
320 | ␉va_end(ap);␊ |
321 | ␉return(0);␊ |
322 | }␊ |
323 | ␊ |
324 | void stop(const char * fmt, ...)␊ |
325 | {␊ |
326 | ␉va_list ap;␊ |
327 | ␊ |
328 | ␉printf("\n");␊ |
329 | ␉va_start(ap, fmt);␊ |
330 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
331 | ␉{␊ |
332 | ␉␉prf(fmt, ap, putchar, 0);␊ |
333 | ␉}␊ |
334 | ␉else␊ |
335 | ␉{␊ |
336 | ␉␉vprf(fmt, ap);␊ |
337 | ␉}␊ |
338 | ␉va_end(ap);␊ |
339 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
340 | ␉halt();␊ |
341 | ␉while (1);␊ |
342 | }␊ |
343 | ␊ |
344 | /** Print user message and a "Press a key to continue..." message and wait for a key press. */␊ |
345 | void pause(const char * fmt, ...) // replace getchar() by pause() were useful.␊ |
346 | {␊ |
347 | va_list ap;␊ |
348 | ␊ |
349 | ␉va_start(ap, fmt);␊ |
350 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
351 | ␉␉prf(fmt, ap, putchar, 0);␊ |
352 | ␉} else {␊ |
353 | ␉␉vprf(fmt, ap);␊ |
354 | ␉}␊ |
355 | ␉va_end(ap);␊ |
356 | ␊ |
357 | printf("Press a key to continue...");␊ |
358 | ␉getchar();␊ |
359 | printf("\n");␊ |
360 | }␊ |
361 | |