1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
12 #include "lthread_int.h"
15 * Sets up the initial stack for the lthread.
18 arch_set_stack(struct lthread *lt, void *func)
20 void **stack_top = (void *)((char *)(lt->stack) + lt->stack_size);
23 * Align stack_top to 16 bytes. Arm64 has the constraint that the
24 * stack pointer must always be quad-word aligned.
26 stack_top = (void **)(((unsigned long)(stack_top)) & ~0xfUL);
35 * Initialize the context
37 lt->ctx.fp = &stack_top[-1];
38 lt->ctx.sp = &stack_top[-2];
41 * Here only the address of _lthread_exec is saved as the link
42 * register value. The argument to _lthread_exec i.e the address of
43 * the lthread struct is not saved. This is because the first
44 * argument to ctx_switch is the address of the new context,
45 * which also happens to be the address of required lthread struct.
46 * So while returning from ctx_switch into _thread_exec, parameter
47 * register x0 will always contain the required value.