root/arch/sparc/prom/printf.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. prom_printf

   1 /* printf.c:  Internal prom library printf facility.
   2  *
   3  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   4  */
   5 
   6 /* This routine is internal to the prom library, no one else should know
   7  * about or use it!  It's simple and smelly anyway....
   8  */
   9 
  10 #include <stdarg.h>
  11 
  12 #include <asm/openprom.h>
  13 #include <asm/oplib.h>
  14 
  15 char hexstring[] = "0123456789abcdef";
  16 
  17 void
  18 prom_printf(char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
  19 {
  20         va_list args;
  21         unsigned int ui_val;
  22         int i_val, n_ctr;
  23         char c_val;
  24         char nstr_buf[32];
  25         char *s_val;
  26         
  27         va_start(args, fmt);
  28         while(*fmt) {
  29                 if(*fmt != '%') {
  30                         if(*fmt == '\n')
  31                                 prom_putchar('\r');
  32                         prom_putchar(*fmt++);
  33                         continue;
  34                 }
  35 
  36                 fmt++;
  37                 if(!*fmt) break;
  38                 n_ctr = 0;
  39                 switch(*fmt) {
  40                 case 'c':
  41                         c_val = va_arg(args, char);
  42                         if(c_val == '\n')
  43                                 prom_putchar('\r');
  44                         prom_putchar(c_val);
  45                         fmt++;
  46                         break;
  47                 case 's':
  48                         s_val = va_arg(args, char *);
  49                         while(*s_val != 0) {
  50                                 prom_putchar(*s_val);
  51                                 s_val++;
  52                         }
  53                         fmt++;
  54                         break;
  55                 case 'd':
  56                         /* Base 10 */
  57                         i_val = va_arg(args, int);
  58                         if(i_val==0x0)
  59                                 prom_putchar('0');
  60                         else
  61                                 while(i_val != 0x0) {
  62                                         nstr_buf[n_ctr] = hexstring[i_val%0xa];
  63                                         i_val = ((unsigned long)i_val) / (unsigned) 0xa;
  64                                         n_ctr++;
  65                                 };
  66                         while(--n_ctr >= 0)
  67                                 prom_putchar(nstr_buf[n_ctr]);
  68                         fmt++;
  69                         break;
  70                 case 'x':
  71                         /* Base 16 */
  72                         ui_val = va_arg(args, unsigned int);
  73                         if(ui_val==0x0)
  74                                 prom_putchar('0');
  75                         else
  76                                 while(ui_val != 0x0) {
  77                                         nstr_buf[n_ctr] = hexstring[ui_val%0x10];
  78                                         ui_val = ((unsigned long) ui_val) / (unsigned) 0x10;
  79                                         n_ctr++;
  80                                 };
  81                         while(--n_ctr >= 0)
  82                                 prom_putchar(nstr_buf[n_ctr]);
  83                         fmt++;
  84                         break;
  85                 case 'o':
  86                         /* Base 8 */
  87                         ui_val = va_arg(args, unsigned int);
  88                         if(ui_val==0x0)
  89                                 prom_putchar('0');
  90                         else
  91                                 while(ui_val != 0x0) {
  92                                         nstr_buf[n_ctr] = hexstring[ui_val%0x8];
  93                                         ui_val = ((unsigned long) ui_val) / (unsigned) 0x8;
  94                                 };
  95                         while(--n_ctr >= 0)
  96                                 prom_putchar(nstr_buf[n_ctr]);
  97                         fmt++;
  98                         break;
  99                 default:
 100                         /* Uh oh, something we can't handle... skip it */
 101                         fmt++;
 102                         break;
 103                 };
 104         }
 105 
 106         /* We are done... */
 107         return;
 108 }

/* [previous][next][first][last][top][bottom][index][help] */