4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/types.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
40 #include <sys/dtrace_impl.h>
41 #include <sys/dtrace_bsd.h>
42 #include <machine/clock.h>
43 #include <machine/frame.h>
44 #include <machine/trap.h>
47 #define DELAYBRANCH(x) ((int)(x) < 0)
49 extern uintptr_t dtrace_in_probe_addr;
50 extern int dtrace_in_probe;
51 extern dtrace_id_t dtrace_probeid_error;
53 int dtrace_invop(uintptr_t, uintptr_t *, uintptr_t);
55 typedef struct dtrace_invop_hdlr {
56 int (*dtih_func)(uintptr_t, uintptr_t *, uintptr_t);
57 struct dtrace_invop_hdlr *dtih_next;
58 } dtrace_invop_hdlr_t;
60 dtrace_invop_hdlr_t *dtrace_invop_hdlr;
63 dtrace_invop(uintptr_t addr, uintptr_t *stack, uintptr_t eax)
65 dtrace_invop_hdlr_t *hdlr;
68 for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next)
69 if ((rval = hdlr->dtih_func(addr, stack, eax)) != 0)
78 dtrace_toxic_ranges(void (*func)(uintptr_t base, uintptr_t limit))
86 dtrace_xcall(processorid_t cpu, dtrace_xcall_t func, void *arg)
90 if (cpu == DTRACE_CPUALL)
93 CPU_SETOF(cpu, &cpus);
95 smp_rendezvous_cpus(cpus, smp_no_rendevous_barrier, func,
96 smp_no_rendevous_barrier, arg);
100 dtrace_sync_func(void)
107 dtrace_xcall(DTRACE_CPUALL, (dtrace_xcall_t)dtrace_sync_func, NULL);
111 * DTrace needs a high resolution time function which can
112 * be called from a probe context and guaranteed not to have
113 * instrumented with probes itself.
115 * Returns nanoseconds since boot.
120 struct timespec curtime;
122 nanouptime(&curtime);
124 return (curtime.tv_sec * 1000000000UL + curtime.tv_nsec);
129 dtrace_gethrestime(void)
131 struct timespec curtime;
133 getnanotime(&curtime);
135 return (curtime.tv_sec * 1000000000UL + curtime.tv_nsec);
138 /* Function to handle DTrace traps during probes. See amd64/amd64/trap.c */
140 dtrace_trap(struct trapframe *frame, u_int type)
143 * A trap can occur while DTrace executes a probe. Before
144 * executing the probe, DTrace blocks re-scheduling and sets
145 * a flag in it's per-cpu flags to indicate that it doesn't
146 * want to fault. On returning from the probe, the no-fault
147 * flag is cleared and finally re-scheduling is enabled.
149 * Check if DTrace has enabled 'no-fault' mode:
152 if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) {
154 * There are only a couple of trap types that are expected.
155 * All the rest will be handled in the usual way.
163 case T_BUS_ERR_IFETCH:
164 /* Flag a bad address. */
165 cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR;
166 cpu_core[curcpu].cpuc_dtrace_illval = frame->badvaddr;
169 * Offset the instruction pointer to the instruction
170 * following the one causing the fault.
172 if (DELAYBRANCH(frame->cause)) /* Check BD bit */
174 /* XXX: check MipsEmulateBranch on MIPS64
175 frame->pc = MipsEmulateBranch(frame, frame->pc,
178 panic("%s: delay slot at %jx, badvaddr = %jx\n",
180 (intmax_t)frame->pc, (intmax_t)frame->badvaddr);
183 frame->pc += sizeof(int);
186 /* Handle all other traps in the usual way. */
191 /* Handle the trap in the usual way. */
196 dtrace_probe_error(dtrace_state_t *state, dtrace_epid_t epid, int which,
197 int fault, int fltoffs, uintptr_t illval)
200 dtrace_probe(dtrace_probeid_error, (uint64_t)(uintptr_t)state,
202 (uintptr_t)which, (uintptr_t)fault, (uintptr_t)fltoffs);