1*9aae5dcdSMark Corbin /*
2*9aae5dcdSMark Corbin * RISC-V thread support
3*9aae5dcdSMark Corbin *
4*9aae5dcdSMark Corbin * Copyright (c) 2019 Mark Corbin
5*9aae5dcdSMark Corbin *
6*9aae5dcdSMark Corbin * This program is free software; you can redistribute it and/or modify
7*9aae5dcdSMark Corbin * it under the terms of the GNU General Public License as published by
8*9aae5dcdSMark Corbin * the Free Software Foundation; either version 2 of the License, or
9*9aae5dcdSMark Corbin * (at your option) any later version.
10*9aae5dcdSMark Corbin *
11*9aae5dcdSMark Corbin * This program is distributed in the hope that it will be useful,
12*9aae5dcdSMark Corbin * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*9aae5dcdSMark Corbin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*9aae5dcdSMark Corbin * GNU General Public License for more details.
15*9aae5dcdSMark Corbin *
16*9aae5dcdSMark Corbin * You should have received a copy of the GNU General Public License
17*9aae5dcdSMark Corbin * along with this program; if not, see <http://www.gnu.org/licenses/>.
18*9aae5dcdSMark Corbin */
19*9aae5dcdSMark Corbin
20*9aae5dcdSMark Corbin #ifndef TARGET_ARCH_THREAD_H
21*9aae5dcdSMark Corbin #define TARGET_ARCH_THREAD_H
22*9aae5dcdSMark Corbin
23*9aae5dcdSMark Corbin /* Compare with cpu_set_upcall() in riscv/riscv/vm_machdep.c */
target_thread_set_upcall(CPURISCVState * regs,abi_ulong entry,abi_ulong arg,abi_ulong stack_base,abi_ulong stack_size)24*9aae5dcdSMark Corbin static inline void target_thread_set_upcall(CPURISCVState *regs,
25*9aae5dcdSMark Corbin abi_ulong entry, abi_ulong arg, abi_ulong stack_base,
26*9aae5dcdSMark Corbin abi_ulong stack_size)
27*9aae5dcdSMark Corbin {
28*9aae5dcdSMark Corbin abi_ulong sp;
29*9aae5dcdSMark Corbin
30*9aae5dcdSMark Corbin sp = ROUND_DOWN(stack_base + stack_size, 16);
31*9aae5dcdSMark Corbin
32*9aae5dcdSMark Corbin regs->gpr[xSP] = sp;
33*9aae5dcdSMark Corbin regs->pc = entry;
34*9aae5dcdSMark Corbin regs->gpr[xA0] = arg;
35*9aae5dcdSMark Corbin }
36*9aae5dcdSMark Corbin
37*9aae5dcdSMark Corbin /* Compare with exec_setregs() in riscv/riscv/machdep.c */
target_thread_init(struct target_pt_regs * regs,struct image_info * infop)38*9aae5dcdSMark Corbin static inline void target_thread_init(struct target_pt_regs *regs,
39*9aae5dcdSMark Corbin struct image_info *infop)
40*9aae5dcdSMark Corbin {
41*9aae5dcdSMark Corbin regs->sepc = infop->entry;
42*9aae5dcdSMark Corbin regs->regs[xRA] = infop->entry;
43*9aae5dcdSMark Corbin regs->regs[xA0] = infop->start_stack;
44*9aae5dcdSMark Corbin regs->regs[xSP] = ROUND_DOWN(infop->start_stack, 16);
45*9aae5dcdSMark Corbin }
46*9aae5dcdSMark Corbin
47*9aae5dcdSMark Corbin #endif /* TARGET_ARCH_THREAD_H */
48