Print this page
12208 dboot_printf(): support %u
@@ -19,10 +19,11 @@
* CDDL HEADER END
*/
/*
* Copyright (c) 2012 Gary Mills
+ * Copyright 2020 Joyent, Inc.
*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -91,11 +92,11 @@
++s;
}
}
static void
-dboot_putnum(uint64_t x, uint_t is_signed, uint8_t base)
+dboot_putnum(uint64_t x, boolean_t is_signed, uint8_t base)
{
char buffer[64]; /* digits in reverse order */
int i;
if (is_signed && (int64_t)x < 0) {
@@ -112,20 +113,19 @@
while (i >= 0)
bcons_putchar(buffer[i--]);
}
/*
- * very primitive printf - only does %s, %d, %x, %lx, or %%
+ * Very primitive printf - only does a subset of the standard format characters.
*/
static void
do_dboot_printf(char *fmt, va_list args)
{
char *s;
uint64_t x;
uint8_t base;
uint8_t size;
- uint_t is_signed = 1;
if (fmt == NULL) {
dboot_puts("dboot_printf(): 1st arg is NULL\n");
return;
}
@@ -157,11 +157,11 @@
dboot_puts(s);
break;
case 'p':
x = va_arg(args, ulong_t);
- dboot_putnum(x, !is_signed, 16);
+ dboot_putnum(x, B_FALSE, 16);
break;
case 'l':
if (size == 0)
size = sizeof (long);
@@ -174,13 +174,17 @@
x = va_arg(args, int);
else if (size == sizeof (long))
x = va_arg(args, long);
else
x = va_arg(args, long long);
- dboot_putnum(x, is_signed, 10);
+ dboot_putnum(x, B_TRUE, 10);
break;
+ case 'u':
+ base = 10;
+ goto unsigned_num;
+
case 'b':
base = 2;
goto unsigned_num;
case 'o':
@@ -190,15 +194,15 @@
case 'x':
base = 16;
unsigned_num:
if (size == 0)
x = va_arg(args, uint_t);
- else if (size == sizeof (long))
+ else if (size == sizeof (ulong_t))
x = va_arg(args, ulong_t);
else
x = va_arg(args, unsigned long long);
- dboot_putnum(x, !is_signed, base);
+ dboot_putnum(x, B_FALSE, base);
break;
default:
dboot_puts("dboot_printf(): unknown % escape\n");
}