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