xref: /illumos-gate/usr/src/lib/libproc/sparc/Pisadep.c (revision d51e90740114c60620c0febffd4d3ce6e280a107)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d51e9074Sab  * Common Development and Distribution License (the "License").
6*d51e9074Sab  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d51e9074Sab  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/stack.h>
297c478bd9Sstevel@tonic-gate #include <sys/regset.h>
307c478bd9Sstevel@tonic-gate #include <sys/frame.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include "Pcontrol.h"
407c478bd9Sstevel@tonic-gate #include "Pstack.h"
417c478bd9Sstevel@tonic-gate #include "Pisadep.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	M_PLT_NRSV	4			/* reserved PLT entries */
447c478bd9Sstevel@tonic-gate #define	M_PLT_ENTSIZE	12			/* size of each PLT entry */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	SYSCALL32 0x91d02008	/* 32-bit syscall (ta 8) instruction */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #ifndef	WINDOWSIZE32
497c478bd9Sstevel@tonic-gate #define	WINDOWSIZE32	(16 * sizeof (int32_t))
507c478bd9Sstevel@tonic-gate #endif
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate const char *
537c478bd9Sstevel@tonic-gate Ppltdest(struct ps_prochandle *P, uintptr_t pltaddr)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	map_info_t *mp = Paddr2mptr(P, pltaddr);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	uintptr_t r_addr;
587c478bd9Sstevel@tonic-gate 	file_info_t *fp;
597c478bd9Sstevel@tonic-gate 	Elf32_Rela r;
607c478bd9Sstevel@tonic-gate 	size_t i;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	if (mp == NULL || (fp = mp->map_file) == NULL ||
637c478bd9Sstevel@tonic-gate 	    fp->file_plt_base == 0 || pltaddr < fp->file_plt_base ||
647c478bd9Sstevel@tonic-gate 	    pltaddr >= fp->file_plt_base + fp->file_plt_size) {
657c478bd9Sstevel@tonic-gate 		errno = EINVAL;
667c478bd9Sstevel@tonic-gate 		return (NULL);
677c478bd9Sstevel@tonic-gate 	}
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	i = (pltaddr - fp->file_plt_base -
707c478bd9Sstevel@tonic-gate 	    M_PLT_NRSV * M_PLT_ENTSIZE) / M_PLT_ENTSIZE;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	r_addr = fp->file_jmp_rel + i * sizeof (Elf32_Rela);
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	if (Pread(P, &r, sizeof (r), r_addr) == sizeof (r) &&
757c478bd9Sstevel@tonic-gate 	    (i = ELF32_R_SYM(r.r_info)) < fp->file_dynsym.sym_symn) {
767c478bd9Sstevel@tonic-gate 
77*d51e9074Sab 		Elf_Data *data = fp->file_dynsym.sym_data_pri;
787c478bd9Sstevel@tonic-gate 		Elf32_Sym *symp = &(((Elf32_Sym *)data->d_buf)[i]);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 		return (fp->file_dynsym.sym_strs + symp->st_name);
817c478bd9Sstevel@tonic-gate 	}
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	return (NULL);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate int
877c478bd9Sstevel@tonic-gate Pissyscall(struct ps_prochandle *P, uintptr_t addr)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	instr_t sysinstr;
907c478bd9Sstevel@tonic-gate 	instr_t instr;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	sysinstr = SYSCALL32;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	if (Pread(P, &instr, sizeof (instr), addr) != sizeof (instr) ||
957c478bd9Sstevel@tonic-gate 	    instr != sysinstr)
967c478bd9Sstevel@tonic-gate 		return (0);
977c478bd9Sstevel@tonic-gate 	else
987c478bd9Sstevel@tonic-gate 		return (1);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate int
1027c478bd9Sstevel@tonic-gate Pissyscall_prev(struct ps_prochandle *P, uintptr_t addr, uintptr_t *dst)
1037c478bd9Sstevel@tonic-gate {
1047c478bd9Sstevel@tonic-gate 	uintptr_t prevaddr = addr - sizeof (instr_t);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if (Pissyscall(P, prevaddr)) {
1077c478bd9Sstevel@tonic-gate 		if (dst)
1087c478bd9Sstevel@tonic-gate 			*dst = prevaddr;
1097c478bd9Sstevel@tonic-gate 		return (1);
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	return (0);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /* ARGSUSED */
1167c478bd9Sstevel@tonic-gate int
1177c478bd9Sstevel@tonic-gate Pissyscall_text(struct ps_prochandle *P, const void *buf, size_t buflen)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	instr_t sysinstr;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	sysinstr = SYSCALL32;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	if (buflen >= sizeof (instr_t) &&
1247c478bd9Sstevel@tonic-gate 	    memcmp(buf, &sysinstr, sizeof (instr_t)) == 0)
1257c478bd9Sstevel@tonic-gate 		return (1);
1267c478bd9Sstevel@tonic-gate 	else
1277c478bd9Sstevel@tonic-gate 		return (0);
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * For gwindows_t support, we define a structure to pass arguments to
1327c478bd9Sstevel@tonic-gate  * a Plwp_iter() callback routine.
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate typedef struct {
1357c478bd9Sstevel@tonic-gate 	struct ps_prochandle *gq_proc;	/* libproc handle */
1367c478bd9Sstevel@tonic-gate 	struct rwindow *gq_rwin;	/* rwindow destination buffer */
1377c478bd9Sstevel@tonic-gate 	uintptr_t gq_addr;		/* stack address to match */
1387c478bd9Sstevel@tonic-gate } gwin_query_t;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate static int
1417c478bd9Sstevel@tonic-gate find_gwin(gwin_query_t *gqp, const lwpstatus_t *psp)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate 	gwindows_t gwin;
1447c478bd9Sstevel@tonic-gate 	struct stat64 st;
1457c478bd9Sstevel@tonic-gate 	char path[64];
1467c478bd9Sstevel@tonic-gate 	ssize_t n;
1477c478bd9Sstevel@tonic-gate 	int fd, i;
1487c478bd9Sstevel@tonic-gate 	int rv = 0; /* Return value for skip to next lwp */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "/proc/%d/lwp/%d/gwindows",
1517c478bd9Sstevel@tonic-gate 	    (int)gqp->gq_proc->pid, (int)psp->pr_lwpid);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	if (stat64(path, &st) == -1 || st.st_size == 0)
1547c478bd9Sstevel@tonic-gate 		return (0); /* Nothing doing; skip to next lwp */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	if ((fd = open64(path, O_RDONLY)) >= 0) {
1577c478bd9Sstevel@tonic-gate 		/*
1587c478bd9Sstevel@tonic-gate 		 * Zero out the gwindows_t because the gwindows file only has
1597c478bd9Sstevel@tonic-gate 		 * as much data as needed to represent the saved windows.
1607c478bd9Sstevel@tonic-gate 		 */
1617c478bd9Sstevel@tonic-gate 		(void) memset(&gwin, 0, sizeof (gwin));
1627c478bd9Sstevel@tonic-gate 		n = read(fd, &gwin, sizeof (gwin));
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 		if (n > 0) {
1657c478bd9Sstevel@tonic-gate 			/*
1667c478bd9Sstevel@tonic-gate 			 * If we actually found a non-zero gwindows file and
1677c478bd9Sstevel@tonic-gate 			 * were able to read it, iterate through the buffers
1687c478bd9Sstevel@tonic-gate 			 * looking for a stack pointer match; if one is found,
1697c478bd9Sstevel@tonic-gate 			 * copy out the corresponding register window.
1707c478bd9Sstevel@tonic-gate 			 */
1717c478bd9Sstevel@tonic-gate 			for (i = 0; i < gwin.wbcnt; i++) {
1727c478bd9Sstevel@tonic-gate 				if (gwin.spbuf[i] == (greg_t *)gqp->gq_addr) {
1737c478bd9Sstevel@tonic-gate 					(void) memcpy(gqp->gq_rwin,
1747c478bd9Sstevel@tonic-gate 					    &gwin.wbuf[i],
1757c478bd9Sstevel@tonic-gate 					    sizeof (struct rwindow));
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 					rv = 1; /* We're done */
1787c478bd9Sstevel@tonic-gate 					break;
1797c478bd9Sstevel@tonic-gate 				}
1807c478bd9Sstevel@tonic-gate 			}
1817c478bd9Sstevel@tonic-gate 		}
1827c478bd9Sstevel@tonic-gate 		(void) close(fd);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	return (rv);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate static int
1897c478bd9Sstevel@tonic-gate read_gwin(struct ps_prochandle *P, struct rwindow *rwp, uintptr_t sp)
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate 	gwin_query_t gq;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	if (P->state == PS_DEAD) {
1947c478bd9Sstevel@tonic-gate 		lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
1957c478bd9Sstevel@tonic-gate 		uint_t n;
1967c478bd9Sstevel@tonic-gate 		int i;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 		for (n = 0; n < P->core->core_nlwp; n++, lwp = list_next(lwp)) {
1997c478bd9Sstevel@tonic-gate 			gwindows_t *gwin = lwp->lwp_gwins;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 			if (gwin == NULL)
2027c478bd9Sstevel@tonic-gate 				continue; /* No gwindows for this lwp */
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 			/*
2057c478bd9Sstevel@tonic-gate 			 * If this lwp has gwindows associated with it, iterate
2067c478bd9Sstevel@tonic-gate 			 * through the buffers looking for a stack pointer
2077c478bd9Sstevel@tonic-gate 			 * match; if one is found, copy out the register window.
2087c478bd9Sstevel@tonic-gate 			 */
2097c478bd9Sstevel@tonic-gate 			for (i = 0; i < gwin->wbcnt; i++) {
2107c478bd9Sstevel@tonic-gate 				if (gwin->spbuf[i] == (greg_t *)sp) {
2117c478bd9Sstevel@tonic-gate 					(void) memcpy(rwp, &gwin->wbuf[i],
2127c478bd9Sstevel@tonic-gate 					    sizeof (struct rwindow));
2137c478bd9Sstevel@tonic-gate 					return (0); /* We're done */
2147c478bd9Sstevel@tonic-gate 				}
2157c478bd9Sstevel@tonic-gate 			}
2167c478bd9Sstevel@tonic-gate 		}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 		return (-1); /* No gwindows match found */
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	gq.gq_proc = P;
2237c478bd9Sstevel@tonic-gate 	gq.gq_rwin = rwp;
2247c478bd9Sstevel@tonic-gate 	gq.gq_addr = sp;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	return (Plwp_iter(P, (proc_lwp_f *)find_gwin, &gq) ? 0 : -1);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate static void
2307c478bd9Sstevel@tonic-gate ucontext_n_to_prgregs(const ucontext_t *src, prgregset_t dst)
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	const greg_t *gregs = &src->uc_mcontext.gregs[0];
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	dst[R_PSR] = gregs[REG_PSR];
2357c478bd9Sstevel@tonic-gate 	dst[R_PC] = gregs[REG_PC];
2367c478bd9Sstevel@tonic-gate 	dst[R_nPC] = gregs[REG_nPC];
2377c478bd9Sstevel@tonic-gate 	dst[R_Y] = gregs[REG_Y];
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	dst[R_G1] = gregs[REG_G1];
2407c478bd9Sstevel@tonic-gate 	dst[R_G2] = gregs[REG_G2];
2417c478bd9Sstevel@tonic-gate 	dst[R_G3] = gregs[REG_G3];
2427c478bd9Sstevel@tonic-gate 	dst[R_G4] = gregs[REG_G4];
2437c478bd9Sstevel@tonic-gate 	dst[R_G5] = gregs[REG_G5];
2447c478bd9Sstevel@tonic-gate 	dst[R_G6] = gregs[REG_G6];
2457c478bd9Sstevel@tonic-gate 	dst[R_G7] = gregs[REG_G7];
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	dst[R_O0] = gregs[REG_O0];
2487c478bd9Sstevel@tonic-gate 	dst[R_O1] = gregs[REG_O1];
2497c478bd9Sstevel@tonic-gate 	dst[R_O2] = gregs[REG_O2];
2507c478bd9Sstevel@tonic-gate 	dst[R_O3] = gregs[REG_O3];
2517c478bd9Sstevel@tonic-gate 	dst[R_O4] = gregs[REG_O4];
2527c478bd9Sstevel@tonic-gate 	dst[R_O5] = gregs[REG_O5];
2537c478bd9Sstevel@tonic-gate 	dst[R_O6] = gregs[REG_O6];
2547c478bd9Sstevel@tonic-gate 	dst[R_O7] = gregs[REG_O7];
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate int
2587c478bd9Sstevel@tonic-gate Pstack_iter(struct ps_prochandle *P, const prgregset_t regs,
2597c478bd9Sstevel@tonic-gate 	proc_stack_f *func, void *arg)
2607c478bd9Sstevel@tonic-gate {
2617c478bd9Sstevel@tonic-gate 	prgreg_t *prevfp = NULL;
2627c478bd9Sstevel@tonic-gate 	uint_t pfpsize = 0;
2637c478bd9Sstevel@tonic-gate 	int nfp = 0;
2647c478bd9Sstevel@tonic-gate 	prgregset_t gregs;
2657c478bd9Sstevel@tonic-gate 	long args[6];
2667c478bd9Sstevel@tonic-gate 	prgreg_t fp;
2677c478bd9Sstevel@tonic-gate 	int i;
2687c478bd9Sstevel@tonic-gate 	int rv;
2697c478bd9Sstevel@tonic-gate 	uintptr_t sp;
2707c478bd9Sstevel@tonic-gate 	ssize_t n;
2717c478bd9Sstevel@tonic-gate 	uclist_t ucl;
2727c478bd9Sstevel@tonic-gate 	ucontext_t uc;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	init_uclist(&ucl, P);
2757c478bd9Sstevel@tonic-gate 	(void) memcpy(gregs, regs, sizeof (gregs));
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	for (;;) {
2787c478bd9Sstevel@tonic-gate 		fp = gregs[R_FP];
2797c478bd9Sstevel@tonic-gate 		if (stack_loop(fp, &prevfp, &nfp, &pfpsize))
2807c478bd9Sstevel@tonic-gate 			break;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 		for (i = 0; i < 6; i++)
2837c478bd9Sstevel@tonic-gate 			args[i] = gregs[R_I0 + i];
2847c478bd9Sstevel@tonic-gate 		if ((rv = func(arg, gregs, 6, args)) != 0)
2857c478bd9Sstevel@tonic-gate 			break;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 		gregs[R_PC] = gregs[R_I7];
2887c478bd9Sstevel@tonic-gate 		gregs[R_nPC] = gregs[R_PC] + 4;
2897c478bd9Sstevel@tonic-gate 		(void) memcpy(&gregs[R_O0], &gregs[R_I0], 8*sizeof (prgreg_t));
2907c478bd9Sstevel@tonic-gate 		if ((sp = gregs[R_FP]) == 0)
2917c478bd9Sstevel@tonic-gate 			break;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 		sp += STACK_BIAS;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 		if (find_uclink(&ucl, sp + SA(sizeof (struct frame))) &&
2967c478bd9Sstevel@tonic-gate 		    Pread(P, &uc, sizeof (uc), sp +
2977c478bd9Sstevel@tonic-gate 		    SA(sizeof (struct frame))) == sizeof (uc)) {
2987c478bd9Sstevel@tonic-gate 			ucontext_n_to_prgregs(&uc, gregs);
2997c478bd9Sstevel@tonic-gate 			sp = gregs[R_SP] + STACK_BIAS;
3007c478bd9Sstevel@tonic-gate 		}
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 		n = Pread(P, &gregs[R_L0], sizeof (struct rwindow), sp);
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 		if (n == sizeof (struct rwindow))
3057c478bd9Sstevel@tonic-gate 			continue;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 		/*
3087c478bd9Sstevel@tonic-gate 		 * If we get here, then our Pread of the register window
3097c478bd9Sstevel@tonic-gate 		 * failed.  If this is because the address was not mapped,
3107c478bd9Sstevel@tonic-gate 		 * then we attempt to read this window via any gwindows
3117c478bd9Sstevel@tonic-gate 		 * information we have.  If that too fails, abort our loop.
3127c478bd9Sstevel@tonic-gate 		 */
3137c478bd9Sstevel@tonic-gate 		if (n > 0)
3147c478bd9Sstevel@tonic-gate 			break;	/* Failed for reason other than not mapped */
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 		if (read_gwin(P, (struct rwindow *)&gregs[R_L0], sp) == -1)
3177c478bd9Sstevel@tonic-gate 			break;	/* No gwindows match either */
3187c478bd9Sstevel@tonic-gate 	}
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	if (prevfp)
3217c478bd9Sstevel@tonic-gate 		free(prevfp);
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	free_uclist(&ucl);
3247c478bd9Sstevel@tonic-gate 	return (rv);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate uintptr_t
3287c478bd9Sstevel@tonic-gate Psyscall_setup(struct ps_prochandle *P, int nargs, int sysindex, uintptr_t sp)
3297c478bd9Sstevel@tonic-gate {
3307c478bd9Sstevel@tonic-gate 	sp -= (nargs > 6)?
3317c478bd9Sstevel@tonic-gate 		WINDOWSIZE32 + sizeof (int32_t) * (1 + nargs) :
3327c478bd9Sstevel@tonic-gate 		WINDOWSIZE32 + sizeof (int32_t) * (1 + 6);
3337c478bd9Sstevel@tonic-gate 	sp = PSTACK_ALIGN32(sp);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	P->status.pr_lwp.pr_reg[R_G1] = sysindex;
3367c478bd9Sstevel@tonic-gate 	P->status.pr_lwp.pr_reg[R_SP] = sp;
3377c478bd9Sstevel@tonic-gate 	P->status.pr_lwp.pr_reg[R_PC] = P->sysaddr;
3387c478bd9Sstevel@tonic-gate 	P->status.pr_lwp.pr_reg[R_nPC] = P->sysaddr + sizeof (instr_t);
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	return (sp + WINDOWSIZE32 + sizeof (int32_t));
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate int
3447c478bd9Sstevel@tonic-gate Psyscall_copyinargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
3457c478bd9Sstevel@tonic-gate     uintptr_t ap)
3467c478bd9Sstevel@tonic-gate {
3477c478bd9Sstevel@tonic-gate 	uint32_t arglist[MAXARGS+2];
3487c478bd9Sstevel@tonic-gate 	int i;
3497c478bd9Sstevel@tonic-gate 	argdes_t *adp;
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	for (i = 0, adp = argp; i < nargs; i++, adp++) {
3527c478bd9Sstevel@tonic-gate 		arglist[i] = adp->arg_value;
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 		if (i < 6)
3557c478bd9Sstevel@tonic-gate 			(void) Pputareg(P, R_O0+i, adp->arg_value);
3567c478bd9Sstevel@tonic-gate 	}
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	if (nargs > 6 &&
3597c478bd9Sstevel@tonic-gate 	    Pwrite(P, &arglist[0], sizeof (int32_t) * nargs,
3607c478bd9Sstevel@tonic-gate 	    (uintptr_t)ap) != sizeof (int32_t) * nargs)
3617c478bd9Sstevel@tonic-gate 		return (-1);
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	return (0);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate /* ARGSUSED */
3677c478bd9Sstevel@tonic-gate int
3687c478bd9Sstevel@tonic-gate Psyscall_copyoutargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
3697c478bd9Sstevel@tonic-gate     uintptr_t ap)
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate 	/* Do nothing */
3727c478bd9Sstevel@tonic-gate 	return (0);
3737c478bd9Sstevel@tonic-gate }
374