44#include <BoardConsole.h>
55#include <osdebug.h>
66
7- static const char hex_conv [] = "0123456789ABCDEF" ;
7+ static const char * hex_conv [2 ] =
8+ {
9+ "0123456789abcdef" , // lower-case
10+ "0123456789ABCDEF" // upper-case
11+ };
12+
813static void dbgput (const void * _str , int n ) {
914 const char * str = (const char * ) _str ;
1015 while (n -- )
@@ -29,6 +34,7 @@ void osDbgPrintf(const char * str, ...) {
2934 long arg_i ;
3035 uintptr_t arg_p ;
3136 int str_size , i ;
37+ int ucase = 0 ;
3238
3339 va_start (ap , str );
3440
@@ -75,7 +81,7 @@ void osDbgPrintf(const char * str, ...) {
7581 tmp_conv_ptr = tmp_n_conv + 32 ;
7682 * tmp_conv_ptr = 0 ;
7783 do {
78- * -- tmp_conv_ptr = hex_conv [arg_u % 10 ];
84+ * -- tmp_conv_ptr = hex_conv [0 ][ arg_u % 10 ];
7985 arg_u /= 10 ;
8086 } while (arg_u );
8187 dbgput (tmp_conv_ptr , strlen (tmp_conv_ptr ));
@@ -84,20 +90,25 @@ void osDbgPrintf(const char * str, ...) {
8490 arg_p = va_arg (ap , uintptr_t );
8591 dbgput ("0x" , 2 );
8692 for (i = sizeof (arg_p ) * 2 - 1 ; i >= 0 ; i -- ) {
87- dbgput (& hex_conv [(arg_p >> (i << 2 )) & 15 ], 1 );
93+ dbgput (& hex_conv [1 ][ (arg_p >> (i << 2 )) & 15 ], 1 );
8894 }
8995 break ;
96+ case 'X' : // same as x but uppercase for alpha chars
97+ ucase = 1 ;
98+ // fall through
9099 case 'x' :
91100 arg_u = va_arg (ap , unsigned long );
92101 seen_something = 0 ;
102+ const char * hex_p = hex_conv [ucase ];
93103 for (i = sizeof (arg_p ) * 2 - 1 ; i >= 0 ; i -- ) {
94104 if (!seen_something && ((arg_u >> (i << 2 )) == 0 ))
95105 continue ;
96- dbgput (& hex_conv [(arg_u >> (i << 2 )) & 15 ], 1 );
106+ dbgput (& hex_p [(arg_u >> (i << 2 )) & 15 ], 1 );
97107 seen_something = 1 ;
98108 }
99109 if (!seen_something )
100110 dbgput ("0" , 1 );
111+ ucase = 0 ;
101112 break ;
102113 case 0 : // malformed format string with a trailing %.
103114 dbgput ("%" , 1 );
0 commit comments