1 /*
2 * ARM AArch64 sigcode 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_SIGTRAMP_H
21 #define TARGET_ARCH_SIGTRAMP_H
22
23 /* Compare to ENTRY(sigcode) in arm64/arm64/locore.S */
setup_sigtramp(abi_ulong offset,unsigned sigf_uc,unsigned sys_sigreturn)24 static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
25 unsigned sys_sigreturn)
26 {
27 int i;
28 uint32_t sys_exit = TARGET_FREEBSD_NR_exit;
29
30 uint32_t sigtramp_code[] = {
31 /* 1 */ 0x910003e0, /* mov x0, sp */
32 /* 2 */ 0x91000000 + (sigf_uc << 10), /* add x0, x0, #SIGF_UC */
33 /* 3 */ 0xd2800000 + (sys_sigreturn << 5) + 0x8, /* mov x8, #SYS_sigreturn */
34 /* 4 */ 0xd4000001, /* svc #0 */
35 /* 5 */ 0xd2800028 + (sys_exit << 5) + 0x8, /* mov x8, #SYS_exit */
36 /* 6 */ 0xd4000001, /* svc #0 */
37 /* 7 */ 0x17fffffc, /* b -4 */
38 /* 8 */ sys_sigreturn,
39 /* 9 */ sys_exit
40 };
41
42 for (i = 0; i < 9; i++) {
43 tswap32s(&sigtramp_code[i]);
44 }
45
46 return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
47 }
48 #endif /* TARGET_ARCH_SIGTRAMP_H */
49