diff options
Diffstat (limited to 'arch/ppc64/boot/prom.c')
| -rw-r--r-- | arch/ppc64/boot/prom.c | 196 |
1 files changed, 27 insertions, 169 deletions
diff --git a/arch/ppc64/boot/prom.c b/arch/ppc64/boot/prom.c index 5e48b80ff5a0..4bea2f4dcb06 100644 --- a/arch/ppc64/boot/prom.c +++ b/arch/ppc64/boot/prom.c | |||
| @@ -7,43 +7,19 @@ | |||
| 7 | * 2 of the License, or (at your option) any later version. | 7 | * 2 of the License, or (at your option) any later version. |
| 8 | */ | 8 | */ |
| 9 | #include <stdarg.h> | 9 | #include <stdarg.h> |
| 10 | #include <linux/types.h> | 10 | #include <stddef.h> |
| 11 | #include <linux/string.h> | 11 | #include "string.h" |
| 12 | #include <linux/ctype.h> | 12 | #include "stdio.h" |
| 13 | 13 | #include "prom.h" | |
| 14 | extern __u32 __div64_32(unsigned long long *dividend, __u32 divisor); | ||
| 15 | |||
| 16 | /* The unnecessary pointer compare is there | ||
| 17 | * to check for type safety (n must be 64bit) | ||
| 18 | */ | ||
| 19 | # define do_div(n,base) ({ \ | ||
| 20 | __u32 __base = (base); \ | ||
| 21 | __u32 __rem; \ | ||
| 22 | (void)(((typeof((n)) *)0) == ((unsigned long long *)0)); \ | ||
| 23 | if (((n) >> 32) == 0) { \ | ||
| 24 | __rem = (__u32)(n) % __base; \ | ||
| 25 | (n) = (__u32)(n) / __base; \ | ||
| 26 | } else \ | ||
| 27 | __rem = __div64_32(&(n), __base); \ | ||
| 28 | __rem; \ | ||
| 29 | }) | ||
| 30 | 14 | ||
| 31 | int (*prom)(void *); | 15 | int (*prom)(void *); |
| 32 | 16 | ||
| 33 | void *chosen_handle; | 17 | void *chosen_handle; |
| 18 | |||
| 34 | void *stdin; | 19 | void *stdin; |
| 35 | void *stdout; | 20 | void *stdout; |
| 36 | void *stderr; | 21 | void *stderr; |
| 37 | 22 | ||
| 38 | void exit(void); | ||
| 39 | void *finddevice(const char *name); | ||
| 40 | int getprop(void *phandle, const char *name, void *buf, int buflen); | ||
| 41 | void chrpboot(int a1, int a2, void *prom); /* in main.c */ | ||
| 42 | |||
| 43 | int printf(char *fmt, ...); | ||
| 44 | |||
| 45 | /* there is no convenient header to get this from... -- paulus */ | ||
| 46 | extern unsigned long strlen(const char *); | ||
| 47 | 23 | ||
| 48 | int | 24 | int |
| 49 | write(void *handle, void *ptr, int nb) | 25 | write(void *handle, void *ptr, int nb) |
| @@ -210,107 +186,6 @@ fputs(char *str, void *f) | |||
| 210 | return write(f, str, n) == n? 0: -1; | 186 | return write(f, str, n) == n? 0: -1; |
| 211 | } | 187 | } |
| 212 | 188 | ||
| 213 | int | ||
| 214 | readchar(void) | ||
| 215 | { | ||
| 216 | char ch; | ||
| 217 | |||
| 218 | for (;;) { | ||
| 219 | switch (read(stdin, &ch, 1)) { | ||
| 220 | case 1: | ||
| 221 | return ch; | ||
| 222 | case -1: | ||
| 223 | printf("read(stdin) returned -1\r\n"); | ||
| 224 | return -1; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | static char line[256]; | ||
| 230 | static char *lineptr; | ||
| 231 | static int lineleft; | ||
| 232 | |||
| 233 | int | ||
| 234 | getchar(void) | ||
| 235 | { | ||
| 236 | int c; | ||
| 237 | |||
| 238 | if (lineleft == 0) { | ||
| 239 | lineptr = line; | ||
| 240 | for (;;) { | ||
| 241 | c = readchar(); | ||
| 242 | if (c == -1 || c == 4) | ||
| 243 | break; | ||
| 244 | if (c == '\r' || c == '\n') { | ||
| 245 | *lineptr++ = '\n'; | ||
| 246 | putchar('\n'); | ||
| 247 | break; | ||
| 248 | } | ||
| 249 | switch (c) { | ||
| 250 | case 0177: | ||
| 251 | case '\b': | ||
| 252 | if (lineptr > line) { | ||
| 253 | putchar('\b'); | ||
| 254 | putchar(' '); | ||
| 255 | putchar('\b'); | ||
| 256 | --lineptr; | ||
| 257 | } | ||
| 258 | break; | ||
| 259 | case 'U' & 0x1F: | ||
| 260 | while (lineptr > line) { | ||
| 261 | putchar('\b'); | ||
| 262 | putchar(' '); | ||
| 263 | putchar('\b'); | ||
| 264 | --lineptr; | ||
| 265 | } | ||
| 266 | break; | ||
| 267 | default: | ||
| 268 | if (lineptr >= &line[sizeof(line) - 1]) | ||
| 269 | putchar('\a'); | ||
| 270 | else { | ||
| 271 | putchar(c); | ||
| 272 | *lineptr++ = c; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | ||
| 276 | lineleft = lineptr - line; | ||
| 277 | lineptr = line; | ||
| 278 | } | ||
| 279 | if (lineleft == 0) | ||
| 280 | return -1; | ||
| 281 | --lineleft; | ||
| 282 | return *lineptr++; | ||
| 283 | } | ||
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | /* String functions lifted from lib/vsprintf.c and lib/ctype.c */ | ||
| 288 | unsigned char _ctype[] = { | ||
| 289 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ | ||
| 290 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ | ||
| 291 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ | ||
| 292 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ | ||
| 293 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ | ||
| 294 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ | ||
| 295 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ | ||
| 296 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ | ||
| 297 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ | ||
| 298 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ | ||
| 299 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ | ||
| 300 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ | ||
| 301 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ | ||
| 302 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ | ||
| 303 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ | ||
| 304 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ | ||
| 305 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ | ||
| 306 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ | ||
| 307 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ | ||
| 308 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ | ||
| 309 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ | ||
| 310 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ | ||
| 311 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ | ||
| 312 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ | ||
| 313 | |||
| 314 | size_t strnlen(const char * s, size_t count) | 189 | size_t strnlen(const char * s, size_t count) |
| 315 | { | 190 | { |
| 316 | const char *sc; | 191 | const char *sc; |
| @@ -320,44 +195,30 @@ size_t strnlen(const char * s, size_t count) | |||
| 320 | return sc - s; | 195 | return sc - s; |
| 321 | } | 196 | } |
| 322 | 197 | ||
| 323 | unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) | 198 | extern unsigned int __div64_32(unsigned long long *dividend, |
| 324 | { | 199 | unsigned int divisor); |
| 325 | unsigned long result = 0,value; | ||
| 326 | 200 | ||
| 327 | if (!base) { | 201 | /* The unnecessary pointer compare is there |
| 328 | base = 10; | 202 | * to check for type safety (n must be 64bit) |
| 329 | if (*cp == '0') { | 203 | */ |
| 330 | base = 8; | 204 | # define do_div(n,base) ({ \ |
| 331 | cp++; | 205 | unsigned int __base = (base); \ |
| 332 | if ((*cp == 'x') && isxdigit(cp[1])) { | 206 | unsigned int __rem; \ |
| 333 | cp++; | 207 | (void)(((typeof((n)) *)0) == ((unsigned long long *)0)); \ |
| 334 | base = 16; | 208 | if (((n) >> 32) == 0) { \ |
| 335 | } | 209 | __rem = (unsigned int)(n) % __base; \ |
| 336 | } | 210 | (n) = (unsigned int)(n) / __base; \ |
| 337 | } | 211 | } else \ |
| 338 | while (isxdigit(*cp) && | 212 | __rem = __div64_32(&(n), __base); \ |
| 339 | (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) { | 213 | __rem; \ |
| 340 | result = result*base + value; | 214 | }) |
| 341 | cp++; | ||
| 342 | } | ||
| 343 | if (endp) | ||
| 344 | *endp = (char *)cp; | ||
| 345 | return result; | ||
| 346 | } | ||
| 347 | |||
| 348 | long simple_strtol(const char *cp,char **endp,unsigned int base) | ||
| 349 | { | ||
| 350 | if(*cp=='-') | ||
| 351 | return -simple_strtoul(cp+1,endp,base); | ||
| 352 | return simple_strtoul(cp,endp,base); | ||
| 353 | } | ||
| 354 | 215 | ||
| 355 | static int skip_atoi(const char **s) | 216 | static int skip_atoi(const char **s) |
| 356 | { | 217 | { |
| 357 | int i=0; | 218 | int i, c; |
| 358 | 219 | ||
| 359 | while (isdigit(**s)) | 220 | for (i = 0; '0' <= (c = **s) && c <= '9'; ++*s) |
| 360 | i = i*10 + *((*s)++) - '0'; | 221 | i = i*10 + c - '0'; |
| 361 | return i; | 222 | return i; |
| 362 | } | 223 | } |
| 363 | 224 | ||
| @@ -436,9 +297,6 @@ static char * number(char * str, unsigned long long num, int base, int size, int | |||
| 436 | return str; | 297 | return str; |
| 437 | } | 298 | } |
| 438 | 299 | ||
| 439 | /* Forward decl. needed for IP address printing stuff... */ | ||
| 440 | int sprintf(char * buf, const char *fmt, ...); | ||
| 441 | |||
| 442 | int vsprintf(char *buf, const char *fmt, va_list args) | 300 | int vsprintf(char *buf, const char *fmt, va_list args) |
| 443 | { | 301 | { |
| 444 | int len; | 302 | int len; |
| @@ -477,7 +335,7 @@ int vsprintf(char *buf, const char *fmt, va_list args) | |||
| 477 | 335 | ||
| 478 | /* get field width */ | 336 | /* get field width */ |
| 479 | field_width = -1; | 337 | field_width = -1; |
| 480 | if (isdigit(*fmt)) | 338 | if ('0' <= *fmt && *fmt <= '9') |
| 481 | field_width = skip_atoi(&fmt); | 339 | field_width = skip_atoi(&fmt); |
| 482 | else if (*fmt == '*') { | 340 | else if (*fmt == '*') { |
| 483 | ++fmt; | 341 | ++fmt; |
| @@ -493,7 +351,7 @@ int vsprintf(char *buf, const char *fmt, va_list args) | |||
| 493 | precision = -1; | 351 | precision = -1; |
| 494 | if (*fmt == '.') { | 352 | if (*fmt == '.') { |
| 495 | ++fmt; | 353 | ++fmt; |
| 496 | if (isdigit(*fmt)) | 354 | if ('0' <= *fmt && *fmt <= '9') |
| 497 | precision = skip_atoi(&fmt); | 355 | precision = skip_atoi(&fmt); |
| 498 | else if (*fmt == '*') { | 356 | else if (*fmt == '*') { |
| 499 | ++fmt; | 357 | ++fmt; |
| @@ -628,7 +486,7 @@ int sprintf(char * buf, const char *fmt, ...) | |||
| 628 | static char sprint_buf[1024]; | 486 | static char sprint_buf[1024]; |
| 629 | 487 | ||
| 630 | int | 488 | int |
| 631 | printf(char *fmt, ...) | 489 | printf(const char *fmt, ...) |
| 632 | { | 490 | { |
| 633 | va_list args; | 491 | va_list args; |
| 634 | int n; | 492 | int n; |
