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

▼魔方 西西 提交于 2019-12-11 13:42:04

问题


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?


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/26966514/why-u-boot-can-put-global-datas-address-into-r9-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!