2 * Copyright (c) 2015 The FreeBSD Foundation
4 * Portions of this software were developed by Konstantin Belousov
5 * under sponsorship from the FreeBSD Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 /* FreeBSD/arm64-specific system call handling. */
34 #include <sys/ptrace.h>
35 #include <sys/syscall.h>
37 #include <machine/reg.h>
38 #include <machine/armreg.h>
39 #include <machine/ucontext.h>
42 #include <sysdecode.h>
47 aarch64_fetch_args(struct trussinfo
*trussinfo
, u_int narg
)
50 struct current_syscall
*cs
;
52 u_int i
, reg
, syscall_num
;
54 tid
= trussinfo
->curthread
->tid
;
55 cs
= &trussinfo
->curthread
->cs
;
56 if (ptrace(PT_GETREGS
, tid
, (caddr_t
)®s
, 0) < 0) {
57 fprintf(trussinfo
->outfile
, "-- CANNOT READ REGISTERS --\n");
62 * FreeBSD has two special kinds of system call redirections --
63 * SYS_syscall, and SYS___syscall. The former is the old syscall()
64 * routine, basically; the latter is for quad-aligned arguments.
66 * The system call argument count and code from ptrace() already
67 * account for these, but we need to skip over the first argument.
69 syscall_num
= regs
.x
[8];
70 if (syscall_num
== SYS_syscall
|| syscall_num
== SYS___syscall
) {
72 syscall_num
= regs
.x
[0];
77 for (i
= 0; i
< narg
&& reg
< 8; i
++, reg
++)
78 cs
->args
[i
] = regs
.x
[reg
];
83 aarch64_fetch_retval(struct trussinfo
*trussinfo
, long *retval
, int *errorp
)
88 tid
= trussinfo
->curthread
->tid
;
89 if (ptrace(PT_GETREGS
, tid
, (caddr_t
)®s
, 0) < 0) {
90 fprintf(trussinfo
->outfile
, "-- CANNOT READ REGISTERS --\n");
94 retval
[0] = regs
.x
[0];
95 retval
[1] = regs
.x
[1];
96 *errorp
= !!(regs
.spsr
& PSR_C
);
100 static struct procabi aarch64_freebsd
= {
102 SYSDECODE_ABI_FREEBSD
,
107 PROCABI(aarch64_freebsd
);