RTEMS | noelv/qemu: Misaligned BSP reset code can make QEMU run after application exit (#5366)
Matteo Concas (@matteo.concas)
gitlab at rtems.org
Thu Oct 2 14:39:59 UTC 2025
Matteo Concas created an issue: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5366
## Summary
NOEL-V binaries on QEMU might have misaligned `bsp_reset` code causing it to run forever:
```
[ RTEMS shutdown ]
CPU: 0
RTEMS version: 6.1.0.not-released
RTEMS tools: 13.3.0 20240521 (RTEMS 6, RSB no-repo, Newlib 1b3dcfd)
executing thread ID: 0x0a010001
executing thread name: UI1
*** FATAL ***
fatal source: 9 (RTEMS_FATAL_SOURCE_EXCEPTION)
CPU: 0
mstatus 0x8000000a00007800
mcause 0x0000000000000003
mepc 0x0000000000026000
ra 0x0000000000024bc8
sp 0x00000000000f1ab0
gp 0x000000000007e018
tp 0x00000000000f1c98
t0 0x0000000000000057
t1 0x0000000000000000
t2 0x0000000000000078
s0 0x0000000000000005
s1 0x0000000000000000
a0 0x0000000000000020
a1 0x00000000000f1ab0
a2 0x0000000000000038
a3 0x0000000000000000
a4 0x0000000000024f38
a5 0x00000000000f1ab0
a6 0x0000000000000018
a7 0xfffffffffffffffc
s2 0x00000000000dc628
s3 0x0000000000037ae0
s4 0x0000000000037ae0
s5 0x0000000000000000
s6 0x0000000000000000
s7 0x0000000000000000
s8 0x0000000000000120
s9 0x00000000000379c0
s10 0x0000000000000000
s11 0x0000000000000000
t3 0x0000000000000000
t4 0x0000000000000000
t5 0x0000000000000000
t6 0x0000000000000000
fcsr 0x00000000
RTEMS version: 6.1.0.not-released
RTEMS tools: 13.3.0 20240521 (RTEMS 6, RSB no-repo, Newlib 1b3dcfd)
executing thread ID: 0x0a010001
executing thread name: UI1
*** FATAL ***
fatal source: 9 (RTEMS_FATAL_SOURCE_EXCEPTION)
CPU: 0
mstatus 0x8000000a00007800
mcause 0x0000000000000003
mepc 0x0000000000026000
ra 0x0000000000024bc8
sp 0x00000000000f1860
gp 0x000000000007e018
tp 0x00000000000f1c98
t0 0x0000000000000057
t1 0x0000000000000000
t2 0x0000000000000078
s0 0x0000000000000009
s1 0x00000000000f1960
a0 0x0000000000000020
a1 0x00000000000f1860
a2 0x0000000000000038
a3 0x0000000000000000
a4 0x0000000000024f38
a5 0x00000000000f1860
a6 0x0000000000000018
a7 0xfffffffffffffffc
s2 0x00000000000dc628
s3 0x0000000000037ae0
s4 0x0000000000037ae0
s5 0x0000000000000000
s6 0x0000000000000000
s7 0x0000000000000000
s8 0x0000000000000120
s9 0x00000000000379c0
s10 0x0000000000000000
s11 0x0000000000000000
t3 0x0000000000000000
t4 0x0000000000000000
t5 0x0000000000000000
t6 0x0000000000000000
fcsr 0x00000000
RTEMS version: 6.1.0.not-released
RTEMS tools: 13.3.0 20240521 (RTEMS 6, RSB no-repo, Newlib 1b3dcfd)
executing thread ID: 0x0a010001
executing thread name: UI1
```
This keeps going forever.
This does not affect hardware.
## Steps to reproduce
Hard to reproduce as it seems most of the time the code will be correctly aligned.
## Solution
A fix is to align the instruction in `bsps/riscv/noel/start/bsp_fatal_halt.c:bsp_reset()` :
```c
void bsp_reset(rtems_fatal_source source, rtems_fatal_code code)
{
(void)source;
uint64_t args[2] = {ADP_Stopped_ApplicationExit, code};
__asm__ volatile("li a0, %0" ::"i"(TARGET_SYS_EXIT_EXTENDED));
__asm__ volatile("mv a1, %0" ::"r"(&args));
__asm__ volatile(".align 4; slli zero, zero, 0x1f");
__asm__ volatile("ebreak");
__asm__ volatile("srai zero, zero, 0x7");
RTEMS_UNREACHABLE();
}
```
### Pre-set options
--
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5366
You're receiving this email because of your account on gitlab.rtems.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20251002/025900e9/attachment-0001.htm>
More information about the bugs
mailing list