1106716Smarcel/* 2204977Simp * Copyright 1997 Sean Eric Fagan 3106716Smarcel * 4106716Smarcel * Redistribution and use in source and binary forms, with or without 5106716Smarcel * modification, are permitted provided that the following conditions 6106716Smarcel * are met: 7106716Smarcel * 1. Redistributions of source code must retain the above copyright 8106716Smarcel * notice, this list of conditions and the following disclaimer. 9106716Smarcel * 2. Redistributions in binary form must reproduce the above copyright 10106716Smarcel * notice, this list of conditions and the following disclaimer in the 11106716Smarcel * documentation and/or other materials provided with the distribution. 12106716Smarcel * 3. All advertising materials mentioning features or use of this software 13106716Smarcel * must display the following acknowledgement: 14106716Smarcel * This product includes software developed by Sean Eric Fagan 15106716Smarcel * 4. Neither the name of the author may be used to endorse or promote 16106716Smarcel * products derived from this software without specific prior written 17106716Smarcel * permission. 18106716Smarcel * 19106716Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20106716Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21106716Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22106716Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23106716Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24106716Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25106716Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26106716Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27106716Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28106716Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29106716Smarcel * SUCH DAMAGE. 30106716Smarcel */ 31106716Smarcel 32290052Sjhb#include <sys/cdefs.h> 33290052Sjhb__FBSDID("$FreeBSD$"); 34106716Smarcel 35290052Sjhb/* FreeBSD/ia64-specific system call handling. */ 36106716Smarcel 37168569Sdelphij#include <sys/ptrace.h> 38106716Smarcel#include <sys/syscall.h> 39106716Smarcel 40106716Smarcel#include <machine/reg.h> 41106716Smarcel 42106716Smarcel#include <stdio.h> 43106716Smarcel 44106716Smarcel#include "truss.h" 45106716Smarcel 46106716Smarcel#include "syscalls.h" 47106716Smarcel 48290052Sjhbstatic int 49290052Sjhbia64_fetch_args(struct trussinfo *trussinfo, u_int narg) 50240562Szont{ 51240005Szont struct reg regs; 52290052Sjhb struct current_syscall *cs; 53240005Szont unsigned long *parm_offset; 54240562Szont lwpid_t tid; 55290052Sjhb int i; 56106716Smarcel 57240562Szont tid = trussinfo->curthread->tid; 58290052Sjhb cs = &trussinfo->curthread->cs; 59240562Szont if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) { 60240005Szont fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 61240005Szont return; 62240005Szont } 63240005Szont parm_offset = ®s.r_scratch.gr16; 64106716Smarcel 65240005Szont /* 66290052Sjhb * FreeBSD has two special kinds of system call redirections -- 67240005Szont * SYS_syscall, and SYS___syscall. The former is the old syscall() 68240005Szont * routine, basically; the latter is for quad-aligned arguments. 69290052Sjhb * 70290052Sjhb * The system call argument count and code from ptrace() already 71290052Sjhb * account for these, but we need to skip over %rax if it contains 72290052Sjhb * either of these values. 73240005Szont */ 74290052Sjhb switch (regs.r_scratch.gr15) { 75290052Sjhb case SYS_syscall: 76290052Sjhb case SYS___syscall: 77290052Sjhb parm_offset++; 78290052Sjhb break; 79240005Szont } 80106716Smarcel 81290052Sjhb memcpy(cs->args, parm_offset, narg * sizeof(long)); 82106716Smarcel 83290052Sjhb return (0); 84106716Smarcel} 85106716Smarcel 86290052Sjhbstatic int 87290052Sjhbia64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) 88122348Smarcel{ 89240005Szont struct reg regs; 90240562Szont lwpid_t tid; 91106716Smarcel 92240562Szont tid = trussinfo->curthread->tid; 93240562Szont if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) { 94240005Szont fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 95240005Szont return (-1); 96240005Szont } 97106716Smarcel 98290052Sjhb retval[0] = regs.r_scratch.gr8; 99290052Sjhb retval[1] = regs.r_scratch.gr9; 100290052Sjhb *errorp = (regs.r_scratch.gr10 != 0) ? 1 : 0; 101290052Sjhb return (0); 102290052Sjhb} 103240005Szont 104290052Sjhbstatic struct procabi ia64_fbsd = { 105290052Sjhb "FreeBSD ELF64", 106290052Sjhb syscallnames, 107290052Sjhb nitems(syscallnames), 108290052Sjhb ia64_fetch_args, 109290052Sjhb ia64_fetch_retval 110290052Sjhb}; 111106716Smarcel 112290052SjhbPROCABI(ia64_fbsd); 113