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