ldr pc _start_armboot
_start_armboot: .word start_armboot
start_armboot是一个函数指针,这个symbol对应了符号表里的函数地址,这个函数是一个C语言的函数,他就是u-boot的stage2的入口点,这个stage2应该是在RAM里面执行的。问题就来了,既然我们只是手动将text relocate到了RAM里面,此时FLASH和RAM里面都有start_armboot的代码,为什么程序就要跳转到RAM里,而不是依然在FLASH里?
我最初感觉除非是ld在连接的时候,修改了符号表里的内容,指定start_armboot符号的地址是RAM里的地址,这样只要我们执行时取其地址,取到的肯定是RAM中的地址。
经查阅资料,有如下一段解释:
转自:http://www.mail-archive.com/u-boot-users@lists.sourceforge.net/msg04018.html
----- Original Message ----
> > > > From: Vishal Oliyil Kunnil
> > > > To: Tiju
> > > >
> > > > Sent: Monday, 31 March, 2008 2:58:12 PM
> > > > Subject: Re: [U-Boot-Users] s3c2440 -- serial_init
> > > >
> > > > TEXT_BASE is the address for which u-boot is linked for.If you take an
> > > > objdump of u-boot
> > > > elf, you will see that it links for address beginning with that
> > > > specified by TEXT_BASE.
> > > > Meaning, you link for the address thus specified.
> > > > Typically the binary will be run from the reset vector of the
> > > > processor, which is not necessarily
> > > > TEXT_BASE : say 0x0 flash address. U-boot starts executing from the
> > > > reset vector,
> > > > relocates to RAM and since it is linked for TEXT_BASE, the ldr pc,
> > > > _start_armboot
> > > > will branch to the start_armboot which is in RAM.
> > > > -------snip - start.S --------------
> > > > ldr pc, _start_armboot
> > > > _start_armboot: .word start_armboot
> > > > -------snip - start.S --------------
> > > > Regards,
> > > > Vishal 上面的意思是说,我们在u-boot的C代码的编译环境里制定了TEXT_BASE的值,然后所有生成的C函数的可执行代码都是以TEXT_BASE作为连接基地址,而不是我们的0x00000000(u-boot在FLASH开始执行的起始地址),也就是说这是我们u-boot的代码中在FLASH里,除了最开始的一部分汇编码是在FLASH里执行的,其他由C语言实现的部分都只能在RAM里执行,因为我们给他们定好的基地址就是RAM的地址。
本文转自:http://blog.chinaunix.net/u2/72383/showart_1071034.html