2 * Copyright 2017 Li-Wen Hsu <lwhsu@FreeBSD.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 /* FreeBSD/riscv-specific system call handling. */
31 #include <sys/ptrace.h>
32 #include <sys/syscall.h>
34 #include <machine/frame.h>
35 #include <machine/reg.h>
39 #include <sysdecode.h>
44 riscv_fetch_args(struct trussinfo *trussinfo, u_int narg)
47 struct current_syscall *cs;
49 u_int i, reg, syscall_num;
51 tid = trussinfo->curthread->tid;
52 cs = &trussinfo->curthread->cs;
53 if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) {
54 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
59 * FreeBSD has two special kinds of system call redirections --
60 * SYS_syscall, and SYS___syscall. The former is the old syscall()
61 * routine, basically; the latter is for quad-aligned arguments.
63 * The system call argument count and code from ptrace() already
64 * account for these, but we need to skip over the first argument.
66 syscall_num = regs.t[0];
67 if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
69 syscall_num = regs.a[0];
74 for (i = 0; i < narg && reg < NARGREG; i++, reg++)
75 cs->args[i] = regs.a[reg];
80 riscv_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
85 tid = trussinfo->curthread->tid;
86 if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) {
87 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
91 retval[0] = regs.a[0];
92 retval[1] = regs.a[1];
93 *errorp = !!(regs.t[0]);
97 static struct procabi riscv_freebsd = {
99 SYSDECODE_ABI_FREEBSD,
102 STAILQ_HEAD_INITIALIZER(riscv_freebsd.extra_syscalls),
106 PROCABI(riscv_freebsd);