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 | ␉*pi.str = '\0';␊ |
101 | ␉va_end(ap);␊ |
102 | ␉cursor += (pi.str - cursor);␊ |
103 | }␊ |
104 | ␊ |
105 | void setupBooterLog(void)␊ |
106 | {␊ |
107 | ␉if (!msgbuf)␊ |
108 | ␉␉return;␊ |
109 | ␊ |
110 | ␉Node *node = DT__FindNode("/", false);␊ |
111 | ␉if (node)␊ |
112 | ␉␉DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);␊ |
113 | }␊ |
114 | /* Kabyl: !BooterLog */␊ |
115 | ␊ |
116 | ␊ |
117 | /*␊ |
118 | * write one character to console␊ |
119 | */␊ |
120 | void putchar(int c)␊ |
121 | {␊ |
122 | ␉if ( c == '\t' )␊ |
123 | ␉{␊ |
124 | ␉␉for (c = 0; c < 8; c++) putc(' ');␊ |
125 | ␉␉return;␊ |
126 | ␉}␊ |
127 | ␊ |
128 | ␉if ( c == '\n' )␊ |
129 | {␊ |
130 | ␉␉putc('\r');␊ |
131 | }␊ |
132 | ␊ |
133 | ␉putc(c);␊ |
134 | }␊ |
135 | ␊ |
136 | int getc()␊ |
137 | {␊ |
138 | int c = bgetc();␊ |
139 | ␊ |
140 | if ((c & 0xff) == 0)␊ |
141 | return c;␊ |
142 | else␊ |
143 | return (c & 0xff);␊ |
144 | }␊ |
145 | ␊ |
146 | // Read and echo a character from console. This doesn't echo backspace␊ |
147 | // since that screws up higher level handling␊ |
148 | ␊ |
149 | int getchar()␊ |
150 | {␊ |
151 | ␉register int c = getc();␊ |
152 | ␊ |
153 | ␉if ( c == '\r' ) c = '\n';␊ |
154 | ␊ |
155 | ␉if ( c >= ' ' && c < 0x7f) putchar(c);␊ |
156 | ␉␊ |
157 | ␉return (c);␊ |
158 | }␊ |
159 | ␊ |
160 | int printf(const char * fmt, ...)␊ |
161 | {␊ |
162 | va_list ap;␊ |
163 | ␉va_start(ap, fmt);␊ |
164 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
165 | ␉␉prf(fmt, ap, putchar, 0);␊ |
166 | ␉else␊ |
167 | ␉␉vprf(fmt, ap);␊ |
168 | ␊ |
169 | ␉{␊ |
170 | ␉/* Kabyl: BooterLog */␊ |
171 | ␉␉struct putc_info pi;␊ |
172 | ␊ |
173 | ␉␉if (!msgbuf)␊ |
174 | ␉␉␉return 0;␊ |
175 | ␊ |
176 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
177 | ␉␉␉return 0;␊ |
178 | ␉␉pi.str = cursor;␊ |
179 | ␉␉pi.last_str = 0;␊ |
180 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
181 | ␉␉*pi.str = '\0';␊ |
182 | ␉␉cursor += (pi.str - cursor);␊ |
183 | ␉}␊ |
184 | ␊ |
185 | ␉va_end(ap);␊ |
186 | return 0;␊ |
187 | }␊ |
188 | ␊ |
189 | int verbose(const char * fmt, ...)␊ |
190 | {␊ |
191 | va_list ap;␊ |
192 | ␊ |
193 | ␉va_start(ap, fmt);␊ |
194 | if (gVerboseMode)␊ |
195 | {␊ |
196 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
197 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
198 | ␉␉else␊ |
199 | ␉␉␉vprf(fmt, ap);␊ |
200 | }␊ |
201 | ␊ |
202 | ␉{␊ |
203 | ␉/* Kabyl: BooterLog */␊ |
204 | ␉␉struct putc_info pi;␊ |
205 | ␊ |
206 | ␉␉if (!msgbuf)␊ |
207 | ␉␉␉return 0;␊ |
208 | ␊ |
209 | ␉␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
210 | ␉␉␉return 0;␊ |
211 | ␉␉pi.str = cursor;␊ |
212 | ␉␉pi.last_str = 0;␊ |
213 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
214 | ␉␉*pi.str = '\0';␊ |
215 | ␉␉cursor += (pi.str - 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!!!");␊ |
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...");␊ |
256 | getc();␊ |
257 | }␊ |
258 | |