Skip to content

Commit fa602a6

Browse files
committed
[libcpu][arm] fix: correct FPU stack initialization order and alignment on Cortex-A
1 parent 934c819 commit fa602a6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

libcpu/arm/cortex-a/stack.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
3131
rt_uint8_t *stack_addr, void *texit)
3232
{
3333
rt_uint32_t *stk;
34+
rt_uint32_t i = 0;
3435

3536
stack_addr += sizeof(rt_uint32_t);
3637
stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
@@ -61,7 +62,25 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
6162
*(--stk) = 0; /* user sp*/
6263
#endif
6364
#ifdef RT_USING_FPU
64-
*(--stk) = 0; /* not use fpu*/
65+
/* 1. D0-D15 */
66+
for (i = 0; i <= 15; i++)
67+
{
68+
*(--stk) = 0x00000000;
69+
*(--stk) = 0x00000000;
70+
}
71+
72+
/* 2. D16-D31 */
73+
for (i = 16; i <= 31; i++)
74+
{
75+
*(--stk) = 0x00000000;
76+
*(--stk) = 0x00000000;
77+
}
78+
79+
/* 3. FPSCR */
80+
*(--stk) = 0x00000000;
81+
82+
/* 4. FPEXC: EN=1 */
83+
*(--stk) = 0x40000000;
6584
#endif
6685

6786
/* return task's current stack address */

0 commit comments

Comments
 (0)