是否保存了rdi和rsi呼叫者或被呼叫者保存的寄存器? [英] Are rdi and rsi caller saved or callee saved registers?

查看:324
本文介绍了是否保存了rdi和rsi呼叫者或被呼叫者保存的寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Wikipedia x86调用约定中,它表示对于Microsoft x64调用约定:

From the wikipedia x86 calling convention, it says that for the Microsoft x64 calling convention:

寄存器RBX,RBP, RDI,RSI ,RSP,R12,R13,R14和R15被认为是非易失性的(保存被调用者).

The registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15 are considered nonvolatile (callee-saved).

但是对于System V AMD64 ABI:

But for System V AMD64 ABI:

如果被叫方希望使用寄存器RBX,RBP和R12-R15,则必须在恢复控制权之前将其恢复为原始状态.

If the callee wishes to use registers RBX, RBP, and R12–R15, it must restore their original values before returning control to the caller.

它没有提及有关rdi和rsi的任何内容.

It did not mention anything about rdi and rsi.

我还读到%rax,%rcx,%rdx,%rdi,%rsi ,%rsp和%r8-r11被视为保存调用者的寄存器 (来自pdf)

I also read that %rax, %rcx, %rdx, %rdi, %rsi, %rsp, and %r8-r11 are considered caller-save registers (from a pdf)

我的问题是,在不同平台上调用约定是否不同?(我尝试在unix环境下的asm中编写一些libc函数)

My question is, is calling convention various across different platform?(I try to write some libc function in asm for unix environment)

我找不到任何讨论此主题的文章,该主题的资源也将有所帮助.我想知道这些约定的优点和缺点.

I could not find any article discussing about this topic, resources to this topic will be helpful as well. I wanted to know the advantage and disadvantage of these conventions.

推荐答案

是的,在我所知道的所有函数调用约定中,传递arg的寄存器都被调用了.(除了用于系统调用的调用约定,通常会保留除返回值(包括arg-passing)之外的所有reg.x86-64syscall会破坏RCX和R11 ...)

Yes, in all function-calling conventions I'm aware of, the arg-passing registers are call-clobbered. (Except for system-call calling conventions, where normally all regs are preserved except a return value, including arg-passing. Except that x86-64 syscall destroys RCX and R11...)

特别是在x86-64系统V中,除RBX,RBP,RSP和R12-R15以外的所有寄存器都被调用. (其中包括xmm0-15,x87/mmx寄存器以及AVX512 zmm0-31和k0-k7掩码寄存器.)

Specifically in x86-64 System V, all registers other than RBX, RBP, RSP, and R12-R15 are call-clobbered. (That includes xmm0-15, x87/mmx registers, and AVX512 zmm0-31 and k0-k7 mask regs.)

保留了哪些寄存器通过linux x86-64函数调用显示了ABI文档中的表格.

What registers are preserved through a linux x86-64 function call shows the table from the ABI doc.

调用约定/ABI将寄存器的状态定义为保留呼叫或保留呼叫的状态.不同的约定可以做出不同的选择.

The calling convention / ABI defines the status of registers as call-preserved or call-clobbered. Different conventions can make different choices.

是的,Microsoft Windows选择了与其他所有人不同的调用约定:

And yes, Microsoft Windows chose a different calling convention from everyone else: Why does Windows64 use a different calling convention from all other OSes on x86-64? In Windows x64, RDI is call-preserved, like in most 32-bit calling conventions.

但是在x86-64 System V中,设计人员从头开始选择寄存器,并且(如我对这个链接问题的回答所示)发现,对于前2个args使用RDI和RSI可以节省指令(在使用早期x86构建SPECint时) -64 gcc端口).可能是因为当时的gcc喜欢使用rep stosd内联memsetmemcpy,或者库实现使用了它.

But in x86-64 System V, the designers chose registers from scratch, and (as my answer on that linked question shows) found that using RDI and RSI for the first 2 args saved instructions (when building SPECint with an early x86-64 port of gcc). Probably because gcc at the time liked to inline memset or memcpy using rep stosd, or the library implementation used that.

(说RDI本质上是呼叫对象,x86-64 ISA对此没有定义.这取决于每个平台来选择.)

(It makes no sense to say that RDI is intrinsically call-clobbered, the x86-64 ISA doesn't define that. It's up to each platform to choose that.)

术语:

我讨厌保存呼叫者"与保存被呼叫者"这两个术语:从两种不同的角度(呼叫者和被呼叫者)思考是令人困惑的,并且错误地暗示每个寄存器都被保存每个call.另外,名称之间仅相差1个字母,因此阅读时在视觉上并没有很大区别.

I hate the "caller saved" vs. "callee saved" terminology: It's confusing to think from 2 different perspectives (caller and callee), and wrongly implies that every register does get saved somewhere on every call. Also, the names only differ by 1 letter, so aren't very visually distinct when reading.

保留"或断断续续"很棒;他们从任何一个角度工作. (被呼叫者将对您的规则执行什么操作,或者您被允许对呼叫者的规则进行操作.)此外,它们是不言自明的.

"preserved" or "clobbered" are great; they work from either perspective. (What a callee will do to your regs, or what you're allowed to do to the caller's regs.) Moreover, they're self-explanatory.

这篇关于是否保存了rdi和rsi呼叫者或被呼叫者保存的寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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