xref: /nrf52832-nimble/rt-thread/libcpu/ia32/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  */
13 
14 #include <rtthread.h>
15 
16 #include <i386.h>
17 
18 /**
19  * @addtogroup I386
20  */
21 /*@{*/
22 
23 /**
24  * This function will initialize thread stack
25  *
26  * @param tentry the entry of thread
27  * @param parameter the parameter of entry
28  * @param stack_addr the beginning stack address
29  * @param texit the function will be called when thread exit
30  *
31  * @return stack address
32  */
33 rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
34 	rt_uint8_t *stack_addr, void *texit)
35 {
36 	unsigned long *stk;
37 
38 	stk = (unsigned long *)stack_addr;
39 	*(--stk) = (unsigned long)parameter;
40 	*(--stk) = (unsigned long)texit;
41 	*(--stk) = 0x200;						/*flags*/
42 	*(--stk) = 0x08;						/*cs*/
43 	*(--stk) = (unsigned long)tentry;		/*eip*/
44 	*(--stk) = 0;							/*irqno*/
45 	*(--stk) = 0x10;						/*ds*/
46 	*(--stk) = 0x10;						/*es*/
47 	*(--stk) = 0;							/*eax*/
48 	*(--stk) = 0;							/*ecx*/
49 	*(--stk) = 0;							/*edx*/
50 	*(--stk) = 0;							/*ebx*/
51 	*(--stk) = 0;							/*esp*/
52 	*(--stk) = 0;							/*ebp*/
53 	*(--stk) = 0;							/*esi*/
54 	*(--stk) = 0;							/*edi*/
55 
56 	/* return task's current stack address */
57 	return (rt_uint8_t *)stk;
58 }
59 /*@}*/
60