Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.16-rc4 172 lines 2.7 kB view raw
1/* 2 * Copyright (C) Paul Mackerras 1997. 3 * 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" 11 12extern int strlen(const char *s); 13extern void boot(int a1, int a2, void *prom); 14 15phandle stdin; 16phandle stdout; 17phandle stderr; 18 19void printk(char *fmt, ...); 20 21void 22start(int a1, int a2, void *promptr) 23{ 24 ofinit(promptr); 25 if (ofstdio(&stdin, &stdout, &stderr)) 26 exit(); 27 28 boot(a1, a2, promptr); 29 for (;;) 30 exit(); 31} 32 33int writestring(void *f, char *ptr, int nb) 34{ 35 int w = 0, i; 36 char *ret = "\r"; 37 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; 43 } 44 write(f, ret, 1); 45 } 46 } 47 if (w < nb) 48 write(f, ptr + w, nb - w); 49 return nb; 50} 51 52int 53putc(int c, void *f) 54{ 55 char ch = c; 56 57 return writestring(f, &ch, 1) == 1? c: -1; 58} 59 60int 61putchar(int c) 62{ 63 return putc(c, stdout); 64} 65 66int 67fputs(char *str, void *f) 68{ 69 int n = strlen(str); 70 71 return writestring(f, str, n) == n? 0: -1; 72} 73 74int 75readchar(void) 76{ 77 char ch; 78 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; 86 } 87 } 88} 89 90static char line[256]; 91static char *lineptr; 92static int lineleft; 93 94int 95getchar(void) 96{ 97 int c; 98 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; 109 } 110 switch (c) { 111 case 0177: 112 case '\b': 113 if (lineptr > line) { 114 putchar('\b'); 115 putchar(' '); 116 putchar('\b'); 117 --lineptr; 118 } 119 break; 120 case 'U' & 0x1F: 121 while (lineptr > line) { 122 putchar('\b'); 123 putchar(' '); 124 putchar('\b'); 125 --lineptr; 126 } 127 break; 128 default: 129 if (lineptr >= &line[sizeof(line) - 1]) 130 putchar('\a'); 131 else { 132 putchar(c); 133 *lineptr++ = c; 134 } 135 } 136 } 137 lineleft = lineptr - line; 138 lineptr = line; 139 } 140 if (lineleft == 0) 141 return -1; 142 --lineleft; 143 return *lineptr++; 144} 145 146extern int vsprintf(char *buf, const char *fmt, va_list args); 147static char sprint_buf[1024]; 148 149void 150printk(char *fmt, ...) 151{ 152 va_list args; 153 int n; 154 155 va_start(args, fmt); 156 n = vsprintf(sprint_buf, fmt, args); 157 va_end(args); 158 writestring(stdout, sprint_buf, n); 159} 160 161int 162printf(char *fmt, ...) 163{ 164 va_list args; 165 int n; 166 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; 172}