[英]Modifying Comipler RT Assembly code to compile for Arm Cortex M3/M4 (CPSR/APSR bit manipulation)
我正在嘗試從 Compiler RT 中獲取數學例程,該程序使用 GCC 工具鏈用於 ARM Cortex M3/M4F 處理器(帶有 fpu 的 armv7m 和 armv7em)。
除了以下函數中的兩行代碼( msr CPSR_f, ip
和msr 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)
還有另一個功能:
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)
CPSR_f 表示法在 armv7m 指令集上不可用。 如何將msr CPSR_f, ip
和msr CPSR_f, #APSR_C
為 armv7m 代碼(armv7em 應該相同)?
instruction.您需要使用MOV APSR,
指令。 Cortex-M 處理器基本上沒有 CPSR,就條件代碼而言, APSR寄存器充當其替代品。
第一個函數很容易修復,因為它使用寄存器作為源操作數。 只需將msr CPSR_f, ip
替換為msr APSR_nzcvq, ip
。 第二個功能需要通過一個寄存器。 假設 IP 寄存器可以像在您可以使用的第一個函數中一樣被破壞:
mov ip, #APSR_C
msr APSR_nzcvq, ip
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.