Print this page
12208 dboot_printf(): support %u

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/i86pc/dboot/dboot_printf.c
          +++ new/usr/src/uts/i86pc/dboot/dboot_printf.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2012 Gary Mills
       24 + * Copyright 2020 Joyent, Inc.
  24   25   *
  25   26   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  26   27   * Use is subject to license terms.
  27   28   */
  28   29  
  29   30  #include <sys/types.h>
  30   31  #include <sys/param.h>
  31   32  #include <sys/machparam.h>
  32   33  #include <sys/archsystm.h>
  33   34  #include <sys/boot_console.h>
↓ open down ↓ 52 lines elided ↑ open up ↑
  86   87  static void
  87   88  dboot_puts(char *s)
  88   89  {
  89   90          while (*s != 0) {
  90   91                  bcons_putchar(*s);
  91   92                  ++s;
  92   93          }
  93   94  }
  94   95  
  95   96  static void
  96      -dboot_putnum(uint64_t x, uint_t is_signed, uint8_t base)
       97 +dboot_putnum(uint64_t x, boolean_t is_signed, uint8_t base)
  97   98  {
  98   99          char buffer[64];        /* digits in reverse order */
  99  100          int i;
 100  101  
 101  102          if (is_signed && (int64_t)x < 0) {
 102  103                  bcons_putchar('-');
 103  104                  x = -x;
 104  105          }
 105  106  
 106  107          for (i  = -1; x != 0 && i <= 63; x /= base)
 107  108                  buffer[++i] = digits[x - ((x / base) * base)];
 108  109  
 109  110          if (i < 0)
 110  111                  buffer[++i] = '0';
 111  112  
 112  113          while (i >= 0)
 113  114                  bcons_putchar(buffer[i--]);
 114  115  }
 115  116  
 116  117  /*
 117      - * very primitive printf - only does %s, %d, %x, %lx, or %%
      118 + * Very primitive printf - only does a subset of the standard format characters.
 118  119   */
 119  120  static void
 120  121  do_dboot_printf(char *fmt, va_list args)
 121  122  {
 122  123          char *s;
 123  124          uint64_t x;
 124  125          uint8_t base;
 125  126          uint8_t size;
 126      -        uint_t is_signed = 1;
 127  127  
 128  128          if (fmt == NULL) {
 129  129                  dboot_puts("dboot_printf(): 1st arg is NULL\n");
 130  130                  return;
 131  131          }
 132  132          for (; *fmt; ++fmt) {
 133  133                  if (*fmt != '%') {
 134  134                          bcons_putchar(*fmt);
 135  135                          continue;
 136  136                  }
↓ open down ↓ 15 lines elided ↑ open up ↑
 152  152                  case 's':
 153  153                          s = va_arg(args, char *);
 154  154                          if (s == NULL)
 155  155                                  dboot_puts("*NULL*");
 156  156                          else
 157  157                                  dboot_puts(s);
 158  158                          break;
 159  159  
 160  160                  case 'p':
 161  161                          x = va_arg(args, ulong_t);
 162      -                        dboot_putnum(x, !is_signed, 16);
      162 +                        dboot_putnum(x, B_FALSE, 16);
 163  163                          break;
 164  164  
 165  165                  case 'l':
 166  166                          if (size == 0)
 167  167                                  size = sizeof (long);
 168  168                          else if (size == sizeof (long))
 169  169                                  size = sizeof (long long);
 170  170                          goto again;
 171  171  
 172  172                  case 'd':
 173  173                          if (size == 0)
 174  174                                  x = va_arg(args, int);
 175  175                          else if (size == sizeof (long))
 176  176                                  x = va_arg(args, long);
 177  177                          else
 178  178                                  x = va_arg(args, long long);
 179      -                        dboot_putnum(x, is_signed, 10);
      179 +                        dboot_putnum(x, B_TRUE, 10);
 180  180                          break;
 181  181  
      182 +                case 'u':
      183 +                        base = 10;
      184 +                        goto unsigned_num;
      185 +
 182  186                  case 'b':
 183  187                          base = 2;
 184  188                          goto unsigned_num;
 185  189  
 186  190                  case 'o':
 187  191                          base = 8;
 188  192                          goto unsigned_num;
 189  193  
 190  194                  case 'x':
 191  195                          base = 16;
 192  196  unsigned_num:
 193  197                          if (size == 0)
 194  198                                  x = va_arg(args, uint_t);
 195      -                        else if (size == sizeof (long))
      199 +                        else if (size == sizeof (ulong_t))
 196  200                                  x = va_arg(args, ulong_t);
 197  201                          else
 198  202                                  x = va_arg(args, unsigned long long);
 199      -                        dboot_putnum(x, !is_signed, base);
      203 +                        dboot_putnum(x, B_FALSE, base);
 200  204                          break;
 201  205  
 202  206                  default:
 203  207                          dboot_puts("dboot_printf(): unknown % escape\n");
 204  208                  }
 205  209          }
 206  210  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX