2
votes

I am trying to understand the U-boot source(2014.07). I could see the following code in arch/arm/cpu/armv7/lowlevel_init.S file.

#ifdef CONFIG_SPL_BUILD
        ldr     r9, =gdata
#else
        sub     sp, sp, #GD_SIZE
        bic     sp, sp, #7
        mov     r9, sp
#endif
        push    {ip, lr}
        bl      s_init
        pop     {ip, pc}

Can you please tell why sp is moved to r9 register - "mov r9, sp"(for SPL build gdata is loaded to r9 register- "ldr r9, =gdata"). Is there any specific use of r9 register, so that we are storing sp value to r9.

1
While it normally wouldn't be used as an argument, maybe it is. What's inside s_init? Since this is an open source project, could you also link to the sources?domen
The s_init function is setting up plls, mux configuration etc. The s_init is defined @ git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/cpu/armv7/…user3693586

1 Answers

3
votes

The general ABI set out by ARM in the Procedure Call Standard designates r9 as the "Platform Register":

A virtual platform may assign any role to this register and must document this usage. For example, it may designate it as the static base (SB) in a position-independent data model, or it may designate it as the thread register (TR) in an environment with thread-local storage. The usage of this register may require that the value held is persistent across all calls. A virtual platform that has no need for such a special register may designate r9 as an additional callee-saved variable register, v6.

In this case, the U-Boot ABI appears to use it for a global data pointer (see also arch/arm/lib/crt0.S and arch/arm/include/asm/global_data.h), but is perhaps falling short on the "must document this usage" point...