I have a program consisting of multiple C source files and I would like to execute it in qemu with a Cortex-M4/M7 CPU. I am using the following command to build the objects:
"arm-none-eabi-gcc" -c -mcpu=cortex-m4 -mthumb -fomit-frame-pointer -Wimplicit-fallthrough -O3 -Wall -Wshadow -Wcast-qual -Wno-long-long -Wno-unknown-pragmas
The linker creates a library:
arm-none-eabi-ar cru lib *.o
And the main is then linked to an executable:
"arm-none-eabi-gcc" -mthumb -specs=rdimon.specs main.o lib.a -lstdc++ -lm -L./lib/arm_none-eabi_gcc/ -o run_main
Now running this binary gives me:
qemu-arm -cpu cortex-m4 run_main
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction
It all works well when using Cortex-A9 as CPU, but the M-Models are troubling me. What am I doing wrong?