为什么 CPSR 寄存器在 ARM ABI 中的函数调用期间不保存?

Why CPSR register is not saved during function call in ARM ABI?

假设我通过像SUBS R0, R0, #1这样的指令改变调用函数中的CPSR寄存器,其中R0正好等于1,然后使用beq cpsr_test调用一个函数。在被调用函数中,CPSRZ 标志仍然设置,对吗?然后被调用函数的行为受调用者的影响,那么为什么所有程序在函数调用期间(甚至上下文切换)都不保存CPSR

caller/callee 示例:

caller  mov     r0, #1
        subs    r0, r0, #1 // Z flag set 
        b       callee

callee  mov     r2, #3
        // something here that have not update cpsr
        beq     label_1    // caller's Z flag is set
        b       label_2

label_1
label_2

内核space上下文切换示例(也不保存cpsr):

/* arm_context_switch(addr_t *old_sp, addr_t new_sp) */
FUNCTION(arm_context_switch)
/* save non callee trashed supervisor registers */
/* spsr and user mode registers are saved and restored in the iframe by exceptions.S */
push    { r4-r11, lr }

/* save old sp */
str     sp, [r0]

/* load new regs */
mov     sp, r1
pop     { r4-r11, lr }
bx      lr

看到这个post:how to understand the function of “__swtich_ to” for contex-switch in the ARM linux,我知道R0-R3因为争用不用保存,但是还是搞不定不保存的意思CPSR。请帮忙。

ARM 上的程序 运行 通常遵循 ARM calling convention

parameters are passed by placing the parameter values into registers R0 through R3 before calling the subroutine, and a subroutine returns a value by placing it into R0 before returning. [...] we'd place any additional parameters onto the stack before entering the subroutine (with the earlier parameters pushed last onto the stack, so that the fifth parameter is on the stack's top (referenced by SP).

Each subroutine is allowed to alter R0 through R3 as it wishes; but if it uses R4 through R12, it must restore them to their previous values. It must also restore the stack pointer R13, effectively removing everything from the stack. It may change the link pointer R14.

请注意,未提及标志寄存器:CPSR。
即使像 The ARM-THUMB Procedure Call Standard 这样更正式的文件也没有。
这意味着标志不会在函数调用之间保存。

进行上下文切换时,保存 CPSR as can be seen in the ARM documentation