如何通知GCC不要使用特定的寄存器 [英] How to inform GCC to not use a particular register

查看:158
本文介绍了如何通知GCC不要使用特定的寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个非常大的源代码,并且打算在执行过程中完全不使用 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:

http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/include/asm/global_data.h;h=4e3ea55e290a19c766017b59241615f7723531d5;hb=HEAD#l83

文件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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆