- 论坛徽章:
- 0
|
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 |
|