1 /*
2  * RISC-V sigcode
3  *
4  * Copyright (c) 2019 Mark Corbin
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_SIGTRAMP_H
21 #define TARGET_ARCH_SIGTRAMP_H
22 
23 /* Compare with sigcode() in riscv/riscv/locore.S */
24 static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
25         unsigned sys_sigreturn)
26 {
27     uint32_t sys_exit = TARGET_FREEBSD_NR_exit;
28 
29     uint32_t sigtramp_code[] = {
30     /*1*/ const_le32(0x00010513),                        /*mv a0, sp*/
31     /*2*/ const_le32(0x00050513 + (sigf_uc << 20)),      /*addi a0,a0,sigf_uc*/
32     /*3*/ const_le32(0x00000293 + (sys_sigreturn << 20)),/*li t0,sys_sigreturn*/
33     /*4*/ const_le32(0x00000073),                        /*ecall*/
34     /*5*/ const_le32(0x00000293 + (sys_exit << 20)),     /*li t0,sys_exit*/
35     /*6*/ const_le32(0x00000073),                        /*ecall*/
36     /*7*/ const_le32(0xFF1FF06F)                         /*b -16*/
37     };
38 
39     return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
40 }
41 #endif /* TARGET_ARCH_SIGTRAMP_H */
42