简体   繁体   中英

Emulate ARM Cortex-M4 with qemu

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?

ARM Cortex-M MCUs always require custom linker script and startup code. Flash and RAM addresses are not standardized across vendors, and the interrupt vector table is device specific.

The linker command line should also specify the core via "-mcpu=cortex-m4" in order to link to the correct libraries (multilib).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM