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 | //Azi: Double log available size; this seems to fix some hangs and instant reboots caused by␊ |
57 | // booting with -f (ignore caches). 96kb are enough to hold full log, booting with -f; even so,␊ |
58 | // this depends on how much we "play" at the boot prompt and with what patches we're playing,␊ |
59 | // depending on how much they print to the log.␊ |
60 | #define BOOTER_LOG_SIZE␉(128 * 1024)␊ |
61 | #define SAFE_LOG_SIZE␉134␊ |
62 | ␊ |
63 | char *msgbuf = 0;␊ |
64 | char *cursor = 0;␊ |
65 | ␊ |
66 | struct putc_info {␊ |
67 | char * str;␊ |
68 | char * last_str;␊ |
69 | };␊ |
70 | ␊ |
71 | static void sputc(int c, struct putc_info * pi)␊ |
72 | {␊ |
73 | ␉if (pi->last_str)␊ |
74 | ␉if (pi->str == pi->last_str)␊ |
75 | ␉{␊ |
76 | ␉␉*(pi->str) = '\0';␊ |
77 | ␉␉return;␊ |
78 | ␉}␊ |
79 | ␉*(pi->str)++ = c;␊ |
80 | }␊ |
81 | ␊ |
82 | void initBooterLog(void)␊ |
83 | {␊ |
84 | ␉msgbuf = malloc(BOOTER_LOG_SIZE);␊ |
85 | ␉bzero(msgbuf, BOOTER_LOG_SIZE);␊ |
86 | ␉cursor = msgbuf;␊ |
87 | }␊ |
88 | ␊ |
89 | void msglog(const char * fmt, ...)␊ |
90 | {␊ |
91 | ␉va_list ap;␊ |
92 | ␉struct putc_info pi;␊ |
93 | ␊ |
94 | ␉if (!msgbuf)␊ |
95 | ␉␉return;␊ |
96 | ␊ |
97 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
98 | ␉␉return;␊ |
99 | ␊ |
100 | ␉va_start(ap, fmt);␊ |
101 | ␉pi.str = cursor;␊ |
102 | ␉pi.last_str = 0;␊ |
103 | ␉prf(fmt, ap, sputc, &pi);␊ |
104 | ␉va_end(ap);␊ |
105 | ␉cursor += strlen((char *)cursor);␊ |
106 | }␊ |
107 | ␊ |
108 | void setupBooterLog(void)␊ |
109 | {␊ |
110 | ␉if (!msgbuf)␊ |
111 | ␉␉return;␊ |
112 | ␊ |
113 | ␉Node *node = DT__FindNode("/", false);␊ |
114 | ␉if (node)␊ |
115 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
116 | }␊ |
117 | /* Kabyl: !BooterLog */␊ |
118 | ␊ |
119 | /*␊ |
120 | * write one character to console␊ |
121 | */␊ |
122 | void putchar(int c)␊ |
123 | {␊ |
124 | ␉if ( c == '\t' )␊ |
125 | ␉{␊ |
126 | ␉␉for (c = 0; c < 8; c++) putc(' ');␊ |
127 | ␉␉return;␊ |
128 | ␉}␊ |
129 | ␊ |
130 | ␉if ( c == '\n' )␊ |
131 | {␊ |
132 | ␉␉putc('\r');␊ |
133 | }␊ |
134 | ␊ |
135 | ␉putc(c);␊ |
136 | }␊ |
137 | ␊ |
138 | int getc()␊ |
139 | {␊ |
140 | int c = bgetc();␊ |
141 | ␊ |
142 | if ((c & 0xff) == 0)␊ |
143 | return c;␊ |
144 | else␊ |
145 | return (c & 0xff);␊ |
146 | }␊ |
147 | ␊ |
148 | // Read and echo a character from console. This doesn't echo backspace␊ |
149 | // since that screws up higher level handling␊ |
150 | ␊ |
151 | int getchar()␊ |
152 | {␊ |
153 | ␉register int c = getc();␊ |
154 | ␊ |
155 | ␉if ( c == '\r' ) c = '\n';␊ |
156 | ␊ |
157 | ␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
158 | ␉␊ |
159 | ␉return (c);␊ |
160 | }␊ |
161 | ␊ |
162 | int printf(const char * fmt, ...)␊ |
163 | {␊ |
164 | va_list ap;␊ |
165 | ␉va_start(ap, fmt);␊ |
166 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
167 | ␉␉prf(fmt, ap, putchar, 0);␊ |
168 | ␉else␊ |
169 | ␉␉vprf(fmt, ap);␊ |
170 | ␊ |
171 | ␉{␊ |
172 | ␉/* Kabyl: BooterLog */␊ |
173 | ␉␉struct putc_info pi;␊ |
174 | ␊ |
175 | ␉␉if (!msgbuf)␊ |
176 | ␉␉␉return 0;␊ |
177 | ␊ |
178 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
179 | ␉␉␉return 0;␊ |
180 | ␉␉pi.str = cursor;␊ |
181 | ␉␉pi.last_str = 0;␊ |
182 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
183 | ␉␉cursor += strlen((char *)cursor);␊ |
184 | ␉}␊ |
185 | ␊ |
186 | ␉va_end(ap);␊ |
187 | return 0;␊ |
188 | }␊ |
189 | ␊ |
190 | int verbose(const char * fmt, ...)␊ |
191 | {␊ |
192 | va_list ap;␊ |
193 | ␊ |
194 | ␉va_start(ap, fmt);␊ |
195 | if (gVerboseMode)␊ |
196 | {␊ |
197 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
198 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
199 | ␉␉else␊ |
200 | ␉␉␉vprf(fmt, ap);␊ |
201 | }␊ |
202 | ␊ |
203 | ␉{␊ |
204 | ␉/* Kabyl: BooterLog */␊ |
205 | ␉␉struct putc_info pi;␊ |
206 | ␊ |
207 | ␉␉if (!msgbuf)␊ |
208 | ␉␉␉return 0;␊ |
209 | ␊ |
210 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
211 | ␉␉␉return 0;␊ |
212 | ␉␉pi.str = cursor;␊ |
213 | ␉␉pi.last_str = 0;␊ |
214 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
215 | ␉␉cursor += strlen((char *)cursor);␊ |
216 | ␉}␊ |
217 | ␊ |
218 | va_end(ap);␊ |
219 | return(0);␊ |
220 | }␊ |
221 | ␊ |
222 | int error(const char * fmt, ...)␊ |
223 | {␊ |
224 | va_list ap;␊ |
225 | gErrors = true;␊ |
226 | va_start(ap, fmt);␊ |
227 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
228 | ␉␉prf(fmt, ap, putchar, 0);␊ |
229 | else␊ |
230 | ␉␉vprf(fmt, ap);␊ |
231 | ␉va_end(ap);␊ |
232 | return(0);␊ |
233 | }␊ |
234 | ␊ |
235 | void stop(const char * fmt, ...)␊ |
236 | {␊ |
237 | ␉va_list ap;␊ |
238 | ␊ |
239 | ␉printf("\n");␊ |
240 | ␉va_start(ap, fmt);␊ |
241 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
242 | ␉␉prf(fmt, ap, putchar, 0);␊ |
243 | ␉} else {␊ |
244 | ␉␉vprf(fmt, ap);␊ |
245 | ␉}␊ |
246 | ␉va_end(ap);␊ |
247 | ␉printf("\nThis is a non recoverable error! System HALTED!!!"); //Azi: line break ??␊ |
248 | ␉halt();␊ |
249 | ␉while (1);␊ |
250 | }␊ |
251 | ␊ |
252 | /** Print a "Press a key to continue..." message and wait for a key press. */␊ |
253 | void pause() ␊ |
254 | {␊ |
255 | printf("Press a key to continue...\n");␊ |
256 | getc();␊ |
257 | }␊ |
258 | |