我正在使用qemu-arm和ARM Workbench IDE来运行/分析一个ARM二进制文件,它是用armcc/armlink (一个.axf文件,用C编写的程序)构建的。这适用于Cortex-A9和ARM926/ARM5TE。然而,无论我怎么尝试,当二进制文件是为Cortex-M4构建的时候,它都不能工作。当选择M4作为CPU时,模拟器和qemu-arm都挂起。
我知道这个处理器需要一些额外的启动代码,但我可以找到任何关于如何让它运行的综合教程。有人知道怎么做吗?我有一个很大的项目,只有一个main函数,但如果运行一个"hello world“或一些简单的带有参数的程序,它已经很有帮助了。
下面是我在Cortex-A9中使用的命令行:
qemu-system-arm -machine versatileab -cpu cortex-a9 -nographic -monitor null -semihosting -append 'some program arguments' -kernel program.axf发布于 2021-05-19 03:07:08
我不知道如何使用多功能节能器,它不是“只是工作”,但它确实工作了:
flash.s
.thumb
.thumb_func
.global _start
_start:
stacktop: .word 0x20001000
.word reset
.word hang
.thumb_func
reset:
bl notmain
b hang
.thumb_func
hang: b .
.thumb_func
.globl PUT32
PUT32:
str r1,[r0]
bx lrnotmain.c
void PUT32 ( unsigned int, unsigned int );
#define UART0BASE 0x4000C000
int notmain ( void )
{
unsigned int rx;
for(rx=0;rx<8;rx++)
{
PUT32(UART0BASE+0x00,0x30+(rx&7));
}
return(0);
}flash.ld
ENTRY(_start)
MEMORY
{
rom : ORIGIN = 0x00000000, LENGTH = 0x1000
ram : ORIGIN = 0x20000000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > rom
.rodata : { *(.rodata*) } > rom
.bss : { *(.bss*) } > ram
}(有人告诉我,作为thumb函数地址的入口点是关键的YMMV)
arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m3 flash.s -o flash.o
arm-none-eabi-gcc -Wall -O2 -ffreestanding -mcpu=cortex-m3 -mthumb -c notmain.c -o notmain.o
arm-none-eabi-ld -nostdlib -nostartfiles -T flash.ld flash.o notmain.o -o notmain.elf
arm-none-eabi-objdump -D notmain.elf > notmain.list
arm-none-eabi-objcopy -O binary notmain.elf notmain.bin检查向量表,等等。
00000000 <_start>:
0: 20001000
4: 0000000d
8: 00000013
0000000c <reset>:
c: f000 f804 bl 18 <notmain>
10: e7ff b.n 12 <hang>
00000012 <hang>:
12: e7fe b.n 12 <hang>看起来不错。
并运行它
qemu-system-arm -M lm3s811evb -m 8K -nographic -kernel notmain.bin
01234567然后按ctrl-a,然后按x退出
QEMU: Terminated-cpu cortex-m4的工作效果和人们预期的一样好。我必须尝试找到m3和m4之间的不同之处,这些东西可能会出现在这样的SIM卡中,然后从那里开始。
在Luminary Micro (不久前被ti收购)之后,我不认为其他人会为一台机器付出努力。但正如在本站点上至少有一个问题中所讨论的,您可以运行核心(读者的练习)。
对于versatilepb
int notmain ( void )
{
unsigned int ra;
for(ra=0;;ra++)
{
ra&=7;
PUT32(0x101f1000,0x30+ra);
}
return(0);
}
qemu-system-arm -machine versatileab -cpu cortex-m4 -nographic -monitor null -kernel notmain.elf
qemu-system-arm: This board cannot be used with Cortex-M CPUs发布于 2021-05-19 20:02:06
您不能任意将不同类型的CPU插入ARM板型号。如果你尝试它,那么最终的系统可能会幸运地工作,或者可能崩溃,或者有奇怪的行为;在某些情况下,-cpu选项将被忽略。这是因为CPU与主板的集成很重要:中断控制器之类的东西是主板的一部分,而不是CPU,但并不是所有的CPU都能与所有的中断控制器一起工作。通常,QEMU在检测和报告无效用户选项的错误方面做得不够好。
在这种情况下,您可能正在使用较旧的QEMU:较新的QEMU将正确地报告:
qemu-system-arm: This board cannot be used with Cortex-M CPUs如果您尝试使用'-machine versatilepb‘和'-cpu cortex m4’。较老的系统要么会崩溃,要么就是行为不端。
通常最好的做法是使用主板默认具有的CPU类型(即不指定-cpu选项),对于除"virt“板之外的每种主板类型。如果您想要为Cortex-M4编写代码,您应该查找具有Cortex-M4的线路板类型。mps2-an386可能是一个很好的选择。(如果您的QEMU没有这种电路板类型,请升级到较新的电路板类型:有许多M-profile仿真错误修复,无论如何都是您想要的。)
https://stackoverflow.com/questions/67591930
复制相似问题