⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diag.cxx

📁 移植到WLIT项目的redboot源代码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
        int i;        diag_write_string("<Bad format string: ");        diag_write_hex((cyg_uint32)fmt);        diag_write_string(" :");        for( i = 0; i < 8; i++ )        {            diag_write_char(' ');            diag_write_hex(args[i]);        }        diag_write_string(">\n");        return;    }        while( *fmt != '\0' )    {        char c = *fmt;        if( c != '%' ) diag_write_char( c );        else        {            cyg_bool pfzero = false;            cyg_count8 width = 0;            char sign = '+';            cyg_bool long_op = false;                                    c = *++fmt;                                    if( c == '0' ) pfzero = true;            while( '0' <= c && c <= '9' )            {                width = width*10 + c - '0';                c = *++fmt;            }            if (c == 'l') {                // %lx and %ld are equivalent to %x/%d                c = *++fmt;                // %llx or %lld used to indicate (long long) operand                if (c == 'l') {                    long_op = true;                    c = *++fmt;                }            }            switch( c )            {            case 'd':            case 'D':            {                if (long_op) {                    long long *lp = (long long *)args;                    long long val = *lp++;                    args = (CYG_ADDRWORD *)lp;                    if( val < 0 ) val = -val, sign = '-';                    diag_write_long_num(val, 10, sign, pfzero, width);                } else {                    long val = (long)(*args++);                    if( val < 0 ) val = -val, sign = '-';                    diag_write_num(val, 10, sign, pfzero, width);                }                break;            }            case 'x':            case 'X':            {                if (long_op) {                    long long *lp = (long long *)args;                    long long val = *lp++;                    args = (CYG_ADDRWORD *)lp;                    diag_write_long_num(val, 16, sign, pfzero, width);                } else {                    unsigned long val = (long)(*args++);                    diag_write_num(val, 16, sign, pfzero, width);                }                break;            }            case 'c':            case 'C':            {                char ch = (char)(*args++);                diag_write_char(ch);                break;            }            case 's':            case 'S':            {                char *s = (char *)(*args++);                cyg_count32 len = 0;                cyg_count32 pre = 0, post = 0;                if( s == NULL ) s = "<null>";                else if( !diag_check_string(s) )                {                    diag_write_string("<Not a string: 0x");                    diag_write_hex((cyg_uint32)s);                    s = ">";                    if( width > 25 ) width -= 25;                    pfzero = false;                    /* Drop through to print the closing ">" */                    /* and pad to the required length.       */                }                                while( s[len] != 0 ) len++;                                if( width && len > width ) len = width;                if( pfzero ) pre = width-len;                else post = width-len;                while( pre-- > 0 ) diag_write_char(' ');                while( *s != '\0' && len-- != 0)                    diag_write_char(*s++);                while( post-- > 0 ) diag_write_char(' ');                                                break;            }            case 'b':            case 'B':            {                unsigned long val = (unsigned long)(*args++);                cyg_uint32 i;                if( width == 0 ) width = 32;                for( i = width-1; i >= 0; i-- )                    diag_write_char( (val&(1<<i))?'1':'.' );                                                break;            }            case '%':                diag_write_char('%');                break;            default:                diag_write_char('%');                diag_write_char(c);                break;            }        }        fmt++;    }       }/*-----------------------------------------------------------------------*//* Formatted diagnostic output.                                          */#ifdef CYGDBG_INFRA_DIAG_PRINTF_USE_VARARGexternC void diag_printf(const char *fmt, ... ){        CYG_ADDRWORD args[8];    va_list a;    va_start(a, fmt);    /* Move all of the arguments into simple scalars. This avoids     * having to use varargs to define diag_vprintf().     */        args[0] = va_arg(a,CYG_ADDRWORD);    args[1] = va_arg(a,CYG_ADDRWORD);    args[2] = va_arg(a,CYG_ADDRWORD);    args[3] = va_arg(a,CYG_ADDRWORD);    args[4] = va_arg(a,CYG_ADDRWORD);    args[5] = va_arg(a,CYG_ADDRWORD);    args[6] = va_arg(a,CYG_ADDRWORD);    args[7] = va_arg(a,CYG_ADDRWORD);    va_end(a);        diag_vprintf( fmt, args);}#else/* The prototype for diag_printf in diag.h is defined using K&R syntax   *//* to allow us to use a variable number of arguments in the call without *//* using ellipses, which would require use of varargs stuff. If we ever  *//* need to support arguments that are not simple words, we may need to   *//* use varargs.                                                          *//* For the actual implementation, a normal ANSI C prototype is           *//* acceptable.                                                            */externC void diag_printf(const char *fmt, CYG_ADDRWORD a1, CYG_ADDRWORD a2,                         CYG_ADDRWORD a3, CYG_ADDRWORD a4,                         CYG_ADDRWORD a5, CYG_ADDRWORD a6,                         CYG_ADDRWORD a7, CYG_ADDRWORD a8){        CYG_ADDRWORD args[8];    args[0] = a1;    args[1] = a2;    args[2] = a3;    args[3] = a4;    args[4] = a5;    args[5] = a6;    args[6] = a7;    args[7] = a8;        diag_vprintf( fmt, args);}#endifstatic voiddiag_dump_buf_with_offset(cyg_uint8     *p,                           CYG_ADDRWORD   s,                           cyg_uint8     *base){    int i, c;    if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {        s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;    }    while ((int)s > 0) {        if (base) {            diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);        } else {            diag_printf("%08X: ", p);        }        for (i = 0;  i < 16;  i++) {            if (i < (int)s) {                diag_printf("%02X", p[i] & 0xFF);            } else {                diag_printf("  ");            }            if ((i % 2) == 1) diag_printf(" ");            if ((i % 8) == 7) diag_printf(" ");        }        diag_printf(" |");        for (i = 0;  i < 16;  i++) {            if (i < (int)s) {                c = p[i] & 0xFF;                if ((c < 0x20) || (c >= 0x7F)) c = '.';            } else {                c = ' ';            }            diag_printf("%c", c);        }        diag_printf("|\n");        s -= 16;        p += 16;    }}externC voiddiag_dump_buf(void *p, CYG_ADDRWORD s){   diag_dump_buf_with_offset((cyg_uint8 *)p, s, 0);}/*-----------------------------------------------------------------------*//* EOF infra/diag.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -