如何通知GCC不要使用特定的寄存器 [英] How to inform GCC to not use a particular register
问题描述
假设我有一个非常大的源代码,并且打算在执行过程中完全不使用 rdx寄存器,即在生成汇编代码时,我要通知的是我的编译器(GCC)它不应该使用 rdx
Assume I have a very big source code and intend to make 'rdx' register totally unused during the execution i.e. While generating the assembly code, all I want is to inform my compiler (GCC) that it should not use 'rdx' at all.
注意:注册rdx只是一个例子。我可以使用任何可用的Intel x86寄存器
我什至很高兴更新编译器的源代码并使用我的自定义GCC。但是在哪里可以更改源代码?
I am even happy to update the source code of compiler and use my custom GCC. But where to change in source code?
推荐答案
您可以在此寄存器中放置一些全局变量。
对于ARM CPU,您可以这样操作:
You can put some global variable to this register. For ARM CPU you can do it this way:
注册易失性类型* global_ptr asm( r8)
此指令使用通用寄存器 r8来保存
,其值为 global_ptr
This instruction uses general purpose register "r8" to hold
the value of global_ptr
pointer.
有关实际示例,请参见U-Boot中的源代码:
See the source in U-Boot for real-life example:
文件arch / arm / include / asm / global_data.h(第83行)。
File arch/arm/include/asm/global_data.h (line ~83).
#define DECLARE_GLOBAL_DATA_PTR寄存器volatile gd_t * gd asm( r8)
这篇关于如何通知GCC不要使用特定的寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!