1 /*
2 * File : stack.c
3 * This file is part of RT-Thread RTOS
4 * COPYRIGHT (C) 2006 - 2013, 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 * 2013-7-14 Peng Fan sep6200 implementation
23 */
24
25 #include <rtthread.h>
26 #include <sep6200.h>
27
28 /**
29 * @addtogroup sep6200
30 */
31 /*@{*/
32
33 /**
34 * This function will initialize thread stack
35 *
36 * @param tentry the entry of thread
37 * @param parameter the parameter of entry
38 * @param stack_addr the beginning stack address
39 * @param texit the function will be called when thread exit
40 *
41 * @return stack address
42 */
43
rt_hw_stack_init(void * tentry,void * parameter,rt_uint8_t * stack_addr,void * texit)44 rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
45 rt_uint8_t *stack_addr, void *texit)
46 {
47 rt_uint32_t *stk;
48
49 stk = (rt_uint32_t*)stack_addr;
50 *(stk) = (rt_uint32_t)tentry; /* entry point */
51 *(--stk) = (rt_uint32_t)texit; /* lr */
52 *(--stk) = 0; /* r28 */
53 *(--stk) = 0; /* r27 */
54 *(--stk) = 0; /* r26 */
55 *(--stk) = 0; /* r25 */
56 *(--stk) = 0; /* r24 */
57 *(--stk) = 0; /* r23 */
58 *(--stk) = 0; /* r22 */
59 *(--stk) = 0; /* r21 */
60 *(--stk) = 0; /* r20 */
61 *(--stk) = 0; /* r19 */
62 *(--stk) = 0; /* r18 */
63 *(--stk) = 0; /* r17 */
64 *(--stk) = 0; /* r16 */
65 *(--stk) = 0; /* r15 */
66 *(--stk) = 0; /* r14 */
67 *(--stk) = 0; /* r13 */
68 *(--stk) = 0; /* r12 */
69 *(--stk) = 0; /* r11 */
70 *(--stk) = 0; /* r10 */
71 *(--stk) = 0; /* r9 */
72 *(--stk) = 0; /* r8 */
73 *(--stk) = 0; /* r7 */
74 *(--stk) = 0; /* r6 */
75 *(--stk) = 0; /* r5 */
76 *(--stk) = 0; /* r4 */
77 *(--stk) = 0; /* r3 */
78 *(--stk) = 0; /* r2 */
79 *(--stk) = 0; /* r1 */
80 *(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
81 *(--stk) = Mode_PRIV; /* asr */
82 *(--stk) = Mode_PRIV; /* bsr */ /*why both PRIV do not need switch?*/
83
84 /* return task's current stack address */
85 return (rt_uint8_t *)stk;
86 }
87
88 /*@}*/
89