9597 Want hypervisor API for FPU management
[unleashed.git] / usr / src / uts / i86pc / os / instr_size.c
blob97423b47348b56718662a47f515ecd2fbdc3a3dd
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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"
33 #include <sys/proc.h>
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
46 * the implementation:
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 {
59 DIS_ISIZE_INSTR,
60 DIS_ISIZE_OPERAND
61 } dis_isize_t;
65 * get a byte from instruction stream
67 static int
68 dtrace_dis_get_byte(void *p)
70 int ret;
71 uchar_t **instr = p;
73 ret = **instr;
74 *instr += 1;
76 return (ret);
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.
87 /* ARGSUSED2 */
88 static int
89 dtrace_dis_isize(uchar_t *instr, dis_isize_t which, model_t model, int *rmindex)
91 int sz;
92 dis86_t x;
93 uint_t mode = SIZE32;
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)
102 return (-1);
104 if (which == DIS_ISIZE_INSTR)
105 sz = x.d86_len; /* length of the instruction */
106 else
107 sz = x.d86_memsize; /* length of memory operand */
109 if (rmindex != NULL)
110 *rmindex = x.d86_rmindex;
111 return (sz);
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,
124 NULL));
127 /*ARGSUSED*/
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));