1 /*
2 * File : stack.c
3 * This file is part of RT-Thread RTOS
4 * COPYRIGHT (C) 2006-2011, RT-Thread Development Team
5 *
6 * The license and distribution terms for this file may be
7 * found in the file LICENSE in this distribution or at
8 * http://www.rt-thread.org/license/LICENSE
9 *
10 * Change Logs:
11 * Date Author Notes
12 * 2011-02-14 aozima first implementation for Nios II.
13 */
14
15 #include <rtthread.h>
16
17 /**
18 * @addtogroup NIOS_II
19 */
20 /*@{*/
21
22 /**
23 * This function will initialize thread stack
24 *
25 * @param tentry the entry of thread
26 * @param parameter the parameter of entry
27 * @param stack_addr the beginning stack address
28 * @param texit the function will be called when thread exit
29 *
30 * @return stack address
31 */
rt_hw_stack_init(void * tentry,void * parameter,rt_uint8_t * stack_addr,void * texit)32 rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
33 rt_uint8_t *stack_addr, void *texit)
34 {
35 unsigned long *stk;
36
37 stk = (unsigned long *)stack_addr;
38 *(stk) = 0x01; /* status */
39 *(--stk) = (unsigned long)texit; /* ra */
40 *(--stk) = 0xdeadbeef; /* fp */
41 *(--stk) = 0xdeadbeef; /* r23 */
42 *(--stk) = 0xdeadbeef; /* r22 */
43 *(--stk) = 0xdeadbeef; /* r21 */
44 *(--stk) = 0xdeadbeef; /* r20 */
45 *(--stk) = 0xdeadbeef; /* r19 */
46 *(--stk) = 0xdeadbeef; /* r18 */
47 *(--stk) = 0xdeadbeef; /* r17 */
48 *(--stk) = 0xdeadbeef; /* r16 */
49 // *(--stk) = 0xdeadbeef; /* r15 */
50 // *(--stk) = 0xdeadbeef; /* r14 */
51 // *(--stk) = 0xdeadbeef; /* r13 */
52 // *(--stk) = 0xdeadbeef; /* r12 */
53 // *(--stk) = 0xdeadbeef; /* r11 */
54 // *(--stk) = 0xdeadbeef; /* r10 */
55 // *(--stk) = 0xdeadbeef; /* r9 */
56 // *(--stk) = 0xdeadbeef; /* r8 */
57 *(--stk) = 0xdeadbeef; /* r7 */
58 *(--stk) = 0xdeadbeef; /* r6 */
59 *(--stk) = 0xdeadbeef; /* r5 */
60 *(--stk) = (unsigned long)parameter; /* r4 argument */
61 *(--stk) = 0xdeadbeef; /* r3 */
62 *(--stk) = 0xdeadbeef; /* r2 */
63 *(--stk) = (unsigned long)tentry; /* pc */
64
65 // *(stk) = (unsigned long)tentry; /* thread entry (ra) */
66 // *(--stk) = (unsigned long)parameter; /* thread argument, r4 */
67
68 /* return task's current stack address */
69 return (rt_uint8_t *)stk;
70 }
71
72 /*@}*/
73