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