xref: /openbmc/qemu/bsd-user/riscv/target_arch_sigtramp.h (revision 35ba77d2fcd10efd6db8318bbd4d21fa9402143b)
1*64023250SMark Corbin /*
2*64023250SMark Corbin  * RISC-V sigcode
3*64023250SMark Corbin  *
4*64023250SMark Corbin  * Copyright (c) 2019 Mark Corbin
5*64023250SMark Corbin  *
6*64023250SMark Corbin  * This library is free software; you can redistribute it and/or
7*64023250SMark Corbin  * modify it under the terms of the GNU Lesser General Public
8*64023250SMark Corbin  * License as published by the Free Software Foundation; either
9*64023250SMark Corbin  * version 2 of the License, or (at your option) any later version.
10*64023250SMark Corbin  *
11*64023250SMark Corbin  * This library is distributed in the hope that it will be useful,
12*64023250SMark Corbin  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*64023250SMark Corbin  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*64023250SMark Corbin  * Lesser General Public License for more details.
15*64023250SMark Corbin  *
16*64023250SMark Corbin  * You should have received a copy of the GNU Lesser General Public
17*64023250SMark Corbin  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18*64023250SMark Corbin  */
19*64023250SMark Corbin 
20*64023250SMark Corbin #ifndef TARGET_ARCH_SIGTRAMP_H
21*64023250SMark Corbin #define TARGET_ARCH_SIGTRAMP_H
22*64023250SMark Corbin 
23*64023250SMark Corbin /* Compare with sigcode() in riscv/riscv/locore.S */
setup_sigtramp(abi_ulong offset,unsigned sigf_uc,unsigned sys_sigreturn)24*64023250SMark Corbin static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
25*64023250SMark Corbin         unsigned sys_sigreturn)
26*64023250SMark Corbin {
27*64023250SMark Corbin     uint32_t sys_exit = TARGET_FREEBSD_NR_exit;
28*64023250SMark Corbin 
29*64023250SMark Corbin     uint32_t sigtramp_code[] = {
30*64023250SMark Corbin     /*1*/ const_le32(0x00010513),                        /*mv a0, sp*/
31*64023250SMark Corbin     /*2*/ const_le32(0x00050513 + (sigf_uc << 20)),      /*addi a0,a0,sigf_uc*/
32*64023250SMark Corbin     /*3*/ const_le32(0x00000293 + (sys_sigreturn << 20)),/*li t0,sys_sigreturn*/
33*64023250SMark Corbin     /*4*/ const_le32(0x00000073),                        /*ecall*/
34*64023250SMark Corbin     /*5*/ const_le32(0x00000293 + (sys_exit << 20)),     /*li t0,sys_exit*/
35*64023250SMark Corbin     /*6*/ const_le32(0x00000073),                        /*ecall*/
36*64023250SMark Corbin     /*7*/ const_le32(0xFF1FF06F)                         /*b -16*/
37*64023250SMark Corbin     };
38*64023250SMark Corbin 
39*64023250SMark Corbin     return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
40*64023250SMark Corbin }
41*64023250SMark Corbin #endif /* TARGET_ARCH_SIGTRAMP_H */
42