Why u-boot can put global data's address into r9 register?

768 views Asked by At

When i look through u-boot source code, i found that it pass global data through r9 register like this

register volatile gd_t *gd asm ("r9")

So, i'm curious, how does u-boot ensure further codes won't use r9 register and corrupt the global data. Is there an options to tell compiler not to use specific register?

2

There are 2 answers

0
auselen On BEST ANSWER

From Procedure Call Standard for the ARM Architecture:

The role of register r9 is platform specific. 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.

Yet GCC doesn't have a abi profile for reserving r9 for platform usage thus the way u-boot does this is with -ffixed-r9 option.

6
David Wohlferd On

Well, there is -ffixed-reg. However, if all code is compiled with this variable declared as global, then it will never be used for any other purpose (see https://gcc.gnu.org/onlinedocs/gcc/Global-Reg-Vars.html#Global-Reg-Vars).