1 /*
2  * ARM AArch64 thread support for bsd-user.
3  *
4  * Copyright (c) 2015 Stacey D. Son <sson at FreeBSD>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TARGET_ARCH_THREAD_H
21 #define TARGET_ARCH_THREAD_H
22 
23 /* Compare to arm64/arm64/vm_machdep.c cpu_set_upcall_kse() */
24 static inline void target_thread_set_upcall(CPUARMState *regs, abi_ulong entry,
25     abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
26 {
27     abi_ulong sp;
28 
29     /*
30      * Make sure the stack is properly aligned.
31      * arm64/include/param.h (STACKLIGN() macro)
32      */
33     sp = ROUND_DOWN(stack_base + stack_size, 16);
34 
35     /* sp = stack base */
36     regs->xregs[31] = sp;
37     /* pc = start function entry */
38     regs->pc = entry;
39     /* r0 = arg */
40     regs->xregs[0] = arg;
41 
42 
43 }
44 
45 static inline void target_thread_init(struct target_pt_regs *regs,
46         struct image_info *infop)
47 {
48     abi_long stack = infop->start_stack;
49 
50     /*
51      * Make sure the stack is properly aligned.
52      * arm64/include/param.h (STACKLIGN() macro)
53      */
54 
55     memset(regs, 0, sizeof(*regs));
56     regs->regs[0] = infop->start_stack;
57     regs->pc = infop->entry;
58     regs->sp = ROUND_DOWN(stack, 16);
59 }
60 
61 #endif /* TARGET_ARCH_THREAD_H */
62