Commit 22399e6
committed
Fix Cortex-R5 SVC stack init for VFP alignment
Critical bugs discovered:
1. SVC stack was never initialized, causing potential alignment faults
for VFP double-precision operations (VSTMDB/VLDMIA in SVC mode)
2. Wrong base pointer: loaded _sp (DDR) instead of _stack_top (ATCM)
Result: Stacks placed in external memory, not TCM
3. Wrong initialization order: assembly didn't match linker layout
Result: Stack overlap and memory corruption
4. Conditional bug: When TX_ENABLE_IRQ_NESTING disabled, code skipped
SYS region, placing FIQ/IRQ in wrong memory regions
5. ARM compliance issues: Full CPSR writes, missing ISB barriers
Fixes applied:
Assembly (tx_initialize_low_level.S):
- Changed base from _sp to _stack_top (ATCM)
- Reordered initialization: SVC → SYS → FIQ → IRQ (matches linker)
- Added SVC_STACK_SIZE = 1024 and SVC stack initialization
- Added #else clause to always subtract SYS_STACK_SIZE (maintain layout)
- Changed MSR CPSR to MSR CPSR_c (control field only)
- Added ISB after each mode change (ARMv7-R best practice)
- Removed unnecessary SUB #1 before BIC eclipse-threadx#7
Linker (sample_threadx_tcm.ld):
- Added .stack_svc section (1KB, ALIGN(8), in ATCM)
- Added SVC_STACK_SIZE constant
- Exported _sp_svc symbol
ARM Reference: ARMv7-R Architecture Manual DDI 0406C
- Section A8.8.383: VSTM alignment requirements (8-byte for D0-D15)
- Section B1.3.3: Processor modes and banked SP registers
- Section A3.8.3: ISB instruction synchronization barrier1 parent f5ef2b5 commit 22399e6
2 files changed
Lines changed: 57 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
116 | 130 | | |
117 | 131 | | |
118 | 132 | | |
| 133 | + | |
119 | 134 | | |
120 | 135 | | |
121 | | - | |
| 136 | + | |
122 | 137 | | |
123 | 138 | | |
124 | 139 | | |
| |||
Lines changed: 40 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
125 | 129 | | |
126 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
127 | 141 | | |
128 | | - | |
| 142 | + | |
129 | 143 | | |
130 | 144 | | |
131 | 145 | | |
132 | 146 | | |
133 | 147 | | |
134 | | - | |
135 | | - | |
| 148 | + | |
| 149 | + | |
136 | 150 | | |
137 | 151 | | |
138 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
139 | 159 | | |
140 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
141 | 163 | | |
142 | 164 | | |
143 | | - | |
144 | | - | |
| 165 | + | |
| 166 | + | |
145 | 167 | | |
146 | 168 | | |
147 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
148 | 173 | | |
149 | 174 | | |
150 | | - | |
151 | | - | |
| 175 | + | |
| 176 | + | |
152 | 177 | | |
153 | 178 | | |
154 | | - | |
155 | | - | |
156 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
157 | 183 | | |
158 | 184 | | |
159 | 185 | | |
| |||
0 commit comments