Commit 27af123
committed
Fix Cortex-R5 context save r4 clobber in non-nested IRQ path
SVC/SYS mode-switching code (introduced in b0c54c6) used r4 as scratch
to determine the interrupted thread's processor mode. r4 is callee-saved
but not part of the minimal interrupt frame (r0-r3, r10, r12, PC, CPSR),
so it was silently corrupted when the thread resumed via the no-preempt
restore path. The preemption path also propagated the corrupted r4 into
the full context frame.
This caused intermittent (~5%) failures on ZynqMP: "FIFO order broken"
(queue corruption) and "counter mismatch" (mutex protection broken),
depending on whether the compiler had a live value in r4 at interrupt
point.
Replace r4 with r0 at all three clobber sites:
1. Mode-bit extraction (AND/CMP for SVC vs SYS check)
2. CPSR switch (MOV/MSR for SYS_MODE and SVC_MODE)
3. IRQ mode re-entry (MOV/MSR for IRQ_MODE after saving context)
r0 is safe because it is overwritten by LDMIA r2,{r0-r3} (recovering
thread registers from the IRQ stack) before being saved to the minimal
frame, and at the IRQ re-entry point r0 has had its last use as the
thread pointer for STR sp,[r0,eclipse-threadx#8].1 parent de4a8af commit 27af123
1 file changed
Lines changed: 9 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
163 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
168 | | - | |
169 | | - | |
| 169 | + | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
174 | | - | |
175 | | - | |
| 175 | + | |
| 176 | + | |
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| |||
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | | - | |
199 | | - | |
| 199 | + | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
| |||
0 commit comments