目標
根據 ARM 的Barrier Litmus Tests and Cookbook檔案,我正在使用 LDREX 和 STREX 指令為 CortexM7 目標使用 gcc 行內匯編構建互斥原語。
代碼
static inline void testAcquireLock(unsigned int *lock) {
unsigned int tempStore1 = 0;
unsigned int tempStore2 = 0;
__asm__ volatile(
"Loop%=: \n\t" // "%=" generates unique #
"LDREX %[ts1], %[lock] \n\t" // exclusive read lock
"CMP %[ts1], #0 \n\t" // check if 0
"ITT EQ \n\t" // block for below conds.
"STREXEQ %[ts1], %[ts2], %[lock] \n\t" // attempt to ex. store new value
"CMPEQ %[ts1], #0 \n\t" // test if store suceeded
"BNE Loop%= \n\t" // retry if not
"DMB \n\t" // mem barrier for subsequent reads
: [lock] " l"(*lock), [ts1] "=l"(tempStore1), [ts2] "=l"(tempStore2)
: // inputs
: "memory");
}
錯誤資訊
顯示的唯一錯誤如下。匯編程式參考 R15,生成的程式集中似乎沒有使用它?錯誤訊息中的第 191 行對應于LDREX上面看到的第一條指令。
[build] /tmp/ccEU4dXd.s: Assembler messages:
[build] /tmp/ccEU4dXd.s:191: Error: r15 not allowed here -- `ldrex r1,r3'
[build] /tmp/ccEU4dXd.s:194: Error: r15 not allowed here -- `strexeq r1,r2,r3'
構建/編譯器選項
該專案使用以下編譯器設定配置了 CMake:
target_compile_options(testing
PRIVATE
-mcpu=cortex-m7
-mfpu=fpv5-d16
-mfloat-abi=hard
-mthumb
-Wall
-fdata-sections
-ffunction-sections
)
編譯導致錯誤的命令:
[build] /usr/bin/arm-none-eabi-gcc -DSTM32F777xx -DUSE_HAL_DRIVER -I<removed> -g -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -Wall -fdata-sections -ffunction-sections -std=gnu11 -o <removed>.c.obj -c <removed>.c
研究/我嘗試過的
After reading I realize there's two (instruction sets? syntax parsers?) for armv7, and the processor can be in one of two modes for these (ARM and THUMB). But I don't fully understand this, and how it affects the parsing of handwritten assembly.
I suspected, because the processor is in thumb mode (-mthumb), it has something to do with my inline alias constraints? Per documentation I tried switching between " l", " r", " h" but it doesn't seem to change anything.
I tried using hardcoded registers "r3, r4, r5" instead of the inline aliases but that gave the same error.
uj5u.com熱心網友回復:
根據@jester 的幫助,我意識到我對鎖的 GCC 行內變數別名有錯誤的約束。它應該是“ m”,指定一個記憶體地址而不是一個暫存器。
當我應該將它作為指標保留時,我也在取消參考鎖的地址。
我更改[lock] " l"(*lock)為[lock] " m"(lock),它現在可以構建。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/424426.html
