ARM 中的指令回写

时间:2021-02-08 18:17:11

标签: assembly arm arm64 armv8

ARM 参考手册指出:

<块引用>

如果 Load 指令指定回写并且正在加载的寄存器也是基址寄存器,则行为是 CONSTRAINEDUNPREDICTABLE

在这种情况下,“回写”一词是什么意思?

1 个答案:

答案 0 :(得分:2)

“ldr(立即)”指令有三种形式:

ldr x0, [x1, 8]
ldr x0, [x1, 8]!
ldr x0, [x1], 8

第一个应该很明显,并且是“常规”语法。
第二个称为预索引,相当于:

add x1, x1, 8
ldr x0, [x1]

第三个称为后索引,相当于:

ldr x0, [x1]
add x1, x1, 8

手册中提到的情况是这样的:

ldr x0, [x0, 8]!
ldr x0, [x0], 8

在那种情况下(来自 the G.a version 的第 K1-8255 页):

CONSTRAINED UNPREDICTABLE behavior

If the instruction encoding specifies pre-indexed addressing or post-indexed
addressing, and n == t && n != 31, then one of the following behaviors must
occur:

•   The instruction is UNDEFINED.
•   The instruction executes as a NOP.
•   The instruction performs the load using the specified addressing mode,
    and the base register is set to an UNKNOWN value. In addition, if an
    exception occurs during such an instruction, the base register might be
    corrupted so that the instruction cannot be repeated.
•   For execution at EL0 or EL1, when EL2 is implemented and enabled for the
    current Security state and HCR_EL2.TIDCP is 1, the instruction is trapped
    to EL2 with EC value 0x0.

------ Note ------------
Pre-indexed addressing and post-indexed addressing imply writeback.
------------------------