I have encountered this error while working with QEMU, specifically a Hardfault error when emulating the MPS2AN505 with a Cortex-M33 core. The error I am facing is as follows: qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1) This occurs when I attempt to run my kernel.elf file using the following command :
qemu-system-arm -machine mps2-an505 -cpu cortex-m33 \
                -m 16M \
                -nographic -serial mon:stdio \
                -device loader,file=kernel.elf
I have been grappling with this issue for some time and am unsure of the next steps to take. I am particularly curious if the issue lies with the vector table placement or the configuration in my linker script.
For your reference, here are the relevant details of my setup:
Startup File (Boot.s):
.thumb
.section .isr_vector
    .long    __StackTop         /* Initial Top of Stack */
    .long    Reset_Handler      /* Reset Handler */
.text
.global Reset_Handler
Reset_Handler:  
    ldr     R0, = main
    bx      R0`
Linker Script (Kernel.ld):
MEMORY
{
   NS_CODE (rx)     : ORIGIN = 0x00000000, LENGTH = 512K
   S_CODE_BOOT (rx) : ORIGIN = 0x10000000, LENGTH = 512k
   RAM   (rwx) : ORIGIN = 0x20000000, LENGTH = 512k
}
/* Entry Point */
ENTRY(Reset_Handler)
SECTIONS
{
    .text : 
    {
        KEEP(*(.isr_vector))
        *(.text)
        *(.data)
        *(.bss) 
    } > S_CODE_BOOT
    /* Set stack top to end of S_CODE_BOOT. */
    __StackTop = ORIGIN(S_CODE_BOOT) + LENGTH(S_CODE_BOOT);
}
Toolchain Used: arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi
Compilation Commands for generating the elf:
arm-none-eabi-gcc -mcpu=cortex-m33 -g -c boot.s -o boot.o
arm-none-eabi-ld boot.o main.o -T kernel.ld -o kernel.elf
arm-none-eabi-objdump -d kernel.elf > kernel.list
arm-none-eabi-objdump -t kernel.elf | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > kernel.sym
arm-none-eabi-readelf -A kernel.elf
Main Function (main.c):
void main(void)
{
    while (1);
}
Output of readelf -wl Command:
Elf file type is EXEC (Executable file)
Entry point 0x10000008
There is 1 program header, starting at offset 52
Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x10000000 0x10000000 0x00016 0x00016 R E 0x1000
 Section to Segment mapping:
  Segment Sections...
   00     .text
Guest Errors Observed:
Invalid read at addr 0x10000000, size 4, region '(null)', reason: rejected
Invalid read at addr 0x10000004, size 4, region '(null)', reason: rejected