xref: /nrf52832-nimble/rt-thread/libcpu/xilinx/microblaze/stack.c (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*
2  * File      : stack.c
3  * This file is part of RT-Thread RTOS
4  * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
9  *
10  * Change Logs:
11  * Date           Author       Notes
12  * 2011-12-17     nl1031       first implementation for MicroBlaze.
13  *
14  */
15 #include <rtthread.h>
16 extern   void  *_SDA_BASE_;
17 extern   void  *_SDA2_BASE_;
18 
19 
20 
21 /**
22  * This function will initialize thread stack
23  *
24  * @param tentry the entry of thread
25  * @param parameter the parameter of entry
26  * @param stack_addr the beginning stack address
27  * @param texit the function will be called when thread exit
28  *
29  * @return stack address
30  */
31 rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
32 	rt_uint8_t *stack_addr, void *texit)
33 {
34 	unsigned long *stk;
35 
36 	stk 	 = (unsigned long *)stack_addr;
37 	stk--;
38 	stk--;
39 	*stk-- = 0;								/* r31 */
40 	*stk-- = 0;								/* r30 */
41 	*stk-- = 0;								/* r29 */
42 	*stk-- = 0;								/* r28 */
43 	*stk-- = 0;								/* r27 */
44 	*stk-- = 0;								/* r26 */
45 	*stk-- = 0;								/* r25 */
46 	*stk-- = 0;								/* r24 */
47 	*stk-- = 0;								/* r23 */
48 	*stk-- = 0;								/* r22 */
49 	*stk-- = 0;								/* r21 */
50 	*stk-- = 0;								/* r20 */
51 	*stk-- = 0;								/* r19 */
52 	*stk-- = 0;								/* r18 */
53 	*stk-- = 0;								/* r17 */
54 	*stk-- = (unsigned long)texit - 8;		/* r15 = task return address*/
55 	*stk-- = (unsigned long)tentry;		/* r14 = entry address*/
56 	*stk-- = (unsigned long)&_SDA_BASE_;	/* r13 */
57 	*stk-- = 0;								/* r12 */
58 	*stk-- = 0;								/* r11 */
59 	*stk-- = 0;								/* r10 */
60 	*stk-- = 0;								/* r09 */
61 	*stk-- = 0;								/* r08 */
62 	*stk-- = 0;								/* r07 */
63 	*stk-- = 0;								/* r06 */
64 	*stk-- = (unsigned long) parameter;	/* r05 */
65 	*stk-- = 0;								/* r04 */
66 	*stk-- = 0;								/* r03 */
67 	*stk-- = (unsigned long)&_SDA2_BASE_;	/* r02 */
68 	*stk   = 2;   							/* enable interrupt */
69 	return (rt_uint8_t *)stk;
70 }
71 
72