Linux-2.6.12-rc2
[linux-2.6/kvm.git] / arch / ppc / boot / openfirmware / start.c
blob1617a26956bfe5d079f5cd3a900b078ea9315ec7
1 /*
2 * Copyright (C) Paul Mackerras 1997.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9 #include <stdarg.h>
10 #include "of1275.h"
12 extern int strlen(const char *s);
13 extern void boot(int a1, int a2, void *prom);
15 phandle stdin;
16 phandle stdout;
17 phandle stderr;
19 void printk(char *fmt, ...);
21 void
22 start(int a1, int a2, void *promptr)
24 ofinit(promptr);
25 if (ofstdio(&stdin, &stdout, &stderr))
26 exit();
28 boot(a1, a2, promptr);
29 for (;;)
30 exit();
33 int writestring(void *f, char *ptr, int nb)
35 int w = 0, i;
36 char *ret = "\r";
38 for (i = 0; i < nb; ++i) {
39 if (ptr[i] == '\n') {
40 if (i > w) {
41 write(f, ptr + w, i - w);
42 w = i;
44 write(f, ret, 1);
47 if (w < nb)
48 write(f, ptr + w, nb - w);
49 return nb;
52 int
53 putc(int c, void *f)
55 char ch = c;
57 return writestring(f, &ch, 1) == 1? c: -1;
60 int
61 putchar(int c)
63 return putc(c, stdout);
66 int
67 fputs(char *str, void *f)
69 int n = strlen(str);
71 return writestring(f, str, n) == n? 0: -1;
74 int
75 readchar(void)
77 char ch;
79 for (;;) {
80 switch (read(stdin, &ch, 1)) {
81 case 1:
82 return ch;
83 case -1:
84 printk("read(stdin) returned -1\n");
85 return -1;
90 static char line[256];
91 static char *lineptr;
92 static int lineleft;
94 int
95 getchar(void)
97 int c;
99 if (lineleft == 0) {
100 lineptr = line;
101 for (;;) {
102 c = readchar();
103 if (c == -1 || c == 4)
104 break;
105 if (c == '\r' || c == '\n') {
106 *lineptr++ = '\n';
107 putchar('\n');
108 break;
110 switch (c) {
111 case 0177:
112 case '\b':
113 if (lineptr > line) {
114 putchar('\b');
115 putchar(' ');
116 putchar('\b');
117 --lineptr;
119 break;
120 case 'U' & 0x1F:
121 while (lineptr > line) {
122 putchar('\b');
123 putchar(' ');
124 putchar('\b');
125 --lineptr;
127 break;
128 default:
129 if (lineptr >= &line[sizeof(line) - 1])
130 putchar('\a');
131 else {
132 putchar(c);
133 *lineptr++ = c;
137 lineleft = lineptr - line;
138 lineptr = line;
140 if (lineleft == 0)
141 return -1;
142 --lineleft;
143 return *lineptr++;
146 extern int vsprintf(char *buf, const char *fmt, va_list args);
147 static char sprint_buf[1024];
149 void
150 printk(char *fmt, ...)
152 va_list args;
153 int n;
155 va_start(args, fmt);
156 n = vsprintf(sprint_buf, fmt, args);
157 va_end(args);
158 writestring(stdout, sprint_buf, n);
162 printf(char *fmt, ...)
164 va_list args;
165 int n;
167 va_start(args, fmt);
168 n = vsprintf(sprint_buf, fmt, args);
169 va_end(args);
170 writestring(stdout, sprint_buf, n);
171 return n;