ARM为C调用约定,寄存器保存 [英] ARM to C calling convention, registers to save

查看:1882
本文介绍了ARM为C调用约定,寄存器保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经有一段时间,因为我最近codeD ARM汇编程序,我在细节上有点生疏。如果我把胳膊从C函数,我只担心节能R0-R3和LR,对不对?如果C函数使用任何其它寄存器,它是负责保存那些在堆栈上,并恢复他们吗?换句话说,编译器会生成code键为C函数做到这一点。例如,如果我在汇编函数中使用R10,我没有推堆栈上的价值,或C调用后内存和流行/恢复它,是吧?

It's been a while since I last coded arm assembler and I'm a little rusty on the details. If I call a C function from arm, I only have to worry about saving r0-r3 and lr, right? If the C function uses any other registers, is it responsible for saving those on the stack and restoring them? In other words, the compiler would generate code to do this for C functions. For example if I use r10 in an assembler function, I don't have to push its value on the stack, or to memory, and pop/restore it after a C call, do I?

这是对ARM-EABI-GCC 4.3.0。

This is for arm-eabi-gcc 4.3.0.

我知道我可以读取整个EABI,但随后shortcutting RTFM是什么,所以是吧? : - )

I realise I could read the whole EABI, but then shortcutting RTFM is what SO is for, right? :-)

推荐答案

这取决于 ABI 您正在编制的平台。在Linux中,有两个ARM的ABI;旧的和新的。据我所知,新一(EABI)其实是在ARM的AAPCS。完整的EABI定义目前居住这里ARM的信息中心

It depends on the ABI for the platform you are compiling for. On Linux, there are two ARM ABIs; the old one and the new one. AFAIK, the new one (EABI) is in fact ARM's AAPCS. The complete EABI definitions currently live here on ARM's infocenter.

AAPCS下,§5.1.1


  • R0-R3 的参数和寄存器; R0-R1 也是结果寄存器

  • R4-R8 被调用函数保存的寄存器

  • R9 可能是被叫保存登记或不(在AAPCS的一些变种它是一种特殊寄存器)

  • R10-R11 被调用函数保存的寄存器

  • R12-R15 的特殊寄存器

  • r0-r3 are the argument and scratch registers; r0-r1 are also the result registers
  • r4-r8 are callee-save registers
  • r9 might be a callee-save register or not (on some variants of AAPCS it is a special register)
  • r10-r11 are callee-save registers
  • r12-r15 are special registers

一个被调用者保存寄存器必须由被调用方保存(反对调用者保存寄存器,调用者保存寄存器);因此,的如果的,这是你使用,你不必调用另一个函数之前保存R10的ABI(另一个功能是负责保存它)。

A callee-save register must be saved by the callee (in opposition to a caller-save register, where the caller saves the register); so, if this is the ABI you are using, you do not have to save r10 before calling another function (the other function is responsible for saving it).

编辑:您使用作出其编译器没有什么区别;的gcc尤其可以被配置为多种不同的ABI,并且它甚至可以在命令行上的变化。纵观序言/结尾code将其产生是没有多大用处,因为它是为每个功能量身打造的的编译器可以使用保存的寄存器(例如,将其保存在其他的方法函数中)。

Which compiler you are using makes no difference; gcc in particular can be configured for several different ABIs, and it can even be changed on the command line. Looking at the prologue/epilogue code it generates is not that useful, since it is tailored for each function and the compiler can use other ways of saving a register (for instance, saving it in the middle of a function).

这篇关于ARM为C调用约定,寄存器保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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