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 | ␊ |
50 | extern int␉vprf(const char * fmt, va_list ap);␊ |
51 | ␊ |
52 | bool gVerboseMode;␊ |
53 | bool gErrors;␊ |
54 | ␊ |
55 | /** Kabyl: BooterLog␊ |
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 | **/ //Azi: closing **/ alows colapse/expand... is this desirable?? colapsing an entire page␊ |
62 | ␉ // will also colapse comments....␊ |
63 | #define BOOTER_LOG_SIZE␉(128 * 1024)␊ |
64 | #define SAFE_LOG_SIZE␉134␊ |
65 | ␊ |
66 | char *msgbuf = 0;␊ |
67 | char *cursor = 0;␊ |
68 | ␊ |
69 | struct putc_info //Azi: same as below␊ |
70 | {␊ |
71 | char * str;␊ |
72 | char * last_str;␊ |
73 | };␊ |
74 | ␊ |
75 | static int␊ |
76 | sputc(int c, struct putc_info * pi) //Azi: exists on printf.c & gui.c␊ |
77 | {␊ |
78 | ␉if (pi->last_str)␊ |
79 | ␉if (pi->str == pi->last_str)␊ |
80 | ␉{␊ |
81 | ␉␉*(pi->str) = '\0';␊ |
82 | ␉␉return 0;␊ |
83 | ␉}␊ |
84 | ␉*(pi->str)++ = c;␊ |
85 | return c;␊ |
86 | }␊ |
87 | ␊ |
88 | void initBooterLog(void)␊ |
89 | {␊ |
90 | ␉msgbuf = malloc(BOOTER_LOG_SIZE);␊ |
91 | ␉bzero(msgbuf, BOOTER_LOG_SIZE);␊ |
92 | ␉cursor = msgbuf;␊ |
93 | }␊ |
94 | ␊ |
95 | void msglog(const char * fmt, ...)␊ |
96 | {␊ |
97 | ␉va_list ap;␊ |
98 | ␉struct putc_info pi;␊ |
99 | ␊ |
100 | ␉if (!msgbuf)␊ |
101 | ␉␉return;␊ |
102 | ␊ |
103 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
104 | ␉␉return;␊ |
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 | ␉␉return;␊ |
118 | ␊ |
119 | ␉Node *node = DT__FindNode("/", false);␊ |
120 | ␉if (node)␊ |
121 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
122 | }␊ |
123 | /* Kabyl: !BooterLog */␊ |
124 | ␊ |
125 | /*␊ |
126 | * write one character to console␊ |
127 | */␊ |
128 | int putchar(int c)␊ |
129 | {␊ |
130 | ␉if ( c == '\t' )␊ |
131 | ␉{␊ |
132 | ␉␉for (c = 0; c < 8; c++) bios_putchar(' ');␊ |
133 | ␉␉return c;␊ |
134 | ␉}␊ |
135 | ␊ |
136 | ␉if ( c == '\n' )␊ |
137 | {␊ |
138 | ␉␉bios_putchar('\r');␊ |
139 | }␊ |
140 | ␊ |
141 | ␉bios_putchar(c);␊ |
142 | ␊ |
143 | return c;␊ |
144 | }␊ |
145 | ␊ |
146 | int getc()␊ |
147 | {␊ |
148 | int c = bgetc();␊ |
149 | ␊ |
150 | if ((c & 0xff) == 0)␊ |
151 | return c;␊ |
152 | else␊ |
153 | return (c & 0xff);␊ |
154 | }␊ |
155 | ␊ |
156 | // Read and echo a character from console. This doesn't echo backspace␊ |
157 | // since that screws up higher level handling␊ |
158 | ␊ |
159 | int getchar()␊ |
160 | {␊ |
161 | ␉register int c = getc();␊ |
162 | ␊ |
163 | ␉if ( c == '\r' ) c = '\n';␊ |
164 | ␊ |
165 | ␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
166 | ␉␊ |
167 | ␉return (c);␊ |
168 | }␊ |
169 | ␊ |
170 | int printf(const char * fmt, ...)␊ |
171 | {␊ |
172 | va_list ap;␊ |
173 | ␉va_start(ap, fmt);␊ |
174 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
175 | ␉␉prf(fmt, ap, putchar, 0);␊ |
176 | ␉else␊ |
177 | ␉␉vprf(fmt, ap);␊ |
178 | ␊ |
179 | ␉{␊ |
180 | ␉␉// Kabyl: BooterLog␊ |
181 | ␉␉struct putc_info pi;␊ |
182 | ␊ |
183 | ␉␉if (!msgbuf)␊ |
184 | ␉␉␉return 0;␊ |
185 | ␊ |
186 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
187 | ␉␉␉return 0;␊ |
188 | ␉␉pi.str = cursor;␊ |
189 | ␉␉pi.last_str = 0;␊ |
190 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
191 | ␉␉cursor += strlen((char *)cursor);␊ |
192 | ␉}␊ |
193 | ␊ |
194 | ␉va_end(ap);␊ |
195 | return 0;␊ |
196 | }␊ |
197 | ␊ |
198 | int verbose(const char * fmt, ...)␊ |
199 | {␊ |
200 | va_list ap;␊ |
201 | ␊ |
202 | ␉va_start(ap, fmt);␊ |
203 | if (gVerboseMode)␊ |
204 | {␊ |
205 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
206 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
207 | ␉␉else␊ |
208 | ␉␉␉vprf(fmt, ap);␊ |
209 | }␊ |
210 | ␊ |
211 | ␉{␊ |
212 | ␉␉// Kabyl: BooterLog␊ |
213 | ␉␉struct putc_info pi;␊ |
214 | ␊ |
215 | ␉␉if (!msgbuf)␊ |
216 | ␉␉␉return 0;␊ |
217 | ␊ |
218 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
219 | ␉␉␉return 0;␊ |
220 | ␉␉pi.str = cursor;␊ |
221 | ␉␉pi.last_str = 0;␊ |
222 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
223 | ␉␉cursor += strlen((char *)cursor);␊ |
224 | ␉}␊ |
225 | ␊ |
226 | va_end(ap);␊ |
227 | return(0);␊ |
228 | }␊ |
229 | ␊ |
230 | int error(const char * fmt, ...)␊ |
231 | {␊ |
232 | va_list ap;␊ |
233 | gErrors = true;␊ |
234 | va_start(ap, fmt);␊ |
235 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
236 | ␉␉prf(fmt, ap, putchar, 0);␊ |
237 | else␊ |
238 | ␉␉vprf(fmt, ap);␊ |
239 | ␉va_end(ap);␊ |
240 | return(0);␊ |
241 | }␊ |
242 | ␊ |
243 | void stop(const char * fmt, ...)␊ |
244 | {␊ |
245 | ␉va_list ap;␊ |
246 | ␊ |
247 | ␉printf("\n");␊ |
248 | ␉va_start(ap, fmt);␊ |
249 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
250 | ␉␉prf(fmt, ap, putchar, 0);␊ |
251 | ␉} else {␊ |
252 | ␉␉vprf(fmt, ap);␊ |
253 | ␉}␊ |
254 | ␉va_end(ap);␊ |
255 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
256 | ␉halt();␊ |
257 | ␉while (1);␊ |
258 | }␊ |
259 | ␊ |
260 | /** Print a "Press a key to continue..." message and wait for a key press. */␊ |
261 | void pause() ␊ |
262 | {␊ |
263 | printf("Press a key to continue...\n");␊ |
264 | getc();␊ |
265 | }␊ |
266 | |