4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
22 * Portions Copyright 2013 Justin Hibbits jhibbits@freebsd.org
23 * Portions Copyright 2013 Howard Su howardsu@freebsd.org
24 * Portions Copyright 2015-2016 Ruslan Bukin <br@bsdpad.com>
30 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
31 * Use is subject to license terms.
34 #include <sys/cdefs.h>
35 #include <sys/param.h>
36 #include <sys/dtrace.h>
38 #include <machine/cpuregs.h>
39 #include <machine/cache.h>
43 #define FBT_PATCHVAL (MIPS_BREAK_INSTR)
44 #define FBT_ENTRY "entry"
45 #define FBT_RETURN "return"
48 fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t rval)
53 cpu = &solaris_cpu[curcpu];
54 fbt = fbt_probetab[FBT_ADDR2NDX(addr)];
56 for (; fbt != NULL; fbt = fbt->fbtp_hashnext) {
57 if ((uintptr_t)fbt->fbtp_patchpoint == addr) {
58 cpu->cpu_dtrace_caller = addr;
60 dtrace_probe(fbt->fbtp_id, frame->a0,
62 frame->a3, frame->a4);
64 cpu->cpu_dtrace_caller = 0;
65 return (fbt->fbtp_savedval);
73 fbt_patch_tracepoint(fbt_probe_t *fbt, fbt_patchval_t val)
76 *fbt->fbtp_patchpoint = val;
77 mips_icache_sync_range((vm_offset_t)fbt->fbtp_patchpoint, 4);
81 fbt_provide_module_function(linker_file_t lf, int symindx,
82 linker_symval_t *symval, void *opaque)
84 fbt_probe_t *fbt, *retfbt;
85 uint32_t *instr, *limit;
92 /* Check if function is excluded from instrumentation */
93 if (fbt_excluded(name))
96 instr = (uint32_t *)(symval->value);
97 limit = (uint32_t *)(symval->value + symval->size);
99 /* Look for store double to ra register */
100 for (; instr < limit; instr++) {
101 if ((*instr & LDSD_RA_SP_MASK) == SD_RA_SP)
108 fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO);
109 fbt->fbtp_name = name;
110 fbt->fbtp_id = dtrace_probe_create(fbt_id, modname,
111 name, FBT_ENTRY, 3, fbt);
112 fbt->fbtp_patchpoint = instr;
114 fbt->fbtp_loadcnt = lf->loadcnt;
115 fbt->fbtp_savedval = *instr;
116 fbt->fbtp_patchval = FBT_PATCHVAL;
117 fbt->fbtp_rval = DTRACE_INVOP_SD;
118 fbt->fbtp_symindx = symindx;
120 fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
121 fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;
127 for (; instr < limit; instr++) {
128 if ((*instr & LDSD_RA_SP_MASK) == LD_RA_SP) {
139 fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO);
140 fbt->fbtp_name = name;
141 if (retfbt == NULL) {
142 fbt->fbtp_id = dtrace_probe_create(fbt_id, modname,
143 name, FBT_RETURN, 3, fbt);
145 retfbt->fbtp_probenext = fbt;
146 fbt->fbtp_id = retfbt->fbtp_id;
150 fbt->fbtp_patchpoint = instr;
152 fbt->fbtp_loadcnt = lf->loadcnt;
153 fbt->fbtp_symindx = symindx;
154 fbt->fbtp_rval = DTRACE_INVOP_LD;
155 fbt->fbtp_savedval = *instr;
156 fbt->fbtp_patchval = FBT_PATCHVAL;
157 fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
158 fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;