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