Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2469