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