assembly ARM64中栈指针的行为

s5a0g9ez  于 2023-11-19  发布在  其他
关注(0)|答案(1)|浏览(139)

由于ARM 64中缺少PUSH和POP指令,我在理解SP在ARM 64中的工作方式方面遇到了问题。
如果我要PUSH/POP,SP会减少/增加4、8还是16个字节?
我在阅读文档中说堆栈帧必须以16个字节对齐,但当我调试时,情况似乎并非如此。

xytpbqjk

xytpbqjk1#

堆栈是向上增长还是向下增长完全取决于您正在查看的系统的ABI。也就是说,我必须处理的所有arm 64代码都有向下增长的堆栈。
有了这个,一个常见的推动看起来像这样:

stp x29, x30, [sp, -0x10]!

字符串
像这样的流行音乐:

ldp x29, x30, [sp], 0x10


很明显,这会一次压入/弹出两个寄存器,从而一次修改堆栈指针16个字节,这将我们带到下一部分:
堆栈对齐检查。堆栈指针是否必须与16字节边界对齐 * 也 * 取决于您正在使用的ABI,但这是一个可以配置的实际硬件功能。参见the ARMv8 Reference ManualSCTLR_EL[123]包括为每个异常级别打开或关闭此功能的位。引用SCTLR_EL1,例如:

**SA0, bit [4]**

    SP Alignment check enable for EL0. When set to 1, if a load or store
    instruction executed at EL0 uses the SP as the base address and the SP is not
    aligned to a 16-byte boundary, then a SP alignment fault exception is
    generated. For more information, see SP alignment checking on page D1-2333.

    When ARMv8.1-VHE is implemented, and the value of HCR_EL2.{E2H, TGE} is
    {1, 1}, this bit has no effect on execution at EL0.

    In a system where the PE resets into EL1, this field resets to an
    architecturally UNKNOWN value.

**SA, bit [3]**

    SP Alignment check enable. When set to 1, if a load or store instruction
    executed at EL1 uses the SP as the base address and the SP is not aligned to
     a 16-byte boundary, then a SP alignment fault exception is generated. For
    more information, see SP alignment checking on page D1-2333.

    When ARMv8.1-VHE is implemented, and the value of HCR_EL2.{E2H, TGE} is
    {1, 1}, this bit has no effect on the PE.

    In a system where the PE resets into EL1, this field resets to an
    architecturally UNKNOWN value.

相关问题