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