Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/libsaio/console.c

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#include <vers.h>
50
51extern intvprf(const char * fmt, va_list ap);
52
53bool gVerboseMode = false;
54bool gErrors = false;
55
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 *
62 * Kabyl: BooterLog
63 */
64#define BOOTER_LOG_SIZE(128 * 1024)
65#define SAFE_LOG_SIZE134
66
67char *msgbuf = 0;
68char *cursor = 0;
69
70// Bungo:
71typedef struct {
72uint16_t year;
73uint8_t mon;
74uint8_t day;
75uint8_t hour;
76uint8_t mins;
77uint8_t secs;
78uint8_t dlight;
79} datetime_t;
80static datetime_t datetime;
81
82struct putc_info //Azi: exists on gui.c & printf.c
83{
84char * str;
85char * last_str;
86};
87
88static int
89sputc(int c, struct putc_info * pi) //Azi: same as above
90{
91if (pi->last_str)
92if (pi->str == pi->last_str)
93{
94*(pi->str) = '\0';
95return 0;
96}
97*(pi->str)++ = c;
98return c;
99}
100
101uint64_t getRTCdatetime() // 0xYYYYMMDDHHMMSS0L in decimal
102{
103biosBuf_t bb;
104
105bb.intno = 0x1a;
106bb.eax.r.h = 0x04; // get RTC date
107//bb.flags.cf = 0;
108bios(&bb);
109if (bb.flags.cf) return 0;
110datetime.year = (bb.ecx.r.h >> 4) * 1000 + (bb.ecx.r.h & 0x0F) * 100 + (bb.ecx.r.l >> 4) * 10 + (bb.ecx.r.l & 0x0F) * 1;
111datetime.mon = (bb.edx.r.h >> 4) * 10 + (bb.edx.r.h & 0x0F) * 1;
112datetime.day = (bb.edx.r.l >> 4) * 10 + (bb.edx.r.l & 0x0F) * 1;
113
114bb.intno = 0x1a;
115bb.eax.r.h = 0x02; // get RTC time
116//bb.flags.cf = 0;
117bios(&bb);
118if (bb.flags.cf) return 0;
119datetime.dlight = bb.edx.r.l & 0x0F;
120datetime.hour = (bb.ecx.r.h >> 4) * 10 + (bb.ecx.r.h & 0x0F) * 1;
121datetime.mins = (bb.ecx.r.l >> 4) * 10 + (bb.ecx.r.l & 0x0F) * 1;
122datetime.secs = (bb.edx.r.h >> 4) * 10 + (bb.edx.r.h & 0x0F) * 1;
123return *(uint64_t *)&datetime;
124}
125
126void initBooterLog(void)
127{
128msgbuf = malloc(BOOTER_LOG_SIZE);
129bzero(msgbuf, BOOTER_LOG_SIZE);
130cursor = msgbuf;
131msglog("%s\n", "Enoch (r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");
132getRTCdatetime();
133msglog("Logging started: %04d/%02d/%02d, %02d:%02d:%02d\n", datetime.year, datetime.mon, datetime.day, datetime.hour, datetime.mins, datetime.secs);
134}
135
136int msglog(const char * fmt, ...)
137{
138va_list ap;
139struct putc_info pi;
140
141if (!msgbuf)
142{
143return 0;
144}
145
146if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
147{
148return 0;
149}
150
151va_start(ap, fmt);
152pi.str = cursor;
153pi.last_str = 0;
154prf(fmt, ap, sputc, &pi);
155va_end(ap);
156cursor += strlen((char *)cursor);
157
158return 0;
159}
160
161void setupBooterLog(void)
162{
163if (!msgbuf)
164{
165return;
166}
167
168Node *node = DT__FindNode("/", false);
169if (node)
170DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
171}
172/* Kabyl: !BooterLog */
173
174/*
175 * write one character to console
176 */
177int putchar(int c)
178{
179if ( c == '\t' ) {
180for (c = 0; c < 8; c++) bios_putchar(' ');
181return c;
182}
183
184if ( c == '\n' ) {
185bios_putchar('\r');
186}
187
188bios_putchar(c);
189
190return c;
191}
192
193int getc()
194{
195int c = bgetc();
196
197if ((c & 0xff) == 0) {
198return c;
199} else {
200return (c & 0xff);
201}
202}
203
204// Read and echo a character from console. This doesn't echo backspace
205// since that screws up higher level handling
206
207int getchar()
208{
209register int c = getc();
210return (c);
211}
212
213int printf(const char * fmt, ...)
214{
215va_list ap;
216
217va_start(ap, fmt);
218if (bootArgs->Video.v_display == VGA_TEXT_MODE)
219{
220prf(fmt, ap, putchar, 0);
221}
222else
223{
224vprf(fmt, ap);
225}
226va_end(ap);
227return 0;
228}
229
230int verbose(const char * fmt, ...)
231{
232va_list ap;
233
234va_start(ap, fmt);
235if (gVerboseMode)
236{
237if (bootArgs->Video.v_display == VGA_TEXT_MODE)
238{
239prf(fmt, ap, putchar, 0);
240}
241else
242{
243vprf(fmt, ap);
244}
245}
246va_end(ap);
247
248{
249// Kabyl: BooterLog
250struct putc_info pi;
251
252if (!msgbuf) {
253return 0;
254}
255
256if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {
257return 0;
258}
259pi.str = cursor;
260pi.last_str = 0;
261va_start(ap, fmt);
262prf(fmt, ap, sputc, &pi);
263va_end(ap);
264cursor += strlen((char *)cursor);
265}
266
267return(0);
268}
269
270int error(const char * fmt, ...)
271{
272va_list ap;
273gErrors = true;
274va_start(ap, fmt);
275if (bootArgs->Video.v_display == VGA_TEXT_MODE)
276{
277prf(fmt, ap, putchar, 0);
278}
279else
280{
281vprf(fmt, ap);
282}
283va_end(ap);
284
285// Kabyl: BooterLog
286struct putc_info pi;
287
288if (!msgbuf)
289{
290return 0;
291}
292
293if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
294{
295return 0;
296}
297
298pi.str = cursor;
299pi.last_str = 0;
300va_start(ap, fmt);
301prf(fmt, ap, sputc, &pi);
302va_end(ap);
303cursor += strlen((char *)cursor);
304
305return(0);
306}
307
308void stop(const char * fmt, ...)
309{
310va_list ap;
311
312printf("\n");
313va_start(ap, fmt);
314if (bootArgs->Video.v_display == VGA_TEXT_MODE)
315{
316prf(fmt, ap, putchar, 0);
317}
318else
319{
320vprf(fmt, ap);
321}
322va_end(ap);
323printf("\nThis is a non recoverable error! System HALTED!!!");
324halt();
325while (1);
326}
327
328/** Print a "Press a key to continue..." message and wait for a key press. */
329void pause()
330{
331printf("Press a key to continue...\n");
332getchar(); // replace getchar() by pause() were useful.
333}
334

Archive Download this file

Revision: 2871