From a09427a54632f57e50512db7b923e90675e8fe69 Mon Sep 17 00:00:00 2001 From: Kinjal Pravinbhai Patel Date: Tue, 7 Jul 2015 10:55:12 +0530 Subject: [PATCH] bsp: a53: added 64bit print support in xil_printf This patch modifies xil_printf to add support for 64bit pointer value print in case of 64bit mode. It adds support to print 64 bit value for long integer and long hex. It also removes unknown specifier 'D'. Signed-off-by: Kinjal Pravinbhai Patel --- .../src/cortexa53/64bit/xil_printf.c | 71 +++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/lib/bsp/standalone/src/cortexa53/64bit/xil_printf.c b/lib/bsp/standalone/src/cortexa53/64bit/xil_printf.c index 8d13cc14..964dc14d 100644 --- a/lib/bsp/standalone/src/cortexa53/64bit/xil_printf.c +++ b/lib/bsp/standalone/src/cortexa53/64bit/xil_printf.c @@ -135,6 +135,61 @@ static void outnum( const s32 n, const s32 base, params_t *par) padding( par->left_flag, par); } +/*---------------------------------------------------*/ +/* */ +/* This routine moves a 64-bit number to the output */ +/* buffer as directed by the padding and positioning */ +/* flags. */ +/* */ + +static void outnum1( const s64 n, const s32 base, params_t *par) +{ + charptr cp; + s32 negative; + s32 i; + char8 outbuf[64]; + const char8 digits[] = "0123456789ABCDEF"; + u64 num; + for(i = 0; i<64; i++) { + outbuf[i] = '0'; + } + + /* Check if number is negative */ + if ((par->unsigned_flag == 0) && (base == 10) && (n < 0L)) { + negative = 1; + num =(-(n)); + } + else{ + num = (n); + negative = 0; + } + + /* Build number (backwards) in outbuf */ + i = 0; + do { + outbuf[i] = digits[(num % base)]; + i++; + num /= base; + } while (num > 0); + + if (negative != 0) { + outbuf[i] = '-'; + i++; + } + + outbuf[i] = 0; + i--; + + /* Move the converted number to the buffer and */ + /* add in the padding where needed. */ + par->len = (s32)strlen(outbuf); + padding( !(par->left_flag), par); + while (&outbuf[i] >= outbuf) { + outbyte( outbuf[i] ); + i--; +} + padding( par->left_flag, par); +} /*---------------------------------------------------*/ /* */ /* This routine gets a number from the format */ @@ -270,8 +325,8 @@ void xil_printf( const char8 *ctrl1, ...) /* fall through */ case 'i': case 'd': - if ((long_flag != 0) || (ch == 'D')) { - outnum( va_arg(argp, s32), 10L, &par); + if (long_flag != 0){ + outnum1((s64)va_arg(argp, s64), 10L, &par); } else { outnum( va_arg(argp, s32), 10L, &par); @@ -279,10 +334,18 @@ void xil_printf( const char8 *ctrl1, ...) Check = 1; break; case 'p': - case 'X': + par.unsigned_flag = 1; + outnum1((s64)va_arg(argp, s64), 16L, &par); + Check = 1; + break; case 'x': par.unsigned_flag = 1; - outnum((s32)va_arg(argp, s32), 16L, &par); + if (long_flag != 0) { + outnum1((s64)va_arg(argp, s64), 16L, &par); + } + else { + outnum((s32)va_arg(argp, s32), 16L, &par); + } Check = 1; break;