debuggers.hg

changeset 22808:7e42363f9005

hvmloader: Fixes to printf() implementation.

1. Remove unportable O and D format specifiers
2. Fix X format specifier to print upper-case hex characters
3. Fix d format specifier to print -ve numbers
4. Fix handling of int vs. long (although not actually an issue
for the i386 compile target)
5. Don't use the antiquated C 'register' type attribute.

Signed-off-by: Keir Fraser <keir@xen.org>
author Keir Fraser <keir@xen.org>
date Fri Jan 14 15:21:24 2011 +0000 (2011-01-14)
parents 47d67a64a2d2
children 3ce532e56efd
files tools/firmware/hvmloader/util.c
line diff
     1.1 --- a/tools/firmware/hvmloader/util.c	Fri Jan 14 15:18:02 2011 +0000
     1.2 +++ b/tools/firmware/hvmloader/util.c	Fri Jan 14 15:21:24 2011 +0000
     1.3 @@ -425,10 +425,10 @@ static char *printnum(char *p, unsigned 
     1.4  
     1.5  static void _doprint(void (*put)(char), const char *fmt, va_list ap)
     1.6  {
     1.7 -    register char *str, c;
     1.8 +    char *str, c;
     1.9      int lflag, zflag, nflag;
    1.10      char buffer[17];
    1.11 -    unsigned value;
    1.12 +    unsigned long value;
    1.13      int i, slen, pad;
    1.14  
    1.15      for ( ; *fmt != '\0'; fmt++ )
    1.16 @@ -457,29 +457,40 @@ static void _doprint(void (*put)(char), 
    1.17              lflag = 1;
    1.18              c = *++fmt;
    1.19          }
    1.20 -        if ( (c == 'd') || (c == 'u') || (c == 'o') || (c == 'x') )
    1.21 +        if ( (c == 'd') || (c == 'u') || (c == 'o') ||
    1.22 +             (c == 'x') || (c == 'X') )
    1.23          {
    1.24              if ( lflag )
    1.25 -                value = va_arg(ap, unsigned);
    1.26 +            {
    1.27 +                value = va_arg(ap, unsigned long);
    1.28 +                if ( (c == 'd') && ((long)value < 0) )
    1.29 +                {
    1.30 +                    value = -value;
    1.31 +                    put('-');
    1.32 +                }
    1.33 +            }
    1.34              else
    1.35 -                value = (unsigned) va_arg(ap, unsigned int);
    1.36 +            {
    1.37 +                value = va_arg(ap, unsigned int);
    1.38 +                if ( (c == 'd') && ((int)value < 0) )
    1.39 +                {
    1.40 +                    value = -(int)value;
    1.41 +                    put('-');
    1.42 +                }
    1.43 +            }
    1.44              str = buffer;
    1.45              printnum(str, value,
    1.46 -                     c == 'o' ? 8 : (c == 'x' ? 16 : 10));
    1.47 -            goto printn;
    1.48 -        }
    1.49 -        else if ( (c == 'O') || (c == 'D') || (c == 'X') )
    1.50 -        {
    1.51 -            value = va_arg(ap, unsigned);
    1.52 -            str = buffer;
    1.53 -            printnum(str, value,
    1.54 -                     c == 'O' ? 8 : (c == 'X' ? 16 : 10));
    1.55 -        printn:
    1.56 +                     c == 'o' ? 8 : ((c == 'x') || (c == 'X') ? 16 : 10));
    1.57              slen = strlen(str);
    1.58              for ( i = pad - slen; i > 0; i-- )
    1.59                  put(zflag ? '0' : ' ');
    1.60              while ( *str )
    1.61 -                put(*str++);
    1.62 +            {
    1.63 +                char ch = *str++;
    1.64 +                if ( (ch >= 'a') && (c == 'X') )
    1.65 +                    ch += 'A'-'a';
    1.66 +                put(ch);
    1.67 +            }
    1.68          }
    1.69          else if ( c == 's' )
    1.70          {