1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * ␊ |
5 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
6 | * Reserved. This file contains Original Code and/or Modifications of␊ |
7 | * Original Code as defined in and that are subject to the Apple Public␊ |
8 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
9 | * except in compliance with the License. Please obtain a copy of the␊ |
10 | * License at http://www.apple.com/publicsource and read it before using␊ |
11 | * this file.␊ |
12 | * ␊ |
13 | * The Original Code and all software distributed under the License are␊ |
14 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
17 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
18 | * License for the specific language governing rights and limitations␊ |
19 | * under the License.␊ |
20 | * ␊ |
21 | * ␊ |
22 | * Mach Operating System␊ |
23 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
24 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
25 | * All rights reserved. The CMU software License Agreement specifies␊ |
26 | * the terms and conditions for use and redistribution.␊ |
27 | *␊ |
28 | * ␉␉␉INTEL CORPORATION PROPRIETARY INFORMATION␊ |
29 | *␊ |
30 | *␉This software is supplied under the terms of a license agreement or ␊ |
31 | *␉nondisclosure agreement with Intel Corporation and may not be copied ␊ |
32 | *␉nor disclosed except in accordance with the terms of that agreement.␊ |
33 | *␊ |
34 | *␉Copyright 1988, 1989 Intel Corporation␊ |
35 | *␊ |
36 | *␊ |
37 | * Copyright 1993 NeXT, Inc.␊ |
38 | * All rights reserved.␊ |
39 | */␊ |
40 | ␊ |
41 | #include "libsaio.h"␊ |
42 | #include "bootstruct.h"␊ |
43 | #include <vers.h>␊ |
44 | ␊ |
45 | extern int␉vprf(const char * fmt, va_list ap);␊ |
46 | ␊ |
47 | bool gVerboseMode;␊ |
48 | bool gErrors;␊ |
49 | ␊ |
50 | /*␊ |
51 | * Azi: Doubled available log size; this seems to fix some hangs and instant reboots caused by␊ |
52 | * booting with -f (ignore caches). 96kb are enough to hold full log, booting with -f; even so,␊ |
53 | * this depends on how much we "play" at the boot prompt and with what patches we're playing,␊ |
54 | * depending on how much they print to the log.␊ |
55 | *␉␊ |
56 | * Kabyl: BooterLog␊ |
57 | */␊ |
58 | #define BOOTER_LOG_SIZE␉(128 * 1024)␊ |
59 | #define SAFE_LOG_SIZE␉134␊ |
60 | ␊ |
61 | char *msgbuf = 0;␊ |
62 | char *cursor = 0;␊ |
63 | ␊ |
64 | struct putc_info //Azi: exists on gui.c & printf.c␊ |
65 | {␊ |
66 | ␉char * str;␊ |
67 | ␉char * last_str;␊ |
68 | };␊ |
69 | ␊ |
70 | static int␊ |
71 | sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
72 | {␊ |
73 | ␉if (pi->last_str)␊ |
74 | ␉if (pi->str == pi->last_str)␊ |
75 | ␉{␊ |
76 | ␉␉*(pi->str) = '\0';␊ |
77 | ␉␉return 0;␊ |
78 | ␉}␊ |
79 | ␉*(pi->str)++ = c;␊ |
80 | ␉return c;␊ |
81 | }␊ |
82 | ␊ |
83 | void initBooterLog(void)␊ |
84 | {␊ |
85 | ␉msgbuf = malloc(BOOTER_LOG_SIZE);␊ |
86 | ␉bzero(msgbuf, BOOTER_LOG_SIZE);␊ |
87 | ␉cursor = msgbuf;␊ |
88 | ␉msglog("%s\n", "Enoch (r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");␊ |
89 | }␊ |
90 | ␊ |
91 | void msglog(const char * fmt, ...)␊ |
92 | {␊ |
93 | ␉va_list ap;␊ |
94 | ␉struct putc_info pi;␊ |
95 | ␊ |
96 | ␉if (!msgbuf)␊ |
97 | ␉{␊ |
98 | ␉␉return;␊ |
99 | ␉}␊ |
100 | ␊ |
101 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
102 | ␉{␊ |
103 | ␉␉return;␊ |
104 | ␉}␊ |
105 | ␊ |
106 | ␉va_start(ap, fmt);␊ |
107 | ␉pi.str = cursor;␊ |
108 | ␉pi.last_str = 0;␊ |
109 | ␉prf(fmt, ap, sputc, &pi);␊ |
110 | ␉va_end(ap);␊ |
111 | ␉cursor += strlen((char *)cursor);␊ |
112 | }␊ |
113 | ␊ |
114 | void setupBooterLog(void)␊ |
115 | {␊ |
116 | ␉if (!msgbuf)␊ |
117 | ␉{␊ |
118 | ␉␉return;␊ |
119 | ␉}␊ |
120 | ␊ |
121 | ␉Node *node = DT__FindNode("/", false);␊ |
122 | ␉if (node)␊ |
123 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
124 | }␊ |
125 | /* Kabyl: !BooterLog */␊ |
126 | ␊ |
127 | /*␊ |
128 | * write one character to console␊ |
129 | */␊ |
130 | int putchar(int c)␊ |
131 | {␊ |
132 | ␉if ( c == '\t' )␊ |
133 | ␉{␊ |
134 | ␉␉for (c = 0; c < 8; c++) bios_putchar(' ');␊ |
135 | ␉␉return c;␊ |
136 | ␉}␊ |
137 | ␊ |
138 | ␉if ( c == '\n' )␊ |
139 | ␉{␊ |
140 | ␉␉bios_putchar('\r');␊ |
141 | ␉}␊ |
142 | ␊ |
143 | ␉bios_putchar(c);␊ |
144 | ␊ |
145 | ␉return c;␊ |
146 | }␊ |
147 | ␊ |
148 | int getc()␊ |
149 | {␊ |
150 | ␉int c = bgetc();␊ |
151 | ␊ |
152 | ␉if ((c & 0xff) == 0)␊ |
153 | ␉{␊ |
154 | ␉␉return c;␊ |
155 | ␉}␊ |
156 | ␉else␊ |
157 | ␉{␊ |
158 | ␉␉return (c & 0xff);␊ |
159 | ␉}␊ |
160 | }␊ |
161 | ␊ |
162 | // Read and echo a character from console. This doesn't echo backspace␊ |
163 | // since that screws up higher level handling␊ |
164 | ␊ |
165 | int getchar()␊ |
166 | {␊ |
167 | ␉register int c = getc();␊ |
168 | ␊ |
169 | //␉if ( c == '\r' ) c = '\n';␊ |
170 | ␊ |
171 | //␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
172 | ␉␊ |
173 | ␉return (c);␊ |
174 | }␊ |
175 | ␊ |
176 | int printf(const char * fmt, ...)␊ |
177 | {␊ |
178 | ␉va_list ap;␊ |
179 | ␉va_start(ap, fmt);␊ |
180 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
181 | ␉{␊ |
182 | ␉␉prf(fmt, ap, putchar, 0);␊ |
183 | ␉}␊ |
184 | ␉else␊ |
185 | ␉{␊ |
186 | ␉␉vprf(fmt, ap);␊ |
187 | ␉}␊ |
188 | ␊ |
189 | ␉{␊ |
190 | ␉␉/* Kabyl: BooterLog */␊ |
191 | ␉␉struct putc_info pi;␊ |
192 | ␊ |
193 | ␉␉if (!msgbuf)␊ |
194 | ␉␉␉return 0;␊ |
195 | ␊ |
196 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
197 | ␉␉␉return 0;␊ |
198 | ␉␉pi.str = cursor;␊ |
199 | ␉␉pi.last_str = 0;␊ |
200 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
201 | ␉␉cursor += strlen((char *)cursor);␊ |
202 | ␉}␊ |
203 | ␊ |
204 | ␉va_end(ap);␊ |
205 | ␉return 0;␊ |
206 | }␊ |
207 | ␊ |
208 | int verbose(const char * fmt, ...)␊ |
209 | {␊ |
210 | va_list ap;␊ |
211 | ␊ |
212 | ␉va_start(ap, fmt);␊ |
213 | ␉if (gVerboseMode)␊ |
214 | ␉{␊ |
215 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
216 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
217 | ␉␉else␊ |
218 | ␉␉␉vprf(fmt, ap);␊ |
219 | ␉}␊ |
220 | ␊ |
221 | ␉{␊ |
222 | ␉␉/* Kabyl: BooterLog */␊ |
223 | ␉␉struct putc_info pi;␊ |
224 | ␊ |
225 | ␉␉if (!msgbuf)␊ |
226 | ␉␉{␊ |
227 | ␉␉␉return 0;␊ |
228 | ␉␉}␊ |
229 | ␊ |
230 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
231 | ␉␉{␊ |
232 | ␉␉␉return 0;␊ |
233 | ␉␉}␊ |
234 | ␉␉pi.str = cursor;␊ |
235 | ␉␉pi.last_str = 0;␊ |
236 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
237 | ␉␉cursor += strlen((char *)cursor);␊ |
238 | ␉}␊ |
239 | ␊ |
240 | ␉va_end(ap);␊ |
241 | ␉return(0);␊ |
242 | }␊ |
243 | ␊ |
244 | int error(const char * fmt, ...)␊ |
245 | {␊ |
246 | ␉va_list ap;␊ |
247 | ␉gErrors = true;␊ |
248 | ␉va_start(ap, fmt);␊ |
249 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
250 | ␉{␊ |
251 | ␉␉prf(fmt, ap, putchar, 0);␊ |
252 | ␉}␊ |
253 | ␉else␊ |
254 | ␉{␊ |
255 | ␉␉vprf(fmt, ap);␊ |
256 | ␉}␊ |
257 | ␉va_end(ap);␊ |
258 | ␉return(0);␊ |
259 | }␊ |
260 | ␊ |
261 | void stop(const char * fmt, ...)␊ |
262 | {␊ |
263 | ␉va_list ap;␊ |
264 | ␊ |
265 | ␉printf("\n");␊ |
266 | ␉va_start(ap, fmt);␊ |
267 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
268 | ␉{␊ |
269 | ␉␉prf(fmt, ap, putchar, 0);␊ |
270 | ␉}␊ |
271 | ␉else␊ |
272 | ␉{␊ |
273 | ␉␉vprf(fmt, ap);␊ |
274 | ␉}␊ |
275 | ␉va_end(ap);␊ |
276 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
277 | ␉halt();␊ |
278 | ␉while (1);␊ |
279 | }␊ |
280 | ␊ |
281 | /** Print a "Press a key to continue..." message and wait for a key press. */␊ |
282 | void pause() ␊ |
283 | {␊ |
284 | printf("Press a key to continue...\n");␊ |
285 | ␉getchar(); // replace getchar() by pause() were useful.␊ |
286 | }␊ |
287 | |