Qemu: fatal: Lockup: cant escalate 3 to Hardfault (Current Priority -1) 错误-Core Dumped

Qemu: fatal: Lockup: cant escalate 3 to Hardfault (Current Priority -1) error -Core Dumped

我正在尝试在 QEMU 上使用 cortex M4 处理器模拟 STM32F407XX 控制器。我写的 .ld 文件如下:

ENTRY(_Reset)

MEMORY
{
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 512K
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
  CCMRAM (rw)     : ORIGIN = 0x10000000, LENGTH = 64K
  PERIPHERALS(rw) : ORIGIN = 0x40000000, LENGTH = 128K
}

SECTIONS
{

 .startup . : { stm32.o(.text) } >FLASH
 .text : { *(.text) } 
 .data : { *(.data) } >RAM AT> FLASH
 .bss : { *(.bss COMMON) } >RAM
 . = ALIGN(4);
 . = . + 0x400; /* required amount of stack */
 stack_top = 0x20020000;
}

当我生成 .elf 文件和 运行 代码时,出现错误

Qemu: fatal: Lockup: cant escalate 3 to Hardfault (Current Priority -1) error.
Aborted (Core Dumped)

感觉是内存问题。我究竟做错了什么? 我已经按照STM32F407的参考手册要求分配了flash、RAM内存。

为什么首先会出现此错误?我该如何解决此错误? 谢谢。

您需要在您的机器加载内核后(armv7m_load_kernel 调用后)重置您的 ROM。您可以使用例如:

rom_check_and_register_reset();
qemu_devices_reset();

CPU 应该在重置处理程序上启动。

将向量 table 放在正确的位置解决了这个问题。我在上面的评论中遵循了@peter Maydell 的所有说明。我在这里添加它们。

You can turn on some of the debug logging options of QEMU with -d ('in_asm,int,exec,cpu,guest_errors,unimp' are probably a good set to start with), which will tell you what your guest code is doing. I would start by checking that your ELF file has a vector table in it at the place where QEMU expects to find it. Otherwise QEMU will hard fault immediately out of reset (which is what the hardware does).

The core dump is expected: QEMU goes into lockup, but we don't emulate lockup correctly (strictly speaking QEMU should just sit there doing nothing like the real hardware does), so we print a register dump and abort(). As I said in my previous comment, your problem is almost certainly that your binary doesn't have a vector table.

The main thing you must have in your vector table is the entries for the initial PC and stack pointer. The interrupt and exception entries are worth putting in but will only be needed if there is an interrupt or exception. If you put in debugging handlers for the other faults you'll at least know when you get a fault due to a bug in the rest of your program, though

为像我这样在尝试修复 qemu 硬故障时遇到的任何人提供的附加信息: 由于未实现的指令,我遇到了同样的硬故障。

发生这种情况是因为我使用 -mcpu=cortex-m4 编译了代码,但是 运行 qemu 使用了 -cpu cortex-m3

关于此的棘手之处在于它适用于大多数代码,因为 gcc 通常不使用 "m4-only-instructions" 之一(即使取决于优化级别 - 它适用于 -O1 但失败 -O2)...