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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <sys/param.h>
35 #include <sys/cmn_err.h>
36 #include <sys/archsystm.h>
37 #include <sys/copyops.h>
38 #include <vm/seg_enum.h>
39 #include <sys/privregs.h>
41 #include <dis_tables.h>
44 * This subsystem (with the minor exception of the instr_size() function) is
45 * is called from DTrace probe context. This imposes several requirements on
48 * 1. External subsystems and functions may not be referenced. The one current
49 * exception is for cmn_err, but only to signal the detection of table
50 * errors. Assuming the tables are correct, no combination of input is to
51 * trigger a cmn_err call.
53 * 2. These functions can't be allowed to be traced. To prevent this,
54 * all functions in the probe path (everything except instr_size()) must
55 * have names that begin with "dtrace_".
58 typedef enum dis_isize
{
65 * get a byte from instruction stream
68 dtrace_dis_get_byte(void *p
)
80 * Returns either the size of a given instruction, in bytes, or the size of that
81 * instruction's memory access (if any), depending on the value of `which'.
82 * If a programming error in the tables is detected, the system will panic to
83 * ease diagnosis. Invalid instructions will not be flagged. They will appear
84 * to have an instruction size between 1 and the actual size, and will be
85 * reported as having no memory impact.
89 dtrace_dis_isize(uchar_t
*instr
, dis_isize_t which
, model_t model
, int *rmindex
)
95 mode
= (model
== DATAMODEL_LP64
) ? SIZE64
: SIZE32
;
97 x
.d86_data
= (void **)&instr
;
98 x
.d86_get_byte
= dtrace_dis_get_byte
;
99 x
.d86_check_func
= NULL
;
101 if (dtrace_disx86(&x
, mode
) != 0)
104 if (which
== DIS_ISIZE_INSTR
)
105 sz
= x
.d86_len
; /* length of the instruction */
107 sz
= x
.d86_memsize
; /* length of memory operand */
110 *rmindex
= x
.d86_rmindex
;
115 dtrace_instr_size_isa(uchar_t
*instr
, model_t model
, int *rmindex
)
117 return (dtrace_dis_isize(instr
, DIS_ISIZE_INSTR
, model
, rmindex
));
121 dtrace_instr_size(uchar_t
*instr
)
123 return (dtrace_dis_isize(instr
, DIS_ISIZE_INSTR
, DATAMODEL_NATIVE
,
129 instr_size(struct regs
*rp
, caddr_t
*addrp
, enum seg_rw rw
)
131 uchar_t instr
[16]; /* maximum size instruction */
132 caddr_t pc
= (caddr_t
)rp
->r_pc
;
134 (void) copyin_nowatch(pc
, (caddr_t
)instr
, sizeof (instr
));
136 return (dtrace_dis_isize(instr
,
137 rw
== S_EXEC
? DIS_ISIZE_INSTR
: DIS_ISIZE_OPERAND
,
138 curproc
->p_model
, NULL
));