Privia 发表于 2013-03-28 00:51

Uboot调用库函数memset程序跑飞,贴出反汇编代码

   我在移植Uboot的时候,在uboot stage 2 发现代码在调用memset库函数的时候就跑飞了,很郁闷,我之后用点灯和反汇编来看,但是没看出问题,我把代码贴出来给大家看看,看哪里出了问题。我用两次点灯来定位问题,发现点灯1操作能正常,点灯2就不正常了,断定memset没有调用成功。不知道哪里出了问题,大家帮忙看看,谢谢了啊 :)

C 代码:

/* ----------- Leds test chen ----------------------*/
        (*((volatile unsigned int *)0x7F008820)) = 0x0110;    //点灯1
        (*((volatile unsigned int *)0x7F008824)) = 0x0;
               
        memset ((void*)gd, 0, sizeof (gd_t));                //这里有问题

        while (1);
/* -------------------------------- ----------------------*/

void * memset(void * s,int c,size_t count)
{

        (*((volatile unsigned int *)0x7F008820)) = 0x1001;   //点灯2
        (*((volatile unsigned int *)0x7F008824)) = 0x0;
       
        unsigned long *sl = (unsigned long *) s;
        unsigned long cl = 0;
        char *s8;
        int i;

        /* do it one word at a time (32 bits or 64 bits) while possible */
        if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
                for (i = 0; i < sizeof(*sl); i++) {
                        cl <<= 8;
                        cl |= c & 0xff;
                }
                while (count >= sizeof(*sl)) {
                        *sl++ = cl;
                        count -= sizeof(*sl);
                }
        }
        /* fill 8 bits at a time */
        s8 = (char *)sl;
        while (count--)
                *s8++ = c;

        return s;
}


反汇编代码:
57e00808 <start_armboot>:
57e00808:         e59f3034         ldr        r3,         ; 57e00844 <start_armboot+0x3c>    //点灯1相关指令
57e0080c:         e92d4010         push        {r4, lr}
57e00810:         e5933000         ldr        r3,                       //点灯1相关指令
57e00814:         e2438941         sub        r8, r3, #1064960        ; 0x104000
57e00818:         e2488020         sub        r8, r8, #32        ; 0x20
57e0081c:         e59fe024         ldr        lr,         ; 57e00848 <start_armboot+0x40>   
57e00820:         e3a0c000         mov        ip, #0        ; 0x0
57e00824:         e3a03e11         mov        r3, #272        ; 0x110         //点灯1相关指令
57e00828:         e58e3820         str        r3,          //点灯1相关指令
57e0082c:         e1a0100c         mov        r1, ip
57e00830:         e1a00008         mov        r0, r8
57e00834:         e3a02020         mov        r2, #32        ; 0x20
57e00838:         e58ec824         str        ip,          //点灯1相关指令
57e0083c:         eb004628         bl        57e120e4 <memset>      //跳转memset执行
57e00840:         eafffffe         b        57e00840 <start_armboot+0x38>
57e00844:         57e00048         .word        0x57e00048
57e00848:         7f008000         .word        0x7f008000


57e120e4 <memset>:
57e120e4:         e59f3088         ldr        r3,         ; 57e12174 <memset+0x90>         //点灯2相关指令
57e120e8:         e92d4010         push        {r4, lr}
57e120ec:        e210c003         ands        ip, r0, #3        ; 0x3
57e120f0:        e1a04000         mov        r4, r0
57e120f4:        e59f007c         ldr        r0,         ; 57e12178 <memset+0x94>          //点灯2相关指令
57e120f8:        e5830820         str        r0,                 //点灯2相关指令
57e120fc:        e3a00000         mov        r0, #0        ; 0x0
57e12100:         e5830824         str        r0,                //点灯2相关指令
57e12104:         e1a00004         mov        r0, r4
57e12108:         1a000010         bne        57e12150 <memset+0x6c>
57e1210c:         e1a0000c         mov        r0, ip
57e12110:         e2800001         add        r0, r0, #1        ; 0x1
57e12114:         e20130ff         and        r3, r1, #255        ; 0xff
57e12118:         e3500004         cmp        r0, #4        ; 0x4
57e1211c:         e183c40c         orr        ip, r3, ip, lsl #8
57e12120:         1afffffa         bne        57e12110 <memset+0x2c>
57e12124:         e1a00002         mov        r0, r2
57e12128:         e3a03000         mov        r3, #0        ; 0x0
57e1212c:         ea000001         b        57e12138 <memset+0x54>
57e12130:         e784c003         str        ip,
57e12134:         e2833004         add        r3, r3, #4        ; 0x4
57e12138:         e3500003         cmp        r0, #3        ; 0x3
57e1213c:         e2400004         sub        r0, r0, #4        ; 0x4
57e12140:         8afffffa         bhi        57e12130 <memset+0x4c>
57e12144:         e3c23003         bic        r3, r2, #3        ; 0x3
57e12148:         e0840003         add        r0, r4, r3
57e1214c:         e2022003         and        r2, r2, #3        ; 0x3
57e12150:         e3a03000         mov        r3, #0        ; 0x0
57e12154:         ea000001         b        57e12160 <memset+0x7c>
57e12158:         e7c01003         strb        r1,
57e1215c:         e2833001         add        r3, r3, #1        ; 0x1
57e12160:         e3520000         cmp        r2, #0        ; 0x0
57e12164:         e2422001         sub        r2, r2, #1        ; 0x1
57e12168:         1afffffa         bne        57e12158 <memset+0x74>
57e1216c:         e1a00004         mov        r0, r4
57e12170:         e8bd8010         pop        {r4, pc}
57e12174:         7f008000         .word        0x7f008000
57e12178:         00001001         .word        0x00001001

txgc_wm 发表于 2013-03-28 18:04

楼主,是不是可作如下测试:

将memset ((void*)gd, 0, sizeof (gd_t));中的变量更改为其它的进行测试。

Privia 发表于 2013-03-30 22:13

回复 2# txgc_wm


    OK 谢谢提醒,我去试试看 嘿嘿 :)
页: [1]
查看完整版本: Uboot调用库函数memset程序跑飞,贴出反汇编代码