AnsweredAssumed Answered

Issue with powerpc-eabivle-gcc.exe, revision 4.9.4: Book E instruction emitted in VLE mode

Question asked by Peter Vranken on Dec 4, 2017
Latest reply on Jan 4, 2018 by Alexander Fedotov

I've encountered an issue with powerpc-eabivle-gcc.exe, revision 4.9.4. The call of the libary function iprintf (not tried if it is the same for printf, etc.) is preceeded by a machine instruction e_crxor 6,6,6, which clears a floating point related fault bit. If the call of iprintf is the very last statement of a function then the stack frame cleanup is combined with the jump to the library function and the emitted machine instructions are accordingly changed. Unfortunately this involves a change of the instruction e_crxor into a Book E instruction crxor 6,6,6. The SW runs into a trap #6, Program interrupt.

The same code runs fine if either compiled with Book E instruction set or with VLE but without optimzation.

Here is the C code. (Note, the commented statement "asm volatile ("se_nop\n");" is a work around. The printf is no longer last statement and the correct e_crxor 6,6,6 is emitted):


 * A non cyclic task, which is activated by software trigger every time the button on the
 * evaluation board is pressed.
static void taskOnButtonDown(void)
    ++ mai_cntTaskOnButtonDown;
    iprintf("You pressed the button the %lu. time\r\n", mai_cntTaskOnButtonDown);

    /* Change the value of artificial CPU load on every click by 10%. */
    if(_cpuLoadInPercent < 100)
        _cpuLoadInPercent += 10;
        _cpuLoadInPercent = 0;
    iprintf("The additional, artificial CPU load has been set to %u%%\r\n", _cpuLoadInPercent);

//  asm volatile ("se_nop\n");

} /* End of taskOnButtonDown */


Here is the assembly listing:


 e_lis %r3,.LC8@ha  # tmp166,
 .loc 2 626 0
 .loc 2 622 0
 e_la %r3,.LC8@l(%r3)  #,, tmp166
 e_lwz %r4,_cpuLoadInPercent@sda21(%r0)  # _cpuLoadInPercent,
 .loc 2 626 0
 se_mtlr %r0  #,
 .cfi_restore 65
 se_addi %r1,8  #,
 .cfi_def_cfa_offset 0
 .loc 2 622 0
 crxor 6,6,6
 e_b iprintf  #


Console output with command line:


Compiling TRK-USB-MPC5643L-RTOS-VLE for production
Compiling C file code/mai_main.c
C:/ProgramFiles/MinGW-powerpc-eabivle-4.9.4/bin/powerpc-eabivle-gcc.exe -c -mcpu=e200z4 -mbig-endian -mvle -mspe -misel=yes -meabi -msdata=default -G8 -mregnames -mhard-float -fshort-double -mno-string -fno-common -fno-exceptions -ffunction-sections -fdata-sections -fshort-enums -fdiagnostics-show-option -finline-functions -fzero-initialized-in-bss -fno-tree-loop-optimize -Wall -Wno-main -Wno-old-style-declaration -Winline -Wextra -Wstrict-overflow=4 -Wmissing-declarations -Wno-parentheses -Wdiv-by-zero -Wcast-align -Wformat -Wformat-security -Wignored-qualifiers -Wsign-conversion -Wsign-compare -Werror=missing-declarations -Werror=implicit-function-declaration -Wno-nested-externs -Werror=int-to-pointer-cast -Werror=pointer-sign -Werror=pointer-to-int-cast -Werror=return-local-addr -MMD -Wa,-a=bin/ppc/PRODUCTION/obj/mai_main.lst -std=gnu11 -Icode/ -Icode/RTOS/ -Icode/serial/ -Icode/startup/ -DPRODUCTION -DNDEBUG  -save-temps=obj -fverbose-asm  -g1 -gdwarf-2 -Os -o bin/ppc/PRODUCTION/obj/mai_main.o code/mai_main.c


Full code context can be found at