GCC:禁止使用某些寄存器 [英] GCC: Prohibit use of some registers

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

问题描述

这是一个奇怪的要求,但我有一种感觉,这是可能的。我想是要插入一些编译指示或指令到我的code区域(用C写的),这样​​GCC的寄存器分配会的的使用它们。

This is a strange request but I have a feeling that it could be possible. What I would like is to insert some pragmas or directives into areas of my code (written in C) so that GCC's register allocator will not use them.

我知道我可以做这样的事情,其中​​的可能的预留该寄存器此变量

I understand that I can do something like this, which might set aside this register for this variable

register int var1 asm ("EBX") = 1984;
register int var2 asm ("r9") = 101;

问题是,我插入新的指令(硬件仿真器)直接和GCC和GAS还没有认识到这些。我的新指令可以使用​​现有的通用寄存器,我想确保我有一些保留它们(即r12-> R15)的。

The problem is that I'm inserting new instructions (for a hardware simulator) directly and GCC and GAS don't recognise these yet. My new instructions can use the existing general purpose registers and I want to make sure that I have some of them (i.e. r12->r15) reserved.

现在,我在样机的环境工作,我想很快做我的实验。今后我将追加GAS,并添加到内部函数GCC,但现在我正在寻找一个快速解决。

Right now, I'm working in a mockup environment and I want to do my experiments quickly. In the future I will append GAS and add intrinsics into GCC, but right now I'm looking for a quick fix.

谢谢!

推荐答案

在写GCC内联汇编,你可以指定一个揍名单 - 这可能是由您的内联汇编code覆盖寄存器列表。然后GCC将尽一切是需要在这些寄存器保存和恢复数据(或避免它们摆在首位使用)通过内联汇编段的课程。你也可以绑定的输入或输出寄存器到C变量。

When writing GCC inline assembler, you can specify a "clobber list" - a list of registers that may be overwritten by your inline assembler code. GCC will then do whatever is needed to save and restore data in those registers (or avoid their use in the first place) over the course of the inline asm segment. You can also bind input or output registers to C variables.

例如:

inline unsigned long addone(unsigned long v)
{
    unsigned long rv;
    asm("mov $1, %%eax;"
        "mov %0, %%ebx;"
        "add %%eax, %%ebx"
        : /* outputs */  "b" (rv)
        : /* inputs */   "g" (v) /* select unused general purpose reg into %0 */
        : /* clobbers */ "eax"
       );
}

有关详细信息,请参阅<一个href=\"http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss5.3\">GCC-Inline-Asm-HOWTO.

For more information, see the GCC-Inline-Asm-HOWTO.

这篇关于GCC:禁止使用某些寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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