简体   繁体   English

修改 Compiler RT 汇编代码以编译 Arm Cortex M3/M4(CPSR/APSR 位操作)

[英]Modifying Comipler RT Assembly code to compile for Arm Cortex M3/M4 (CPSR/APSR bit manipulation)

I am trying to get the math routines from Compiler RT working with a GCC toolchain for the ARM Cortex M3/M4F processors (armv7m and armv7em with fpu).我正在尝试从 Compiler RT 中获取数学例程,该程序使用 GCC 工具链用于 ARM Cortex M3/M4F 处理器(带有 fpu 的 armv7m 和 armv7em)。

I have everything compiling (with minimal changes) except two lines of code ( msr CPSR_f, ip and msr CPSR_f, #APSR_C ) in the functions below除了以下函数中的两行代码( msr CPSR_f, ipmsr CPSR_f, #APSR_C )之外,我已经编译了所有内容(更改很少)

#define APSR_Z (1 << 30)
#define APSR_C (1 << 29)

DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmple)
    // Per the RTABI, this function must preserve r0-r11.
    // Save lr in the same instruction for compactness
    push {r0-r3, lr}

    bl __aeabi_fcmplt
    cmp r0, #1
    IT(eq)
    moveq ip, #0
    beq 1f

    ldm sp, {r0-r3}
    bl __aeabi_fcmpeq
    cmp r0, #1
    IT(eq)
    moveq ip, #(APSR_C | APSR_Z)
    IT(ne)
    movne ip, #(APSR_C)

1:
    msr CPSR_f, ip
    pop {r0-r3}
    POP_PC()
END_COMPILERRT_FUNCTION(__aeabi_cfcmple)

And the other function:还有另一个功能:

DEFINE_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)
    push {r0-r3, lr}
    bl __aeabi_cfcmpeq_check_nan
    cmp r0, #1
    pop {r0-r3, lr}

    // NaN has been ruled out, so __aeabi_cfcmple can't trap
    bne __aeabi_cfcmple

    msr CPSR_f, #APSR_C
    JMP(lr)
END_COMPILERRT_FUNCTION(__aeabi_cfcmpeq)

The CPSR_f notation is not available on the armv7m instruction set. CPSR_f 表示法在 armv7m 指令集上不可用。 How do I convert msr CPSR_f, ip and msr CPSR_f, #APSR_C to armv7m code (should be the same for armv7em)?如何将msr CPSR_f, ipmsr CPSR_f, #APSR_C为 armv7m 代码(armv7em 应该相同)?

You need to use the MOV APSR, Rm instruction.您需要使用MOV APSR, Rm指令。 The Cortex-M processors basically don't have a CPSR, and the APSR register acts as its replacement as far as the condition codes go. Cortex-M 处理器基本上没有 CPSR,就条件代码而言, APSR寄存器充当其替代品。

The first function is easy to fix, since it uses a register as the source operand.第一个函数很容易修复,因为它使用寄存器作为源操作数。 Just replace msr CPSR_f, ip with msr APSR_nzcvq, ip .只需将msr CPSR_f, ip替换为msr APSR_nzcvq, ip The second function would require going through a register.第二个功能需要通过一个寄存器。 Assuming the IP register can be clobbered just like it is in the first function you can use:假设 IP 寄存器可以像在您可以使用的第一个函数中一样被破坏:

mov ip, #APSR_C
msr APSR_nzcvq, ip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM