c - ELLCC 嵌入式 LLVM 编译失败,某些 asm 指令针对 Thumb2 Cortex-M0

标签 c assembly arm embedded ellcc

在 Gnu G++ 中成功使用的已知有效指令在此处针对 Freescale MKL16Z Cortex-M0+ Thumb2 导致了一些错误

代码:

/* setup the stack before we attempt anything else
   skip stack setup if __SP_INIT is 0
   assume sp is already setup. */
__asm (
"mov r0,%0\n\t"
"cmp r0,#0\n\t"
"beq skip_sp\n\t"
"mov sp,r0\n\t"
"sub sp,#4\n\t"
"mov r0,#0\n\t"
"mvn r0,r0\n\t"
"str r0,[sp,#0]\n\t"
"add sp,#4\n\t"
"skip_sp:\n\t"
::"r"(addr));

编译命令:

ecc -target thumb-linux-engeabi -mtune=cortex-m0plus -mcpu=cortex-m0plus -mthumb -O2 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -Wconversion -Wpointer-arith -Wshadow -Wfloat-equal  -g3 -I"[redacted]" -I"[redacted]" -I"[redacted]" -I"[redacted]" -std=c99 -MMD -MP -MF"Project_Settings/Startup_Code/startup.d" -MT"Project_Settings/Startup_Code/startup.o" -c -o "Project_Settings/Startup_Code/startup.o" "../Project_Settings/Startup_Code/startup.c"
../Project_Settings/Startup_Code/startup.c:209:17: error: instruction requires: arm-mode
    "sub sp,#4\n\t"
                ^
<inline asm>:6:2: note: instantiated into assembly here
        mov r0,#0
        ^
../Project_Settings/Startup_Code/startup.c:210:17: error: invalid instruction
    "mov r0,#0\n\t"
                ^
<inline asm>:7:2: note: instantiated into assembly here
        mvn r0,r0
        ^~~
2 errors generated.
make: *** [Project_Settings/Startup_Code/startup.o] Error 1

感谢提示!我想知道我是否可以使用更简单的指令将 asm 重写成某种东西……它似乎不喜欢立即值编码?我不擅长组装。

最佳答案

我认为编译器告诉的是该指令不存在于 Thumb 中,只存在于 ARM 中。

在 Thumb 中,几乎所有数据处理指令都会更新标志。这意味着:

MOV r0, #0

不存在,而是:

MOVS r0, #0 ; Update NZCV flags

关于c - ELLCC 嵌入式 LLVM 编译失败,某些 asm 指令针对 Thumb2 Cortex-M0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35968339/

相关文章:

macos - 如何从 Mac OS X 调试 ARM

c - 餐厅程序重复时会跳过第一个输入

c - 如何在多个显示器上使用 XGetImage?

c++ - 内联函数

c - 使用内存引用的 GCC 内联汇编程序

assembly - 关于多核CPU的x86 LOCK问题

memory-management - Windows CE : Mapping Physical memory in user mode

c - 使用 jpegtran 旋转渐进式 jpeg : invalid SOS parameter for sequential jpeg

c - 将四字移动到 %RDI 的操作码

c - Openocd:将值写入闪存地址