1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/dtrace_impl.h> 30*0Sstevel@tonic-gate #include <sys/atomic.h> 31*0Sstevel@tonic-gate #include <sys/model.h> 32*0Sstevel@tonic-gate #include <sys/frame.h> 33*0Sstevel@tonic-gate #include <sys/stack.h> 34*0Sstevel@tonic-gate #include <sys/machpcb.h> 35*0Sstevel@tonic-gate #include <sys/procfs_isa.h> 36*0Sstevel@tonic-gate #include <sys/cmn_err.h> 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #define DTRACE_FMT3OP3_MASK 0x81000000 39*0Sstevel@tonic-gate #define DTRACE_FMT3OP3 0x80000000 40*0Sstevel@tonic-gate #define DTRACE_FMT3RS1_SHIFT 14 41*0Sstevel@tonic-gate #define DTRACE_FMT3RD_SHIFT 25 42*0Sstevel@tonic-gate #define DTRACE_RMASK 0x1f 43*0Sstevel@tonic-gate #define DTRACE_REG_L0 16 44*0Sstevel@tonic-gate #define DTRACE_REG_O7 15 45*0Sstevel@tonic-gate #define DTRACE_REG_I0 24 46*0Sstevel@tonic-gate #define DTRACE_REG_I6 30 47*0Sstevel@tonic-gate #define DTRACE_RET 0x81c7e008 48*0Sstevel@tonic-gate #define DTRACE_RETL 0x81c3e008 49*0Sstevel@tonic-gate #define DTRACE_SAVE_MASK 0xc1f80000 50*0Sstevel@tonic-gate #define DTRACE_SAVE 0x81e00000 51*0Sstevel@tonic-gate #define DTRACE_RESTORE 0x81e80000 52*0Sstevel@tonic-gate #define DTRACE_CALL_MASK 0xc0000000 53*0Sstevel@tonic-gate #define DTRACE_CALL 0x40000000 54*0Sstevel@tonic-gate #define DTRACE_JMPL_MASK 0x81f10000 55*0Sstevel@tonic-gate #define DTRACE_JMPL 0x81c00000 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate extern int dtrace_getupcstack_top(uint64_t *, int, uintptr_t *); 58*0Sstevel@tonic-gate extern ulong_t dtrace_getreg_win(uint_t, uint_t); 59*0Sstevel@tonic-gate extern void dtrace_putreg_win(uint_t, ulong_t); 60*0Sstevel@tonic-gate extern int dtrace_fish(int, int, uintptr_t *); 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate /* 63*0Sstevel@tonic-gate * This is similar in principle to getpcstack(), but there are several marked 64*0Sstevel@tonic-gate * differences in implementation: 65*0Sstevel@tonic-gate * 66*0Sstevel@tonic-gate * (a) dtrace_getpcstack() is called from probe context. Thus, the call 67*0Sstevel@tonic-gate * to flush_windows() from getpcstack() is a call to the probe-safe 68*0Sstevel@tonic-gate * equivalent here. 69*0Sstevel@tonic-gate * 70*0Sstevel@tonic-gate * (b) dtrace_getpcstack() is willing to sacrifice some performance to get 71*0Sstevel@tonic-gate * a correct stack. While consumers of getpcstack() are largely 72*0Sstevel@tonic-gate * subsystem-specific in-kernel debugging facilities, DTrace consumers 73*0Sstevel@tonic-gate * are arbitrary user-level analysis tools; dtrace_getpcstack() must 74*0Sstevel@tonic-gate * deliver as correct a stack as possible. Details on the issues 75*0Sstevel@tonic-gate * surrounding stack correctness are found below. 76*0Sstevel@tonic-gate * 77*0Sstevel@tonic-gate * (c) dtrace_getpcstack() _always_ fills in pstack_limit pc_t's -- filling 78*0Sstevel@tonic-gate * in the difference between the stack depth and pstack_limit with NULLs. 79*0Sstevel@tonic-gate * Due to this behavior dtrace_getpcstack() returns void. 80*0Sstevel@tonic-gate * 81*0Sstevel@tonic-gate * (d) dtrace_getpcstack() takes a third parameter, aframes, that 82*0Sstevel@tonic-gate * denotes the number of _artificial frames_ on the bottom of the 83*0Sstevel@tonic-gate * stack. An artificial frame is one induced by the provider; all 84*0Sstevel@tonic-gate * artificial frames are stripped off before frames are stored to 85*0Sstevel@tonic-gate * pcstack. 86*0Sstevel@tonic-gate * 87*0Sstevel@tonic-gate * (e) dtrace_getpcstack() takes a fourth parameter, pc, that indicates 88*0Sstevel@tonic-gate * an interrupted program counter (if any). This should be a non-NULL 89*0Sstevel@tonic-gate * value if and only if the hit probe is unanchored. (Anchored probes 90*0Sstevel@tonic-gate * don't fire through an interrupt source.) This parameter is used to 91*0Sstevel@tonic-gate * assure (b), above. 92*0Sstevel@tonic-gate */ 93*0Sstevel@tonic-gate void 94*0Sstevel@tonic-gate dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, uint32_t *pc) 95*0Sstevel@tonic-gate { 96*0Sstevel@tonic-gate struct frame *fp, *nextfp, *minfp, *stacktop; 97*0Sstevel@tonic-gate int depth = 0; 98*0Sstevel@tonic-gate int on_intr, j = 0; 99*0Sstevel@tonic-gate uint32_t i, r; 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate fp = (struct frame *)((caddr_t)dtrace_getfp() + STACK_BIAS); 102*0Sstevel@tonic-gate dtrace_flush_windows(); 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate if (pc != NULL) { 105*0Sstevel@tonic-gate /* 106*0Sstevel@tonic-gate * If we've been passed a non-NULL pc, we need to determine 107*0Sstevel@tonic-gate * whether or not the specified program counter falls in a leaf 108*0Sstevel@tonic-gate * function. If it falls within a leaf function, we know that 109*0Sstevel@tonic-gate * %o7 is valid in its frame (and we can just drive on). If 110*0Sstevel@tonic-gate * it's a non-leaf, however, we know that %o7 is garbage in the 111*0Sstevel@tonic-gate * bottom frame. To trim this frame, we simply increment 112*0Sstevel@tonic-gate * aframes and drop into the stack-walking loop. 113*0Sstevel@tonic-gate * 114*0Sstevel@tonic-gate * To quickly determine if the specified program counter is in 115*0Sstevel@tonic-gate * a leaf function, we exploit the fact that leaf functions 116*0Sstevel@tonic-gate * tend to be short and non-leaf functions tend to frequently 117*0Sstevel@tonic-gate * perform operations that are only permitted in a non-leaf 118*0Sstevel@tonic-gate * function (e.g., using the %i's or %l's; calling a function; 119*0Sstevel@tonic-gate * performing a restore). We exploit these tendencies by 120*0Sstevel@tonic-gate * simply scanning forward from the specified %pc -- if we see 121*0Sstevel@tonic-gate * an operation only permitted in a non-leaf, we know we're in 122*0Sstevel@tonic-gate * a non-leaf; if we see a retl, we know we're in a leaf. 123*0Sstevel@tonic-gate * Fortunately, one need not perform anywhere near full 124*0Sstevel@tonic-gate * disassembly to effectively determine the former: determining 125*0Sstevel@tonic-gate * that an instruction is a format-3 instruction and decoding 126*0Sstevel@tonic-gate * its rd and rs1 fields, for example, requires very little 127*0Sstevel@tonic-gate * manipulation. Overall, this method of leaf determination 128*0Sstevel@tonic-gate * performs quite well: on average, we only examine between 129*0Sstevel@tonic-gate * 1.5 and 2.5 instructions before making the determination. 130*0Sstevel@tonic-gate * (Outliers do exist, however; of note is the non-leaf 131*0Sstevel@tonic-gate * function ip_sioctl_not_ours() which -- as of this writing -- 132*0Sstevel@tonic-gate * has a whopping 455 straight instructions that manipulate 133*0Sstevel@tonic-gate * only %g's and %o's.) 134*0Sstevel@tonic-gate */ 135*0Sstevel@tonic-gate int delay = 0; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate if (depth < pcstack_limit) 138*0Sstevel@tonic-gate pcstack[depth++] = (pc_t)pc; 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate for (;;) { 141*0Sstevel@tonic-gate i = pc[j++]; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate if ((i & DTRACE_FMT3OP3_MASK) == DTRACE_FMT3OP3) { 144*0Sstevel@tonic-gate /* 145*0Sstevel@tonic-gate * This is a format-3 instruction. We can 146*0Sstevel@tonic-gate * look at rd and rs1. 147*0Sstevel@tonic-gate */ 148*0Sstevel@tonic-gate r = (i >> DTRACE_FMT3RS1_SHIFT) & DTRACE_RMASK; 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate if (r >= DTRACE_REG_L0) 151*0Sstevel@tonic-gate goto nonleaf; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate r = (i >> DTRACE_FMT3RD_SHIFT) & DTRACE_RMASK; 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate if (r >= DTRACE_REG_L0) 156*0Sstevel@tonic-gate goto nonleaf; 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate if ((i & DTRACE_JMPL_MASK) == DTRACE_JMPL) { 159*0Sstevel@tonic-gate delay = 1; 160*0Sstevel@tonic-gate continue; 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate /* 164*0Sstevel@tonic-gate * If we see explicit manipulation with %o7 165*0Sstevel@tonic-gate * as a destination register, we know that 166*0Sstevel@tonic-gate * %o7 is likely bogus -- and we treat this 167*0Sstevel@tonic-gate * function as a non-leaf. 168*0Sstevel@tonic-gate */ 169*0Sstevel@tonic-gate if (r == DTRACE_REG_O7) { 170*0Sstevel@tonic-gate if (delay) 171*0Sstevel@tonic-gate goto leaf; 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate i &= DTRACE_JMPL_MASK; 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate if (i == DTRACE_JMPL) { 176*0Sstevel@tonic-gate delay = 1; 177*0Sstevel@tonic-gate continue; 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate goto nonleaf; 181*0Sstevel@tonic-gate } 182*0Sstevel@tonic-gate } else { 183*0Sstevel@tonic-gate /* 184*0Sstevel@tonic-gate * If this is a call, it may or may not be 185*0Sstevel@tonic-gate * a leaf; we need to check the delay slot. 186*0Sstevel@tonic-gate */ 187*0Sstevel@tonic-gate if ((i & DTRACE_CALL_MASK) == DTRACE_CALL) { 188*0Sstevel@tonic-gate delay = 1; 189*0Sstevel@tonic-gate continue; 190*0Sstevel@tonic-gate } 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate /* 193*0Sstevel@tonic-gate * If we see a ret it's not a leaf; if we 194*0Sstevel@tonic-gate * see a retl, it is a leaf. 195*0Sstevel@tonic-gate */ 196*0Sstevel@tonic-gate if (i == DTRACE_RET) 197*0Sstevel@tonic-gate goto nonleaf; 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate if (i == DTRACE_RETL) 200*0Sstevel@tonic-gate goto leaf; 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate /* 203*0Sstevel@tonic-gate * Finally, if it's a save, it should be 204*0Sstevel@tonic-gate * treated as a leaf; if it's a restore it 205*0Sstevel@tonic-gate * should not be treated as a leaf. 206*0Sstevel@tonic-gate */ 207*0Sstevel@tonic-gate if ((i & DTRACE_SAVE_MASK) == DTRACE_SAVE) 208*0Sstevel@tonic-gate goto leaf; 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate if ((i & DTRACE_SAVE_MASK) == DTRACE_RESTORE) 211*0Sstevel@tonic-gate goto nonleaf; 212*0Sstevel@tonic-gate } 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate if (delay) { 215*0Sstevel@tonic-gate /* 216*0Sstevel@tonic-gate * If this was a delay slot instruction and 217*0Sstevel@tonic-gate * we didn't pick it up elsewhere, this is a 218*0Sstevel@tonic-gate * non-leaf. 219*0Sstevel@tonic-gate */ 220*0Sstevel@tonic-gate goto nonleaf; 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate } 223*0Sstevel@tonic-gate nonleaf: 224*0Sstevel@tonic-gate aframes++; 225*0Sstevel@tonic-gate leaf: 226*0Sstevel@tonic-gate ; 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate if ((on_intr = CPU_ON_INTR(CPU)) != 0) 230*0Sstevel@tonic-gate stacktop = (struct frame *)(CPU->cpu_intr_stack + SA(MINFRAME)); 231*0Sstevel@tonic-gate else 232*0Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 233*0Sstevel@tonic-gate minfp = fp; 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate while (depth < pcstack_limit) { 236*0Sstevel@tonic-gate nextfp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 237*0Sstevel@tonic-gate if (nextfp <= minfp || nextfp >= stacktop) { 238*0Sstevel@tonic-gate if (!on_intr && nextfp == stacktop && aframes != 0) { 239*0Sstevel@tonic-gate /* 240*0Sstevel@tonic-gate * If we are exactly at the top of the stack 241*0Sstevel@tonic-gate * with a non-zero number of artificial frames, 242*0Sstevel@tonic-gate * it must be that the stack is filled with 243*0Sstevel@tonic-gate * nothing _but_ artificial frames. In this 244*0Sstevel@tonic-gate * case, we assert that this is so, zero 245*0Sstevel@tonic-gate * pcstack, and return. 246*0Sstevel@tonic-gate */ 247*0Sstevel@tonic-gate ASSERT(aframes == 1); 248*0Sstevel@tonic-gate ASSERT(depth == 0); 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate while (depth < pcstack_limit) 251*0Sstevel@tonic-gate pcstack[depth++] = NULL; 252*0Sstevel@tonic-gate return; 253*0Sstevel@tonic-gate } 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate if (on_intr) { 256*0Sstevel@tonic-gate /* 257*0Sstevel@tonic-gate * Hop from interrupt stack to thread stack. 258*0Sstevel@tonic-gate */ 259*0Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 260*0Sstevel@tonic-gate minfp = (struct frame *)curthread->t_stkbase; 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gate on_intr = 0; 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gate if (nextfp > minfp && nextfp < stacktop) 265*0Sstevel@tonic-gate continue; 266*0Sstevel@tonic-gate } else { 267*0Sstevel@tonic-gate /* 268*0Sstevel@tonic-gate * High-level interrupts may occur when %sp is 269*0Sstevel@tonic-gate * not necessarily contained in the stack 270*0Sstevel@tonic-gate * bounds implied by %g7 -- interrupt thread 271*0Sstevel@tonic-gate * management runs with %pil at DISP_LEVEL, 272*0Sstevel@tonic-gate * and high-level interrupts may thus occur 273*0Sstevel@tonic-gate * in windows when %sp and %g7 are not self- 274*0Sstevel@tonic-gate * consistent. If we call dtrace_getpcstack() 275*0Sstevel@tonic-gate * from a high-level interrupt that has occurred 276*0Sstevel@tonic-gate * in such a window, we will fail the above test 277*0Sstevel@tonic-gate * of nextfp against minfp/stacktop. If the 278*0Sstevel@tonic-gate * high-level interrupt has in turn interrupted 279*0Sstevel@tonic-gate * a non-passivated interrupt thread, we 280*0Sstevel@tonic-gate * will execute the below code with non-zero 281*0Sstevel@tonic-gate * aframes. We therefore want to assert that 282*0Sstevel@tonic-gate * aframes is zero _or_ we are in a high-level 283*0Sstevel@tonic-gate * interrupt -- but because cpu_intr_actv is 284*0Sstevel@tonic-gate * updated with high-level interrupts enabled, 285*0Sstevel@tonic-gate * we must reduce this to only asserting that 286*0Sstevel@tonic-gate * %pil is greater than DISP_LEVEL. 287*0Sstevel@tonic-gate */ 288*0Sstevel@tonic-gate ASSERT(aframes == 0 || 289*0Sstevel@tonic-gate dtrace_getipl() > DISP_LEVEL); 290*0Sstevel@tonic-gate pcstack[depth++] = (pc_t)fp->fr_savpc; 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate while (depth < pcstack_limit) 294*0Sstevel@tonic-gate pcstack[depth++] = NULL; 295*0Sstevel@tonic-gate return; 296*0Sstevel@tonic-gate } 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate if (aframes > 0) { 299*0Sstevel@tonic-gate aframes--; 300*0Sstevel@tonic-gate } else { 301*0Sstevel@tonic-gate pcstack[depth++] = (pc_t)fp->fr_savpc; 302*0Sstevel@tonic-gate } 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate fp = nextfp; 305*0Sstevel@tonic-gate minfp = fp; 306*0Sstevel@tonic-gate } 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate void 310*0Sstevel@tonic-gate dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) 311*0Sstevel@tonic-gate { 312*0Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread); 313*0Sstevel@tonic-gate proc_t *p = ttoproc(curthread); 314*0Sstevel@tonic-gate struct regs *rp; 315*0Sstevel@tonic-gate uintptr_t sp; 316*0Sstevel@tonic-gate int n; 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate if (lwp == NULL || p == NULL || lwp->lwp_regs == NULL) 319*0Sstevel@tonic-gate return; 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gate if (pcstack_limit <= 0) 322*0Sstevel@tonic-gate return; 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate *pcstack++ = (uint64_t)p->p_pid; 325*0Sstevel@tonic-gate pcstack_limit--; 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate if (pcstack_limit <= 0) 328*0Sstevel@tonic-gate return; 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gate rp = lwp->lwp_regs; 331*0Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_pc; 332*0Sstevel@tonic-gate pcstack_limit--; 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate if (pcstack_limit <= 0) 335*0Sstevel@tonic-gate return; 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gate if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { 338*0Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_o7; 339*0Sstevel@tonic-gate pcstack_limit--; 340*0Sstevel@tonic-gate if (pcstack_limit <= 0) 341*0Sstevel@tonic-gate return; 342*0Sstevel@tonic-gate } 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate sp = rp->r_sp; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate n = dtrace_getupcstack_top(pcstack, pcstack_limit, &sp); 347*0Sstevel@tonic-gate ASSERT(n >= 0); 348*0Sstevel@tonic-gate ASSERT(n <= pcstack_limit); 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate pcstack += n; 351*0Sstevel@tonic-gate pcstack_limit -= n; 352*0Sstevel@tonic-gate 353*0Sstevel@tonic-gate if (p->p_model == DATAMODEL_NATIVE) { 354*0Sstevel@tonic-gate while (pcstack_limit > 0) { 355*0Sstevel@tonic-gate struct frame *fr = (struct frame *)(sp + STACK_BIAS); 356*0Sstevel@tonic-gate uintptr_t pc; 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate if (sp == 0 || fr == NULL || 359*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savpc & 3) != 0 || 360*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savfp & 3) != 0) 361*0Sstevel@tonic-gate break; 362*0Sstevel@tonic-gate 363*0Sstevel@tonic-gate pc = dtrace_fulword(&fr->fr_savpc); 364*0Sstevel@tonic-gate sp = dtrace_fulword(&fr->fr_savfp); 365*0Sstevel@tonic-gate 366*0Sstevel@tonic-gate if (pc == 0) 367*0Sstevel@tonic-gate break; 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate *pcstack++ = pc; 370*0Sstevel@tonic-gate pcstack_limit--; 371*0Sstevel@tonic-gate } 372*0Sstevel@tonic-gate } else { 373*0Sstevel@tonic-gate while (pcstack_limit > 0) { 374*0Sstevel@tonic-gate struct frame32 *fr = (struct frame32 *)sp; 375*0Sstevel@tonic-gate uint32_t pc; 376*0Sstevel@tonic-gate 377*0Sstevel@tonic-gate if (sp == 0 || 378*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savpc & 3) != 0 || 379*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savfp & 3) != 0) 380*0Sstevel@tonic-gate break; 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate pc = dtrace_fuword32(&fr->fr_savpc); 383*0Sstevel@tonic-gate sp = dtrace_fuword32(&fr->fr_savfp); 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate *pcstack++ = pc; 386*0Sstevel@tonic-gate pcstack_limit--; 387*0Sstevel@tonic-gate } 388*0Sstevel@tonic-gate } 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate while (pcstack_limit-- > 0) 391*0Sstevel@tonic-gate *pcstack++ = NULL; 392*0Sstevel@tonic-gate } 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate void 395*0Sstevel@tonic-gate dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack, int pcstack_limit) 396*0Sstevel@tonic-gate { 397*0Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread); 398*0Sstevel@tonic-gate proc_t *p = ttoproc(curthread); 399*0Sstevel@tonic-gate struct regs *rp; 400*0Sstevel@tonic-gate uintptr_t sp; 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gate if (lwp == NULL || p == NULL || lwp->lwp_regs == NULL) 403*0Sstevel@tonic-gate return; 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gate if (pcstack_limit <= 0) 406*0Sstevel@tonic-gate return; 407*0Sstevel@tonic-gate 408*0Sstevel@tonic-gate *pcstack++ = (uint64_t)p->p_pid; 409*0Sstevel@tonic-gate pcstack_limit--; 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate if (pcstack_limit <= 0) 412*0Sstevel@tonic-gate return; 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gate rp = lwp->lwp_regs; 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { 417*0Sstevel@tonic-gate *fpstack++ = 0; 418*0Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_pc; 419*0Sstevel@tonic-gate pcstack_limit--; 420*0Sstevel@tonic-gate if (pcstack_limit <= 0) 421*0Sstevel@tonic-gate return; 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate *fpstack++ = (uint64_t)rp->r_sp; 424*0Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_o7; 425*0Sstevel@tonic-gate pcstack_limit--; 426*0Sstevel@tonic-gate } else { 427*0Sstevel@tonic-gate *fpstack++ = (uint64_t)rp->r_sp; 428*0Sstevel@tonic-gate *pcstack++ = (uint64_t)rp->r_pc; 429*0Sstevel@tonic-gate pcstack_limit--; 430*0Sstevel@tonic-gate } 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate if (pcstack_limit <= 0) 433*0Sstevel@tonic-gate return; 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate sp = rp->r_sp; 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate dtrace_flush_user_windows(); 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate if (p->p_model == DATAMODEL_NATIVE) { 440*0Sstevel@tonic-gate while (pcstack_limit > 0) { 441*0Sstevel@tonic-gate struct frame *fr = (struct frame *)(sp + STACK_BIAS); 442*0Sstevel@tonic-gate uintptr_t pc; 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate if (sp == 0 || fr == NULL || 445*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savpc & 3) != 0 || 446*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savfp & 3) != 0) 447*0Sstevel@tonic-gate break; 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate pc = dtrace_fulword(&fr->fr_savpc); 450*0Sstevel@tonic-gate sp = dtrace_fulword(&fr->fr_savfp); 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate if (pc == 0) 453*0Sstevel@tonic-gate break; 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate *fpstack++ = sp; 456*0Sstevel@tonic-gate *pcstack++ = pc; 457*0Sstevel@tonic-gate pcstack_limit--; 458*0Sstevel@tonic-gate } 459*0Sstevel@tonic-gate } else { 460*0Sstevel@tonic-gate while (pcstack_limit > 0) { 461*0Sstevel@tonic-gate struct frame32 *fr = (struct frame32 *)sp; 462*0Sstevel@tonic-gate uint32_t pc; 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate if (sp == 0 || 465*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savpc & 3) != 0 || 466*0Sstevel@tonic-gate ((uintptr_t)&fr->fr_savfp & 3) != 0) 467*0Sstevel@tonic-gate break; 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate pc = dtrace_fuword32(&fr->fr_savpc); 470*0Sstevel@tonic-gate sp = dtrace_fuword32(&fr->fr_savfp); 471*0Sstevel@tonic-gate 472*0Sstevel@tonic-gate *fpstack++ = sp; 473*0Sstevel@tonic-gate *pcstack++ = pc; 474*0Sstevel@tonic-gate pcstack_limit--; 475*0Sstevel@tonic-gate } 476*0Sstevel@tonic-gate } 477*0Sstevel@tonic-gate 478*0Sstevel@tonic-gate while (pcstack_limit-- > 0) 479*0Sstevel@tonic-gate *pcstack++ = NULL; 480*0Sstevel@tonic-gate } 481*0Sstevel@tonic-gate 482*0Sstevel@tonic-gate uint64_t 483*0Sstevel@tonic-gate dtrace_getarg(int arg, int aframes) 484*0Sstevel@tonic-gate { 485*0Sstevel@tonic-gate uintptr_t val; 486*0Sstevel@tonic-gate struct frame *fp; 487*0Sstevel@tonic-gate uint64_t rval; 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate /* 490*0Sstevel@tonic-gate * Account for the fact that dtrace_getarg() consumes an additional 491*0Sstevel@tonic-gate * stack frame. 492*0Sstevel@tonic-gate */ 493*0Sstevel@tonic-gate aframes++; 494*0Sstevel@tonic-gate 495*0Sstevel@tonic-gate if (arg < 6) { 496*0Sstevel@tonic-gate if (dtrace_fish(aframes, DTRACE_REG_I0 + arg, &val) == 0) 497*0Sstevel@tonic-gate return (val); 498*0Sstevel@tonic-gate } else { 499*0Sstevel@tonic-gate if (dtrace_fish(aframes, DTRACE_REG_I6, &val) == 0) { 500*0Sstevel@tonic-gate /* 501*0Sstevel@tonic-gate * We have a stack pointer; grab the argument. 502*0Sstevel@tonic-gate */ 503*0Sstevel@tonic-gate fp = (struct frame *)(val + STACK_BIAS); 504*0Sstevel@tonic-gate 505*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 506*0Sstevel@tonic-gate rval = fp->fr_argx[arg - 6]; 507*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 508*0Sstevel@tonic-gate 509*0Sstevel@tonic-gate return (rval); 510*0Sstevel@tonic-gate } 511*0Sstevel@tonic-gate } 512*0Sstevel@tonic-gate 513*0Sstevel@tonic-gate /* 514*0Sstevel@tonic-gate * There are other ways to do this. But the slow, painful way works 515*0Sstevel@tonic-gate * just fine. Because this requires some loads, we need to set 516*0Sstevel@tonic-gate * CPU_DTRACE_NOFAULT to protect against looking for an argument that 517*0Sstevel@tonic-gate * isn't there. 518*0Sstevel@tonic-gate */ 519*0Sstevel@tonic-gate fp = (struct frame *)((caddr_t)dtrace_getfp() + STACK_BIAS); 520*0Sstevel@tonic-gate dtrace_flush_windows(); 521*0Sstevel@tonic-gate 522*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 523*0Sstevel@tonic-gate 524*0Sstevel@tonic-gate for (aframes -= 1; aframes; aframes--) 525*0Sstevel@tonic-gate fp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 526*0Sstevel@tonic-gate 527*0Sstevel@tonic-gate if (arg < 6) { 528*0Sstevel@tonic-gate rval = fp->fr_arg[arg]; 529*0Sstevel@tonic-gate } else { 530*0Sstevel@tonic-gate fp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 531*0Sstevel@tonic-gate rval = fp->fr_argx[arg - 6]; 532*0Sstevel@tonic-gate } 533*0Sstevel@tonic-gate 534*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 535*0Sstevel@tonic-gate 536*0Sstevel@tonic-gate return (rval); 537*0Sstevel@tonic-gate } 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate int 540*0Sstevel@tonic-gate dtrace_getstackdepth(int aframes) 541*0Sstevel@tonic-gate { 542*0Sstevel@tonic-gate struct frame *fp, *nextfp, *minfp, *stacktop; 543*0Sstevel@tonic-gate int depth = 0; 544*0Sstevel@tonic-gate int on_intr; 545*0Sstevel@tonic-gate 546*0Sstevel@tonic-gate fp = (struct frame *)((caddr_t)dtrace_getfp() + STACK_BIAS); 547*0Sstevel@tonic-gate dtrace_flush_windows(); 548*0Sstevel@tonic-gate 549*0Sstevel@tonic-gate if ((on_intr = CPU_ON_INTR(CPU)) != 0) 550*0Sstevel@tonic-gate stacktop = (struct frame *)CPU->cpu_intr_stack + SA(MINFRAME); 551*0Sstevel@tonic-gate else 552*0Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 553*0Sstevel@tonic-gate minfp = fp; 554*0Sstevel@tonic-gate 555*0Sstevel@tonic-gate for (;;) { 556*0Sstevel@tonic-gate nextfp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS); 557*0Sstevel@tonic-gate if (nextfp <= minfp || nextfp >= stacktop) { 558*0Sstevel@tonic-gate if (on_intr) { 559*0Sstevel@tonic-gate /* 560*0Sstevel@tonic-gate * Hop from interrupt stack to thread stack. 561*0Sstevel@tonic-gate */ 562*0Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk; 563*0Sstevel@tonic-gate minfp = (struct frame *)curthread->t_stkbase; 564*0Sstevel@tonic-gate on_intr = 0; 565*0Sstevel@tonic-gate continue; 566*0Sstevel@tonic-gate } 567*0Sstevel@tonic-gate 568*0Sstevel@tonic-gate return (++depth); 569*0Sstevel@tonic-gate } 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate if (aframes > 0) { 572*0Sstevel@tonic-gate aframes--; 573*0Sstevel@tonic-gate } else { 574*0Sstevel@tonic-gate depth++; 575*0Sstevel@tonic-gate } 576*0Sstevel@tonic-gate 577*0Sstevel@tonic-gate fp = nextfp; 578*0Sstevel@tonic-gate minfp = fp; 579*0Sstevel@tonic-gate } 580*0Sstevel@tonic-gate } 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate /* 583*0Sstevel@tonic-gate * This uses the same register numbering scheme as in sys/procfs_isa.h. 584*0Sstevel@tonic-gate */ 585*0Sstevel@tonic-gate ulong_t 586*0Sstevel@tonic-gate dtrace_getreg(struct regs *rp, uint_t reg) 587*0Sstevel@tonic-gate { 588*0Sstevel@tonic-gate ulong_t value; 589*0Sstevel@tonic-gate uintptr_t fp; 590*0Sstevel@tonic-gate struct machpcb *mpcb; 591*0Sstevel@tonic-gate 592*0Sstevel@tonic-gate if (reg == R_G0) 593*0Sstevel@tonic-gate return (0); 594*0Sstevel@tonic-gate 595*0Sstevel@tonic-gate if (reg <= R_G7) 596*0Sstevel@tonic-gate return ((&rp->r_g1)[reg - 1]); 597*0Sstevel@tonic-gate 598*0Sstevel@tonic-gate if (reg > R_I7) { 599*0Sstevel@tonic-gate switch (reg) { 600*0Sstevel@tonic-gate case R_CCR: 601*0Sstevel@tonic-gate return ((rp->r_tstate >> TSTATE_CCR_SHIFT) & 602*0Sstevel@tonic-gate TSTATE_CCR_MASK); 603*0Sstevel@tonic-gate case R_PC: 604*0Sstevel@tonic-gate return (rp->r_pc); 605*0Sstevel@tonic-gate case R_nPC: 606*0Sstevel@tonic-gate return (rp->r_npc); 607*0Sstevel@tonic-gate case R_Y: 608*0Sstevel@tonic-gate return (rp->r_y); 609*0Sstevel@tonic-gate case R_ASI: 610*0Sstevel@tonic-gate return ((rp->r_tstate >> TSTATE_ASI_SHIFT) & 611*0Sstevel@tonic-gate TSTATE_ASI_MASK); 612*0Sstevel@tonic-gate case R_FPRS: 613*0Sstevel@tonic-gate return (dtrace_getfprs()); 614*0Sstevel@tonic-gate default: 615*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP); 616*0Sstevel@tonic-gate return (0); 617*0Sstevel@tonic-gate } 618*0Sstevel@tonic-gate } 619*0Sstevel@tonic-gate 620*0Sstevel@tonic-gate /* 621*0Sstevel@tonic-gate * We reach go to the fake restore case if the probe we hit was a pid 622*0Sstevel@tonic-gate * return probe on a restore instruction. We partially emulate the 623*0Sstevel@tonic-gate * restore in the kernel and then execute a simple restore 624*0Sstevel@tonic-gate * instruction that we've secreted away to do the actual register 625*0Sstevel@tonic-gate * window manipulation. We need to go one register window further 626*0Sstevel@tonic-gate * down to get at the %ls, and %is and we need to treat %os like %is 627*0Sstevel@tonic-gate * to pull them out of the topmost user frame. 628*0Sstevel@tonic-gate */ 629*0Sstevel@tonic-gate if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAKERESTORE)) { 630*0Sstevel@tonic-gate if (reg > R_O7) 631*0Sstevel@tonic-gate goto fake_restore; 632*0Sstevel@tonic-gate else 633*0Sstevel@tonic-gate reg += R_I0 - R_O0; 634*0Sstevel@tonic-gate 635*0Sstevel@tonic-gate } else if (reg <= R_O7) { 636*0Sstevel@tonic-gate return ((&rp->r_g1)[reg - 1]); 637*0Sstevel@tonic-gate } 638*0Sstevel@tonic-gate 639*0Sstevel@tonic-gate if (dtrace_getotherwin() > 0) 640*0Sstevel@tonic-gate return (dtrace_getreg_win(reg, 1)); 641*0Sstevel@tonic-gate 642*0Sstevel@tonic-gate mpcb = (struct machpcb *)((caddr_t)rp - REGOFF); 643*0Sstevel@tonic-gate 644*0Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE) { 645*0Sstevel@tonic-gate struct frame *fr = (void *)(rp->r_sp + STACK_BIAS); 646*0Sstevel@tonic-gate 647*0Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 648*0Sstevel@tonic-gate struct rwindow *rwin = (void *)mpcb->mpcb_wbuf; 649*0Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 650*0Sstevel@tonic-gate do { 651*0Sstevel@tonic-gate i--; 652*0Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) 653*0Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 654*0Sstevel@tonic-gate } while (i > 0); 655*0Sstevel@tonic-gate } 656*0Sstevel@tonic-gate 657*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 658*0Sstevel@tonic-gate value = dtrace_fulword(&fr->fr_local[reg - 16]); 659*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 660*0Sstevel@tonic-gate } else { 661*0Sstevel@tonic-gate struct frame32 *fr = (void *)(caddr32_t)rp->r_sp; 662*0Sstevel@tonic-gate 663*0Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 664*0Sstevel@tonic-gate struct rwindow32 *rwin = (void *)mpcb->mpcb_wbuf; 665*0Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 666*0Sstevel@tonic-gate do { 667*0Sstevel@tonic-gate i--; 668*0Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) 669*0Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 670*0Sstevel@tonic-gate } while (i > 0); 671*0Sstevel@tonic-gate } 672*0Sstevel@tonic-gate 673*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 674*0Sstevel@tonic-gate value = dtrace_fuword32(&fr->fr_local[reg - 16]); 675*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 676*0Sstevel@tonic-gate } 677*0Sstevel@tonic-gate 678*0Sstevel@tonic-gate return (value); 679*0Sstevel@tonic-gate 680*0Sstevel@tonic-gate fake_restore: 681*0Sstevel@tonic-gate ASSERT(R_L0 <= reg && reg <= R_I7); 682*0Sstevel@tonic-gate 683*0Sstevel@tonic-gate /* 684*0Sstevel@tonic-gate * We first look two user windows down to see if we can dig out 685*0Sstevel@tonic-gate * the register we're looking for. 686*0Sstevel@tonic-gate */ 687*0Sstevel@tonic-gate if (dtrace_getotherwin() > 1) 688*0Sstevel@tonic-gate return (dtrace_getreg_win(reg, 2)); 689*0Sstevel@tonic-gate 690*0Sstevel@tonic-gate /* 691*0Sstevel@tonic-gate * First we need to get the frame pointer and then we perform 692*0Sstevel@tonic-gate * the same computation as in the non-fake-o-restore case. 693*0Sstevel@tonic-gate */ 694*0Sstevel@tonic-gate 695*0Sstevel@tonic-gate mpcb = (struct machpcb *)((caddr_t)rp - REGOFF); 696*0Sstevel@tonic-gate 697*0Sstevel@tonic-gate if (dtrace_getotherwin() > 0) { 698*0Sstevel@tonic-gate fp = dtrace_getreg_win(R_FP, 1); 699*0Sstevel@tonic-gate goto got_fp; 700*0Sstevel@tonic-gate } 701*0Sstevel@tonic-gate 702*0Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE) { 703*0Sstevel@tonic-gate struct frame *fr = (void *)(rp->r_sp + STACK_BIAS); 704*0Sstevel@tonic-gate 705*0Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 706*0Sstevel@tonic-gate struct rwindow *rwin = (void *)mpcb->mpcb_wbuf; 707*0Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 708*0Sstevel@tonic-gate do { 709*0Sstevel@tonic-gate i--; 710*0Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) { 711*0Sstevel@tonic-gate fp = rwin[i].rw_fp; 712*0Sstevel@tonic-gate goto got_fp; 713*0Sstevel@tonic-gate } 714*0Sstevel@tonic-gate } while (i > 0); 715*0Sstevel@tonic-gate } 716*0Sstevel@tonic-gate 717*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 718*0Sstevel@tonic-gate fp = dtrace_fulword(&fr->fr_savfp); 719*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 720*0Sstevel@tonic-gate if (cpu_core[CPU->cpu_id].cpuc_dtrace_flags & CPU_DTRACE_FAULT) 721*0Sstevel@tonic-gate return (0); 722*0Sstevel@tonic-gate } else { 723*0Sstevel@tonic-gate struct frame32 *fr = (void *)(caddr32_t)rp->r_sp; 724*0Sstevel@tonic-gate 725*0Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 726*0Sstevel@tonic-gate struct rwindow32 *rwin = (void *)mpcb->mpcb_wbuf; 727*0Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 728*0Sstevel@tonic-gate do { 729*0Sstevel@tonic-gate i--; 730*0Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == rp->r_sp) { 731*0Sstevel@tonic-gate fp = rwin[i].rw_fp; 732*0Sstevel@tonic-gate goto got_fp; 733*0Sstevel@tonic-gate } 734*0Sstevel@tonic-gate } while (i > 0); 735*0Sstevel@tonic-gate } 736*0Sstevel@tonic-gate 737*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 738*0Sstevel@tonic-gate fp = dtrace_fuword32(&fr->fr_savfp); 739*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 740*0Sstevel@tonic-gate if (cpu_core[CPU->cpu_id].cpuc_dtrace_flags & CPU_DTRACE_FAULT) 741*0Sstevel@tonic-gate return (0); 742*0Sstevel@tonic-gate } 743*0Sstevel@tonic-gate got_fp: 744*0Sstevel@tonic-gate 745*0Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE) { 746*0Sstevel@tonic-gate struct frame *fr = (void *)(fp + STACK_BIAS); 747*0Sstevel@tonic-gate 748*0Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 749*0Sstevel@tonic-gate struct rwindow *rwin = (void *)mpcb->mpcb_wbuf; 750*0Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 751*0Sstevel@tonic-gate do { 752*0Sstevel@tonic-gate i--; 753*0Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == fp) 754*0Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 755*0Sstevel@tonic-gate } while (i > 0); 756*0Sstevel@tonic-gate } 757*0Sstevel@tonic-gate 758*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 759*0Sstevel@tonic-gate value = dtrace_fulword(&fr->fr_local[reg - 16]); 760*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 761*0Sstevel@tonic-gate } else { 762*0Sstevel@tonic-gate struct frame32 *fr = (void *)(caddr32_t)fp; 763*0Sstevel@tonic-gate 764*0Sstevel@tonic-gate if (mpcb->mpcb_wbcnt > 0) { 765*0Sstevel@tonic-gate struct rwindow32 *rwin = (void *)mpcb->mpcb_wbuf; 766*0Sstevel@tonic-gate int i = mpcb->mpcb_wbcnt; 767*0Sstevel@tonic-gate do { 768*0Sstevel@tonic-gate i--; 769*0Sstevel@tonic-gate if ((long)mpcb->mpcb_spbuf[i] == fp) 770*0Sstevel@tonic-gate return (rwin[i].rw_local[reg - 16]); 771*0Sstevel@tonic-gate } while (i > 0); 772*0Sstevel@tonic-gate } 773*0Sstevel@tonic-gate 774*0Sstevel@tonic-gate DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); 775*0Sstevel@tonic-gate value = dtrace_fuword32(&fr->fr_local[reg - 16]); 776*0Sstevel@tonic-gate DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); 777*0Sstevel@tonic-gate } 778*0Sstevel@tonic-gate 779*0Sstevel@tonic-gate return (value); 780*0Sstevel@tonic-gate } 781