1 /*
2 * File : stack_ck802.c
3 * This file is part of RT-Thread RTOS
4 * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Change Logs:
21 * Date Author Notes
22 * 2017-01-01 Urey first version
23 */
24
25 #include <rtthread.h>
26
rt_hw_stack_init(void * tentry,void * parameter,rt_uint8_t * stack_addr,void * texit)27 rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint8_t *stack_addr, void *texit)
28 {
29 rt_uint32_t *stk = (rt_uint32_t *)stack_addr;
30
31 stk = (rt_uint32_t *)(stack_addr + sizeof(rt_uint32_t));
32 stk = (rt_uint32_t *)RT_ALIGN_DOWN((rt_uint32_t)stk, 8);
33
34 *(--stk) = (rt_uint32_t)tentry; /* Entry Point */
35 *(--stk) = (rt_uint32_t)0x80000150L; /* PSR */
36 *(--stk) = (rt_uint32_t)texit; /* R15 (LR) (init value will cause fault if ever used) */
37 *(--stk) = (rt_uint32_t)0x13131313L; /* R13 */
38 *(--stk) = (rt_uint32_t)0x12121212L; /* R12 */
39 *(--stk) = (rt_uint32_t)0x11111111L; /* R11 */
40 *(--stk) = (rt_uint32_t)0x10101010L; /* R10 */
41 *(--stk) = (rt_uint32_t)0x09090909L; /* R9 */
42 *(--stk) = (rt_uint32_t)0x08080808L; /* R8 */
43 *(--stk) = (rt_uint32_t)0x07070707L; /* R7 */
44 *(--stk) = (rt_uint32_t)0x06060606L; /* R6 */
45 *(--stk) = (rt_uint32_t)0x05050505L; /* R5 */
46 *(--stk) = (rt_uint32_t)0x04040404L; /* R4 */
47 *(--stk) = (rt_uint32_t)0x03030303L; /* R3 */
48 *(--stk) = (rt_uint32_t)0x02020202L; /* R2 */
49 *(--stk) = (rt_uint32_t)0x01010101L; /* R1 */
50 *(--stk) = (rt_uint32_t)parameter; /* R0 : argument */
51
52 /* return task's current stack address */
53 return (rt_uint8_t *)stk;
54 }
55
56