免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1067 | 回复: 0
打印 上一主题 下一主题

U-boot And GOT [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-30 15:06 |只看该作者 |倒序浏览

Disassemble u-boot
mips_fp_be-objdump -D u-boot

Some segment
bfc00400 reset>:
……
bfc00440:    04110002     bal    bfc0044c reset+0x4c>
bfc00444:    00000000     nop
bfc00448:    bfc34500     cache    0x3,17664(s8)
bfc0044c:    03e0e021     move    gp,ra
bfc00450:    8fe90000     lw    t1,0(ra)
bfc00454:    0120e021     move    gp,t1

bfc00458:    8f9902b0     lw    t9,688(gp)
bfc0045c:    0320f809     jalr    t9
bfc00460:    00000000     nop
bfc00464:    8f9904ec     lw    t9,1260(gp)
bfc00468:    0320f809     jalr    t9
bfc0046c:    00000000     nop
……

bfc07a70 lowlevel_init>:
bfc07a70:    3c08a043     lui    t0,0xa043
……
bfc0fa90 mips_cache_reset>:
bfc0fa90:    240a4000     li    t2,16384
……
bfc34500 _GLOBAL_OFFSET_TABLE_>:
bfc34500:    00000000     nop
bfc34504:    80000000     lb    zero,0(zero)
bfc34508:    bfc00000     cache    0x0,0(s8)
bfc3450c:    bfc30000     cache    0x3,0(s8)
bfc34510:    bfc10000     cache    0x1,0(s8)
bfc34514:    bfc20000     cache    0x2,0(s8)
……
bfc347b0:    bfc07a70     cache    0x0,31344(s8)
bfc347b4:    bfc35154     cache    0x3,20820(s8)
bfc347b8:    bfc16fb0     cache    0x1,28592(s8)
……
bfc349e8:    bfc20144     cache    0x2,324(s8)
bfc349ec:    bfc0fa90     cache    0x0,-1392(s8)
bfc349f0:    bfc1336c     cache    0x1,13164(s8)
……
reset:
    ……
    /* Initialize GOT pointer.
    */
    bal 1f
    nop
    .word _GLOBAL_OFFSET_TABLE_
    1:
    move gp, ra
    lw t1, 0(ra)
    move    gp, t1
    /* Initialize any external memory.
     */
    la t9, lowlevel_init
    jalr t9
    nop
    /* Initialize caches...
     */
    la t9, mips_cache_reset
    jalr t9
    nop   

Analysis
Initialize the GOT pointer
“bal 1f” load the the address of _GLOBAL_OFFSET_TABLE_ into ra.
“lw t1, 0(ra)” load the destination register (ra) with the contents of the word that is at the memory location.
Finally, GOT header is saved into gp.

Example 1: Get the address of lowlevel_init
Use assemble code, the following sentence can get the address.

       la      t9, lowlevel_init

But in final code, to get the location-independent address, u-boot adds the gp and an offset to get the address.

bfc00458:       8f9902b0       lw    t9,688(gp)

Please refer to the GOT table, start at “bfc34500 ”.
The address of GOT is 0xbfc34500, the offset is 688 (0x2b0), the result is 0xbfc347b0. The content of address 0xbfc347b0 is 0xbfc07a70. And the address 0xbfc07a70 just is the address of lowlevel_init.
Example 2: Get the address of mips_cache_reset
The address of mips_cache_reset is:
0xbfc0fa90 = 0xbfc34500 + 0x4ec.

Question



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/22020/showart_1096960.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP