10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/dtrace_impl.h> 300Sstevel@tonic-gate #include <sys/atomic.h> 310Sstevel@tonic-gate #include <sys/model.h> 320Sstevel@tonic-gate #include <sys/frame.h> 330Sstevel@tonic-gate #include <sys/stack.h> 340Sstevel@tonic-gate #include <sys/machpcb.h> 350Sstevel@tonic-gate #include <sys/procfs_isa.h> 360Sstevel@tonic-gate #include <sys/cmn_err.h> 37*191Sahl #include <sys/sysmacros.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #define DTRACE_FMT3OP3_MASK 0x81000000 400Sstevel@tonic-gate #define DTRACE_FMT3OP3 0x80000000 410Sstevel@tonic-gate #define DTRACE_FMT3RS1_SHIFT 14 420Sstevel@tonic-gate #define DTRACE_FMT3RD_SHIFT 25 430Sstevel@tonic-gate #define DTRACE_RMASK 0x1f 440Sstevel@tonic-gate #define DTRACE_REG_L0 16 450Sstevel@tonic-gate #define DTRACE_REG_O7 15 460Sstevel@tonic-gate #define DTRACE_REG_I0 24 470Sstevel@tonic-gate #define DTRACE_REG_I6 30 480Sstevel@tonic-gate #define DTRACE_RET 0x81c7e008 490Sstevel@tonic-gate #define DTRACE_RETL 0x81c3e008 500Sstevel@tonic-gate #define DTRACE_SAVE_MASK 0xc1f80000 510Sstevel@tonic-gate #define DTRACE_SAVE 0x81e00000 520Sstevel@tonic-gate #define DTRACE_RESTORE 0x81e80000 530Sstevel@tonic-gate #define DTRACE_CALL_MASK 0xc0000000 540Sstevel@tonic-gate #define DTRACE_CALL 0x40000000 550Sstevel@tonic-gate #define DTRACE_JMPL_MASK 0x81f10000 560Sstevel@tonic-gate #define DTRACE_JMPL 0x81c00000 570Sstevel@tonic-gate 580Sstevel@tonic-gate extern int dtrace_getupcstack_top(uint64_t *, int, uintptr_t *); 59*191Sahl extern int dtrace_getustackdepth_top(uintptr_t *); 600Sstevel@tonic-gate extern ulong_t dtrace_getreg_win(uint_t, uint_t); 610Sstevel@tonic-gate extern void dtrace_putreg_win(uint_t, ulong_t); 620Sstevel@tonic-gate extern int dtrace_fish(int, int, uintptr_t *); 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * This is similar in principle to getpcstack(), but there are several marked 660Sstevel@tonic-gate * differences in implementation: 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * (a) dtrace_getpcstack() is called from probe context. Thus, the call 690Sstevel@tonic-gate * to flush_windows() from getpcstack() is a call to the probe-safe 700Sstevel@tonic-gate * equivalent here. 710Sstevel@tonic-gate * 720Sstevel@tonic-gate * (b) dtrace_getpcstack() is willing to sacrifice some performance to get 730Sstevel@tonic-gate * a correct stack. While consumers of getpcstack() are largely 740Sstevel@tonic-gate * subsystem-specific in-kernel debugging facilities, DTrace consumers 750Sstevel@tonic-gate * are arbitrary user-level analysis tools; dtrace_getpcstack() must 760Sstevel@tonic-gate * deliver as correct a stack as possible. Details on the issues 770Sstevel@tonic-gate * surrounding stack correctness are found below. 780Sstevel@tonic-gate * 79*191Sahl * (c) dtrace_getpcstack() _always_ fills in pcstack_limit pc_t's -- filling 80*191Sahl * in the difference between the stack depth and pcstack_limit with NULLs. 810Sstevel@tonic-gate * Due to this behavior dtrace_getpcstack() returns void. 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * (d) dtrace_getpcstack() takes a third parameter, aframes, that 840Sstevel@tonic-gate * denotes the number of _artificial frames_ on the bottom of the 850Sstevel@tonic-gate * stack. An artificial frame is one induced by the provider; all 860Sstevel@tonic-gate * artificial frames are stripped off before frames are stored to 870Sstevel@tonic-gate * pcstack. 880Sstevel@tonic-gate * 890Sstevel@tonic-gate * (e) dtrace_getpcstack() takes a fourth parameter, pc, that indicates 900Sstevel@tonic-gate * an interrupted program counter (if any). This should be a non-NULL 910Sstevel@tonic-gate * value if and only if the hit probe is unanchored. (Anchored probes 920Sstevel@tonic-gate * don't fire through an interrupt source.) This parameter is used to 930Sstevel@tonic-gate * assure (b), above. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate void 960Sstevel@tonic-gate dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, uint32_t *pc) 970Sstevel@tonic-gate { 980Sstevel@tonic-gate struct frame *fp, *nextfp, *minfp, *stacktop; 990Sstevel@tonic-gate int depth = 0; 1000Sstevel@tonic-gate int on_intr, j = 0; 1010Sstevel@tonic-gate uint32_t i, r; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate fp = (struct frame *)((caddr_t)dtrace_getfp() + STACK_BIAS); 1040Sstevel@tonic-gate dtrace_flush_windows(); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate if (pc != NULL) { 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * If we've been passed a non-NULL pc, we need to determine 1090Sstevel@tonic-gate * whether or not the specified program counter falls in a leaf 1100Sstevel@tonic-gate * function. If it falls within a leaf function, we know that 1110Sstevel@tonic-gate * %o7 is valid in its frame (and we can just drive on). If 1120Sstevel@tonic-gate * it's a non-leaf, however, we know that %o7 is garbage in the 1130Sstevel@tonic-gate * bottom frame. To trim this frame, we simply increment 1140Sstevel@tonic-gate * aframes and drop into the stack-walking loop. 1150Sstevel@tonic-gate * 1160Sstevel@tonic-gate * To quickly determine if the specified program counter is in 1170Sstevel@tonic-gate * a leaf function, we exploit the fact that leaf functions 1180Sstevel@tonic-gate * tend to be short and non-leaf functions tend to frequently 1190Sstevel@tonic-gate * perform operations that are only permitted in a non-leaf 1200Sstevel@tonic-gate * function (e.g., using the %i's or %l's; calling a function; 1210Sstevel@tonic-gate * performing a restore). We exploit these tendencies by 1220Sstevel@tonic-gate * simply scanning forward from the specified %pc -- if we see 1230Sstevel@tonic-gate * an operation only permitted in a non-leaf, we know we're in 1240Sstevel@tonic-gate * a non-leaf; if we see a retl, we know we're in a leaf. 1250Sstevel@tonic-gate * Fortunately, one need not perform anywhere near full 1260Sstevel@tonic-gate * disassembly to effectively determine the former: determining 1270Sstevel@tonic-gate * that an instruction is a format-3 instruction and decoding 1280Sstevel@tonic-gate * its rd and rs1 fields, for example, requires very little 1290Sstevel@tonic-gate * manipulation. Overall, this method of leaf determination 1300Sstevel@tonic-gate * performs quite well: on average, we only examine between 1310Sstevel@tonic-gate * 1.5 and 2.5 instructions before making the determination. 1320Sstevel@tonic-gate * (Outliers do exist, however; of note is the non-leaf 1330Sstevel@tonic-gate * function ip_sioctl_not_ours() which -- as of this writing -- 1340Sstevel@tonic-gate * has a whopping 455 straight instructions that manipulate 1350Sstevel@tonic-gate * only %g's and %o's.) 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate int delay = 0; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate if (depth < pcstack_limit) 1400Sstevel@tonic-gate pcstack[depth++] = (pc_t)pc; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate for (;;) { 1430Sstevel@tonic-gate i = pc[j++]; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate if ((i & DTRACE_FMT3OP3_MASK) == DTRACE_FMT3OP3) { 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * This is a format-3 instruction. We can 1480Sstevel@tonic-gate * look at rd and rs1. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate r = (i >> DTRACE_FMT3RS1_SHIFT) & DTRACE_RMASK; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate if (r >= DTRACE_REG_L0) 1530Sstevel@tonic-gate goto nonleaf; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate r = (i >> DTRACE_FMT3RD_SHIFT) & DTRACE_RMASK; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate if (r >= DTRACE_REG_L0) 1580Sstevel@tonic-gate goto nonleaf; 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate if ((i & DTRACE_JMPL_MASK) == DTRACE_JMPL) { 1610Sstevel@tonic-gate delay = 1; 1620Sstevel@tonic-gate continue; 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate /* 1660Sstevel@tonic-gate * If we see explicit manipulation with %o7 1670Sstevel@tonic-gate * as a destination register, we know that 1680Sstevel@tonic-gate * %o7 is likely bogus -- and we treat this 1690Sstevel@tonic-gate * function as a non-leaf. 1700Sstevel@tonic-gate */ 1710Sstevel@tonic-gate if (r == DTRACE_REG_O7) { 1720Sstevel@tonic-gate if (delay) 1730Sstevel@tonic-gate goto leaf; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate i &= DTRACE_JMPL_MASK; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate if (i == DTRACE_JMPL) { 1780Sstevel@tonic-gate delay = 1; 1790Sstevel@tonic-gate continue; 1800Sstevel@tonic-gate } 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate goto nonleaf; 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate } else { 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * If this is a call, it may or may not be 1870Sstevel@tonic-gate * a leaf; we need to check the delay slot. 1880Sstevel@tonic-gate */ 1890Sstevel@tonic-gate if ((i & DTRACE_CALL_MASK) == DTRACE_CALL) { 1900Sstevel@tonic-gate delay = 1; 1910Sstevel@tonic-gate continue; 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate * If we see a ret it's not a leaf; if we 1960Sstevel@tonic-gate * see a retl, it is a leaf. 1970Sstevel@tonic-gate */ 1980Sstevel@tonic-gate if (i == DTRACE_RET) 1990Sstevel@tonic-gate goto nonleaf; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate if (i == DTRACE_RETL) 2020Sstevel@tonic-gate goto leaf; 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * Finally, if it's a save, it should be 2060Sstevel@tonic-gate * treated as a leaf; if it's a restore it 2070Sstevel@tonic-gate * should not be treated as a leaf. 2080Sstevel@tonic-gate */ 2090Sstevel@tonic-gate if ((i & DTRACE_SAVE_MASK) == DTRACE_SAVE) 2100Sstevel@tonic-gate goto leaf; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate if ((i & DTRACE_SAVE_MASK) == DTRACE_RESTORE) 2130Sstevel@tonic-gate goto nonleaf; 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate if (delay) { 2170Sstevel@tonic-gate /* 2180Sstevel@tonic-gate * If this was a delay slot instruction and 2190Sstevel@tonic-gate * we didn't pick it up elsewhere, this is a 2200Sstevel@tonic-gate * non-leaf. 2210Sstevel@tonic-gate */ 2220Sstevel@tonic-gate goto nonleaf; 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate nonleaf: 2260Sstevel@tonic-gate aframes++; 2270Sstevel@tonic-gate leaf: 2280Sstevel@tonic-gate ; 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate if ((on_intr = CPU_ON_INTR(CPU)) != 0) 2320Sstevel@tonic-gate stacktop = (struct frame *)(CPU->cpu_intr_stack + SA(MINFRAME)); 2330Sstevel@tonic-gate else 2340Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 2350Sstevel@tonic-gate minfp = fp; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate while (depth < pcstack_limit) { 2380Sstevel@tonic-gate nextfp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 2390Sstevel@tonic-gate if (nextfp <= minfp || nextfp >= stacktop) { 2400Sstevel@tonic-gate if (!on_intr && nextfp == stacktop && aframes != 0) { 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * If we are exactly at the top of the stack 2430Sstevel@tonic-gate * with a non-zero number of artificial frames, 2440Sstevel@tonic-gate * it must be that the stack is filled with 2450Sstevel@tonic-gate * nothing _but_ artificial frames. In this 2460Sstevel@tonic-gate * case, we assert that this is so, zero 2470Sstevel@tonic-gate * pcstack, and return. 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate ASSERT(aframes == 1); 2500Sstevel@tonic-gate ASSERT(depth == 0); 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate while (depth < pcstack_limit) 2530Sstevel@tonic-gate pcstack[depth++] = NULL; 2540Sstevel@tonic-gate return; 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate if (on_intr) { 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * Hop from interrupt stack to thread stack. 2600Sstevel@tonic-gate */ 2610Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 2620Sstevel@tonic-gate minfp = (struct frame *)curthread->t_stkbase; 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate on_intr = 0; 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate if (nextfp > minfp && nextfp < stacktop) 2670Sstevel@tonic-gate continue; 2680Sstevel@tonic-gate } else { 2690Sstevel@tonic-gate /* 2700Sstevel@tonic-gate * High-level interrupts may occur when %sp is 2710Sstevel@tonic-gate * not necessarily contained in the stack 2720Sstevel@tonic-gate * bounds implied by %g7 -- interrupt thread 2730Sstevel@tonic-gate * management runs with %pil at DISP_LEVEL, 2740Sstevel@tonic-gate * and high-level interrupts may thus occur 2750Sstevel@tonic-gate * in windows when %sp and %g7 are not self- 2760Sstevel@tonic-gate * consistent. If we call dtrace_getpcstack() 2770Sstevel@tonic-gate * from a high-level interrupt that has occurred 2780Sstevel@tonic-gate * in such a window, we will fail the above test 2790Sstevel@tonic-gate * of nextfp against minfp/stacktop. If the 2800Sstevel@tonic-gate * high-level interrupt has in turn interrupted 2810Sstevel@tonic-gate * a non-passivated interrupt thread, we 2820Sstevel@tonic-gate * will execute the below code with non-zero 2830Sstevel@tonic-gate * aframes. We therefore want to assert that 2840Sstevel@tonic-gate * aframes is zero _or_ we are in a high-level 2850Sstevel@tonic-gate * interrupt -- but because cpu_intr_actv is 2860Sstevel@tonic-gate * updated with high-level interrupts enabled, 2870Sstevel@tonic-gate * we must reduce this to only asserting that 2880Sstevel@tonic-gate * %pil is greater than DISP_LEVEL. 2890Sstevel@tonic-gate */ 2900Sstevel@tonic-gate ASSERT(aframes == 0 || 2910Sstevel@tonic-gate dtrace_getipl() > DISP_LEVEL); 2920Sstevel@tonic-gate pcstack[depth++] = (pc_t)fp->fr_savpc; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate while (depth < pcstack_limit) 2960Sstevel@tonic-gate pcstack[depth++] = NULL; 2970Sstevel@tonic-gate return; 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate if (aframes > 0) { 3010Sstevel@tonic-gate aframes--; 3020Sstevel@tonic-gate } else { 3030Sstevel@tonic-gate pcstack[depth++] = (pc_t)fp->fr_savpc; 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate fp = nextfp; 3070Sstevel@tonic-gate minfp = fp; 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate 311*191Sahl static int 312*191Sahl dtrace_getustack_common(uint64_t *pcstack, int pcstack_limit, uintptr_t sp) 313*191Sahl { 314*191Sahl proc_t *p = curproc; 315*191Sahl int ret = 0; 316*191Sahl 317*191Sahl ASSERT(pcstack == NULL || pcstack_limit > 0); 318*191Sahl 319*191Sahl if (p->p_model == DATAMODEL_NATIVE) { 320*191Sahl for (;;) { 321*191Sahl struct frame *fr = (struct frame *)(sp + STACK_BIAS); 322*191Sahl uintptr_t pc; 323*191Sahl 324*191Sahl if (sp == 0 || fr == NULL || 325*191Sahl !IS_P2ALIGNED((uintptr_t)fr, STACK_ALIGN)) 326*191Sahl break; 327*191Sahl 328*191Sahl pc = dtrace_fulword(&fr->fr_savpc); 329*191Sahl sp = dtrace_fulword(&fr->fr_savfp); 330*191Sahl 331*191Sahl if (pc == 0) 332*191Sahl break; 333*191Sahl 334*191Sahl ret++; 335*191Sahl 336*191Sahl if (pcstack != NULL) { 337*191Sahl *pcstack++ = pc; 338*191Sahl pcstack_limit--; 339*191Sahl if (pcstack_limit == 0) 340*191Sahl break; 341*191Sahl } 342*191Sahl } 343*191Sahl } else { 344*191Sahl for (;;) { 345*191Sahl struct frame32 *fr = (struct frame32 *)sp; 346*191Sahl uint32_t pc; 347*191Sahl 348*191Sahl if (sp == 0 || 349*191Sahl !IS_P2ALIGNED((uintptr_t)fr, STACK_ALIGN32)) 350*191Sahl break; 351*191Sahl 352*191Sahl pc = dtrace_fuword32(&fr->fr_savpc); 353*191Sahl sp = dtrace_fuword32(&fr->fr_savfp); 354*191Sahl 355*191Sahl if (pc == 0) 356*191Sahl break; 357*191Sahl 358*191Sahl ret++; 359*191Sahl 360*191Sahl if (pcstack != NULL) { 361*191Sahl *pcstack++ = pc; 362*191Sahl pcstack_limit--; 363*191Sahl if (pcstack_limit == 0) 364*191Sahl break; 365*191Sahl } 366*191Sahl } 367*191Sahl } 368*191Sahl 369*191Sahl return (ret); 370*191Sahl } 371*191Sahl 3720Sstevel@tonic-gate void 3730Sstevel@tonic-gate dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) 3740Sstevel@tonic-gate { 3750Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread); 376*191Sahl proc_t *p = curproc; 3770Sstevel@tonic-gate struct regs *rp; 3780Sstevel@tonic-gate uintptr_t sp; 3790Sstevel@tonic-gate int n; 3800Sstevel@tonic-gate 381*191Sahl if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL) 3820Sstevel@tonic-gate return; 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate if (pcstack_limit <= 0) 3850Sstevel@tonic-gate return; 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate *pcstack++ = (uint64_t)p->p_pid; 3880Sstevel@tonic-gate pcstack_limit--; 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate if (pcstack_limit <= 0) 3910Sstevel@tonic-gate return; 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_pc; 3940Sstevel@tonic-gate pcstack_limit--; 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate if (pcstack_limit <= 0) 3970Sstevel@tonic-gate return; 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { 4000Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_o7; 4010Sstevel@tonic-gate pcstack_limit--; 4020Sstevel@tonic-gate if (pcstack_limit <= 0) 4030Sstevel@tonic-gate return; 4040Sstevel@tonic-gate } 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate sp = rp->r_sp; 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate n = dtrace_getupcstack_top(pcstack, pcstack_limit, &sp); 4090Sstevel@tonic-gate ASSERT(n >= 0); 4100Sstevel@tonic-gate ASSERT(n <= pcstack_limit); 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate pcstack += n; 4130Sstevel@tonic-gate pcstack_limit -= n; 414*191Sahl if (pcstack_limit <= 0) 415*191Sahl return; 4160Sstevel@tonic-gate 417*191Sahl n = dtrace_getustack_common(pcstack, pcstack_limit, sp); 418*191Sahl ASSERT(n >= 0); 419*191Sahl ASSERT(n <= pcstack_limit); 4200Sstevel@tonic-gate 421*191Sahl pcstack += n; 422*191Sahl pcstack_limit -= n; 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate while (pcstack_limit-- > 0) 4250Sstevel@tonic-gate *pcstack++ = NULL; 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 428*191Sahl int 429*191Sahl dtrace_getustackdepth(void) 430*191Sahl { 431*191Sahl klwp_t *lwp = ttolwp(curthread); 432*191Sahl proc_t *p = curproc; 433*191Sahl struct regs *rp; 434*191Sahl uintptr_t sp; 435*191Sahl int n = 1; 436*191Sahl 437*191Sahl if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL) 438*191Sahl return (0); 439*191Sahl 440*191Sahl if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT)) 441*191Sahl return (-1); 442*191Sahl 443*191Sahl if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) 444*191Sahl n++; 445*191Sahl 446*191Sahl sp = rp->r_sp; 447*191Sahl 448*191Sahl n += dtrace_getustackdepth_top(&sp); 449*191Sahl n += dtrace_getustack_common(NULL, 0, sp); 450*191Sahl 451*191Sahl return (n); 452*191Sahl } 453*191Sahl 4540Sstevel@tonic-gate void 4550Sstevel@tonic-gate dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack, int pcstack_limit) 4560Sstevel@tonic-gate { 4570Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread); 4580Sstevel@tonic-gate proc_t *p = ttoproc(curthread); 4590Sstevel@tonic-gate struct regs *rp; 4600Sstevel@tonic-gate uintptr_t sp; 4610Sstevel@tonic-gate 462*191Sahl if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL) 4630Sstevel@tonic-gate return; 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (pcstack_limit <= 0) 4660Sstevel@tonic-gate return; 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate *pcstack++ = (uint64_t)p->p_pid; 4690Sstevel@tonic-gate pcstack_limit--; 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate if (pcstack_limit <= 0) 4720Sstevel@tonic-gate return; 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { 4750Sstevel@tonic-gate *fpstack++ = 0; 4760Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_pc; 4770Sstevel@tonic-gate pcstack_limit--; 4780Sstevel@tonic-gate if (pcstack_limit <= 0) 4790Sstevel@tonic-gate return; 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate *fpstack++ = (uint64_t)rp->r_sp; 4820Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_o7; 4830Sstevel@tonic-gate pcstack_limit--; 4840Sstevel@tonic-gate } else { 4850Sstevel@tonic-gate *fpstack++ = (uint64_t)rp->r_sp; 4860Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_pc; 4870Sstevel@tonic-gate pcstack_limit--; 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate if (pcstack_limit <= 0) 4910Sstevel@tonic-gate return; 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate sp = rp->r_sp; 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate dtrace_flush_user_windows(); 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate if (p->p_model == DATAMODEL_NATIVE) { 4980Sstevel@tonic-gate while (pcstack_limit > 0) { 4990Sstevel@tonic-gate struct frame *fr = (struct frame *)(sp + STACK_BIAS); 5000Sstevel@tonic-gate uintptr_t pc; 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate if (sp == 0 || fr == NULL || 5030Sstevel@tonic-gate ((uintptr_t)&fr->fr_savpc & 3) != 0 || 5040Sstevel@tonic-gate ((uintptr_t)&fr->fr_savfp & 3) != 0) 5050Sstevel@tonic-gate break; 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate pc = dtrace_fulword(&fr->fr_savpc); 5080Sstevel@tonic-gate sp = dtrace_fulword(&fr->fr_savfp); 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate if (pc == 0) 5110Sstevel@tonic-gate break; 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate *fpstack++ = sp; 5140Sstevel@tonic-gate *pcstack++ = pc; 5150Sstevel@tonic-gate pcstack_limit--; 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate } else { 5180Sstevel@tonic-gate while (pcstack_limit > 0) { 5190Sstevel@tonic-gate struct frame32 *fr = (struct frame32 *)sp; 5200Sstevel@tonic-gate uint32_t pc; 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate if (sp == 0 || 5230Sstevel@tonic-gate ((uintptr_t)&fr->fr_savpc & 3) != 0 || 5240Sstevel@tonic-gate ((uintptr_t)&fr->fr_savfp & 3) != 0) 5250Sstevel@tonic-gate break; 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate pc = dtrace_fuword32(&fr->fr_savpc); 5280Sstevel@tonic-gate sp = dtrace_fuword32(&fr->fr_savfp); 5290Sstevel@tonic-gate 530*191Sahl if (pc == 0) 531*191Sahl break; 532*191Sahl 5330Sstevel@tonic-gate *fpstack++ = sp; 5340Sstevel@tonic-gate *pcstack++ = pc; 5350Sstevel@tonic-gate pcstack_limit--; 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate while (pcstack_limit-- > 0) 5400Sstevel@tonic-gate *pcstack++ = NULL; 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate uint64_t 5440Sstevel@tonic-gate dtrace_getarg(int arg, int aframes) 5450Sstevel@tonic-gate { 5460Sstevel@tonic-gate uintptr_t val; 5470Sstevel@tonic-gate struct frame *fp; 5480Sstevel@tonic-gate uint64_t rval; 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate /* 5510Sstevel@tonic-gate * Account for the fact that dtrace_getarg() consumes an additional 5520Sstevel@tonic-gate * stack frame. 5530Sstevel@tonic-gate */ 5540Sstevel@tonic-gate aframes++; 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate if (arg < 6) { 5570Sstevel@tonic-gate if (dtrace_fish(aframes, DTRACE_REG_I0 + arg, &val) == 0) 5580Sstevel@tonic-gate return (val); 5590Sstevel@tonic-gate } else { 5600Sstevel@tonic-gate if (dtrace_fish(aframes, DTRACE_REG_I6, &val) == 0) { 5610Sstevel@tonic-gate /* 5620Sstevel@tonic-gate * We have a stack pointer; grab the argument. 5630Sstevel@tonic-gate */ 5640Sstevel@tonic-gate fp = (struct frame *)(val + STACK_BIAS); 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 5670Sstevel@tonic-gate rval = fp->fr_argx[arg - 6]; 5680Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate return (rval); 5710Sstevel@tonic-gate } 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate /* 5750Sstevel@tonic-gate * There are other ways to do this. But the slow, painful way works 5760Sstevel@tonic-gate * just fine. Because this requires some loads, we need to set 5770Sstevel@tonic-gate * CPU_DTRACE_NOFAULT to protect against looking for an argument that 5780Sstevel@tonic-gate * isn't there. 5790Sstevel@tonic-gate */ 5800Sstevel@tonic-gate fp = (struct frame *)((caddr_t)dtrace_getfp() + STACK_BIAS); 5810Sstevel@tonic-gate dtrace_flush_windows(); 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate for (aframes -= 1; aframes; aframes--) 5860Sstevel@tonic-gate fp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate if (arg < 6) { 5890Sstevel@tonic-gate rval = fp->fr_arg[arg]; 5900Sstevel@tonic-gate } else { 5910Sstevel@tonic-gate fp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 5920Sstevel@tonic-gate rval = fp->fr_argx[arg - 6]; 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate return (rval); 5980Sstevel@tonic-gate } 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate int 6010Sstevel@tonic-gate dtrace_getstackdepth(int aframes) 6020Sstevel@tonic-gate { 6030Sstevel@tonic-gate struct frame *fp, *nextfp, *minfp, *stacktop; 6040Sstevel@tonic-gate int depth = 0; 6050Sstevel@tonic-gate int on_intr; 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate fp = (struct frame *)((caddr_t)dtrace_getfp() + STACK_BIAS); 6080Sstevel@tonic-gate dtrace_flush_windows(); 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate if ((on_intr = CPU_ON_INTR(CPU)) != 0) 6110Sstevel@tonic-gate stacktop = (struct frame *)CPU->cpu_intr_stack + SA(MINFRAME); 6120Sstevel@tonic-gate else 6130Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 6140Sstevel@tonic-gate minfp = fp; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate for (;;) { 6170Sstevel@tonic-gate nextfp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 6180Sstevel@tonic-gate if (nextfp <= minfp || nextfp >= stacktop) { 6190Sstevel@tonic-gate if (on_intr) { 6200Sstevel@tonic-gate /* 6210Sstevel@tonic-gate * Hop from interrupt stack to thread stack. 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 6240Sstevel@tonic-gate minfp = (struct frame *)curthread->t_stkbase; 6250Sstevel@tonic-gate on_intr = 0; 6260Sstevel@tonic-gate continue; 6270Sstevel@tonic-gate } 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate return (++depth); 6300Sstevel@tonic-gate } 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate if (aframes > 0) { 6330Sstevel@tonic-gate aframes--; 6340Sstevel@tonic-gate } else { 6350Sstevel@tonic-gate depth++; 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate fp = nextfp; 6390Sstevel@tonic-gate minfp = fp; 6400Sstevel@tonic-gate } 6410Sstevel@tonic-gate } 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate /* 6440Sstevel@tonic-gate * This uses the same register numbering scheme as in sys/procfs_isa.h. 6450Sstevel@tonic-gate */ 6460Sstevel@tonic-gate ulong_t 6470Sstevel@tonic-gate dtrace_getreg(struct regs *rp, uint_t reg) 6480Sstevel@tonic-gate { 6490Sstevel@tonic-gate ulong_t value; 6500Sstevel@tonic-gate uintptr_t fp; 6510Sstevel@tonic-gate struct machpcb *mpcb; 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate if (reg == R_G0) 6540Sstevel@tonic-gate return (0); 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate if (reg <= R_G7) 6570Sstevel@tonic-gate return ((&rp->r_g1)[reg - 1]); 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate if (reg > R_I7) { 6600Sstevel@tonic-gate switch (reg) { 6610Sstevel@tonic-gate case R_CCR: 6620Sstevel@tonic-gate return ((rp->r_tstate >> TSTATE_CCR_SHIFT) & 6630Sstevel@tonic-gate TSTATE_CCR_MASK); 6640Sstevel@tonic-gate case R_PC: 6650Sstevel@tonic-gate return (rp->r_pc); 6660Sstevel@tonic-gate case R_nPC: 6670Sstevel@tonic-gate return (rp->r_npc); 6680Sstevel@tonic-gate case R_Y: 6690Sstevel@tonic-gate return (rp->r_y); 6700Sstevel@tonic-gate case R_ASI: 6710Sstevel@tonic-gate return ((rp->r_tstate >> TSTATE_ASI_SHIFT) & 6720Sstevel@tonic-gate TSTATE_ASI_MASK); 6730Sstevel@tonic-gate case R_FPRS: 6740Sstevel@tonic-gate return (dtrace_getfprs()); 6750Sstevel@tonic-gate default: 6760Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP); 6770Sstevel@tonic-gate return (0); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate /* 6820Sstevel@tonic-gate * We reach go to the fake restore case if the probe we hit was a pid 6830Sstevel@tonic-gate * return probe on a restore instruction. We partially emulate the 6840Sstevel@tonic-gate * restore in the kernel and then execute a simple restore 6850Sstevel@tonic-gate * instruction that we've secreted away to do the actual register 6860Sstevel@tonic-gate * window manipulation. We need to go one register window further 6870Sstevel@tonic-gate * down to get at the %ls, and %is and we need to treat %os like %is 6880Sstevel@tonic-gate * to pull them out of the topmost user frame. 6890Sstevel@tonic-gate */ 6900Sstevel@tonic-gate if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAKERESTORE)) { 6910Sstevel@tonic-gate if (reg > R_O7) 6920Sstevel@tonic-gate goto fake_restore; 6930Sstevel@tonic-gate else 6940Sstevel@tonic-gate reg += R_I0 - R_O0; 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate } else if (reg <= R_O7) { 6970Sstevel@tonic-gate return ((&rp->r_g1)[reg - 1]); 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate if (dtrace_getotherwin() > 0) 7010Sstevel@tonic-gate return (dtrace_getreg_win(reg, 1)); 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate mpcb = (struct machpcb *)((caddr_t)rp - REGOFF); 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE) { 7060Sstevel@tonic-gate struct frame *fr = (void *)(rp->r_sp + STACK_BIAS); 7070Sstevel@tonic-gate 7080Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 7090Sstevel@tonic-gate struct rwindow *rwin = (void *)mpcb->mpcb_wbuf; 7100Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 7110Sstevel@tonic-gate do { 7120Sstevel@tonic-gate i--; 7130Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) 7140Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 7150Sstevel@tonic-gate } while (i > 0); 7160Sstevel@tonic-gate } 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 7190Sstevel@tonic-gate value = dtrace_fulword(&fr->fr_local[reg - 16]); 7200Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 7210Sstevel@tonic-gate } else { 7220Sstevel@tonic-gate struct frame32 *fr = (void *)(caddr32_t)rp->r_sp; 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 7250Sstevel@tonic-gate struct rwindow32 *rwin = (void *)mpcb->mpcb_wbuf; 7260Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 7270Sstevel@tonic-gate do { 7280Sstevel@tonic-gate i--; 7290Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) 7300Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 7310Sstevel@tonic-gate } while (i > 0); 7320Sstevel@tonic-gate } 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 7350Sstevel@tonic-gate value = dtrace_fuword32(&fr->fr_local[reg - 16]); 7360Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate return (value); 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate fake_restore: 7420Sstevel@tonic-gate ASSERT(R_L0 <= reg && reg <= R_I7); 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate /* 7450Sstevel@tonic-gate * We first look two user windows down to see if we can dig out 7460Sstevel@tonic-gate * the register we're looking for. 7470Sstevel@tonic-gate */ 7480Sstevel@tonic-gate if (dtrace_getotherwin() > 1) 7490Sstevel@tonic-gate return (dtrace_getreg_win(reg, 2)); 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate /* 7520Sstevel@tonic-gate * First we need to get the frame pointer and then we perform 7530Sstevel@tonic-gate * the same computation as in the non-fake-o-restore case. 7540Sstevel@tonic-gate */ 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate mpcb = (struct machpcb *)((caddr_t)rp - REGOFF); 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate if (dtrace_getotherwin() > 0) { 7590Sstevel@tonic-gate fp = dtrace_getreg_win(R_FP, 1); 7600Sstevel@tonic-gate goto got_fp; 7610Sstevel@tonic-gate } 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE) { 7640Sstevel@tonic-gate struct frame *fr = (void *)(rp->r_sp + STACK_BIAS); 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 7670Sstevel@tonic-gate struct rwindow *rwin = (void *)mpcb->mpcb_wbuf; 7680Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 7690Sstevel@tonic-gate do { 7700Sstevel@tonic-gate i--; 7710Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) { 7720Sstevel@tonic-gate fp = rwin[i].rw_fp; 7730Sstevel@tonic-gate goto got_fp; 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate } while (i > 0); 7760Sstevel@tonic-gate } 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 7790Sstevel@tonic-gate fp = dtrace_fulword(&fr->fr_savfp); 7800Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 7810Sstevel@tonic-gate if (cpu_core[CPU->cpu_id].cpuc_dtrace_flags & CPU_DTRACE_FAULT) 7820Sstevel@tonic-gate return (0); 7830Sstevel@tonic-gate } else { 7840Sstevel@tonic-gate struct frame32 *fr = (void *)(caddr32_t)rp->r_sp; 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 7870Sstevel@tonic-gate struct rwindow32 *rwin = (void *)mpcb->mpcb_wbuf; 7880Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 7890Sstevel@tonic-gate do { 7900Sstevel@tonic-gate i--; 7910Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) { 7920Sstevel@tonic-gate fp = rwin[i].rw_fp; 7930Sstevel@tonic-gate goto got_fp; 7940Sstevel@tonic-gate } 7950Sstevel@tonic-gate } while (i > 0); 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 7990Sstevel@tonic-gate fp = dtrace_fuword32(&fr->fr_savfp); 8000Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 8010Sstevel@tonic-gate if (cpu_core[CPU->cpu_id].cpuc_dtrace_flags & CPU_DTRACE_FAULT) 8020Sstevel@tonic-gate return (0); 8030Sstevel@tonic-gate } 8040Sstevel@tonic-gate got_fp: 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE) { 8070Sstevel@tonic-gate struct frame *fr = (void *)(fp + STACK_BIAS); 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 8100Sstevel@tonic-gate struct rwindow *rwin = (void *)mpcb->mpcb_wbuf; 8110Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 8120Sstevel@tonic-gate do { 8130Sstevel@tonic-gate i--; 8140Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == fp) 8150Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 8160Sstevel@tonic-gate } while (i > 0); 8170Sstevel@tonic-gate } 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 8200Sstevel@tonic-gate value = dtrace_fulword(&fr->fr_local[reg - 16]); 8210Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 8220Sstevel@tonic-gate } else { 8230Sstevel@tonic-gate struct frame32 *fr = (void *)(caddr32_t)fp; 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 8260Sstevel@tonic-gate struct rwindow32 *rwin = (void *)mpcb->mpcb_wbuf; 8270Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 8280Sstevel@tonic-gate do { 8290Sstevel@tonic-gate i--; 8300Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == fp) 8310Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 8320Sstevel@tonic-gate } while (i > 0); 8330Sstevel@tonic-gate } 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 8360Sstevel@tonic-gate value = dtrace_fuword32(&fr->fr_local[reg - 16]); 8370Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 8380Sstevel@tonic-gate } 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate return (value); 8410Sstevel@tonic-gate } 842