1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015 Intel Corporation.
3  * Copyright(c) Cavium, Inc. 2017.
4  * All rights reserved
5  * Copyright (C) 2012, Hasan Alayli <[email protected]>
6  * Portions derived from: https://github.com/halayli/lthread
7  * With permissions from Hasan Alayli to use them as BSD-3-Clause
8  */
9 
10 #ifndef STACK_H
11 #define STACK_H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #include "lthread_int.h"
18 
19 /*
20  * Sets up the initial stack for the lthread.
21  */
22 static inline void
23 arch_set_stack(struct lthread *lt, void *func)
24 {
25 	char *stack_top = (char *)(lt->stack) + lt->stack_size;
26 	void **s = (void **)stack_top;
27 
28 	/* set initial context */
29 	s[-3] = NULL;
30 	s[-2] = (void *)lt;
31 	lt->ctx.rsp = (void *)(stack_top - (4 * sizeof(void *)));
32 	lt->ctx.rbp = (void *)(stack_top - (3 * sizeof(void *)));
33 	lt->ctx.rip = func;
34 }
35 
36 #ifdef __cplusplus
37 }
38 #endif
39 
40 #endif /* STACK_H_ */
41