M0+ asm instructions bug

Home Forums Forum M0+ asm instructions bug

This topic contains 2 replies, has 2 voices, and was last updated by  rich 8 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #76500

    Jake

    Instructions which are known to be valid, successfully used in gnu g++ are causing some errors here against a Freescale MKL16Z Cortex-M0+ thumb2

    the code:

    
        /* 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));
    

    the compile command:

    
    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
    

    Tips appreciated! I wonder if I can rewrite the asm into something using simpler instructions… it doesn’t seem to like immediate value encoding? I’m not skilled with assembly.

    #76501

    Jake

    Seems like the instructions supported in Cortex-M0+ are not all included in LLVM. After adjusting some assembly instructions, I got things compiling. Unfortunately, even with optimizations enabled, the binary overflowed the available program memory, with a binary size 6 times larger than the gnu g++ one.

    #76507

    rich
    Keymaster

    How big of a binary are you creating? 6X seems like a lot. How did you measure the size?

    -Rich

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.