2 * Copyright (c) 2013-2019, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include "pt_decoder_function.h"
30 #include "pt_packet_decoder.h"
31 #include "pt_query_decoder.h"
32 #include "pt_opcodes.h"
37 const struct pt_decoder_function pt_decode_unknown = {
38 /* .packet = */ pt_pkt_decode_unknown,
39 /* .decode = */ pt_qry_decode_unknown,
40 /* .header = */ pt_qry_decode_unknown,
41 /* .flags = */ pdff_unknown
44 const struct pt_decoder_function pt_decode_pad = {
45 /* .packet = */ pt_pkt_decode_pad,
46 /* .decode = */ pt_qry_decode_pad,
47 /* .header = */ pt_qry_decode_pad,
48 /* .flags = */ pdff_pad
51 const struct pt_decoder_function pt_decode_psb = {
52 /* .packet = */ pt_pkt_decode_psb,
53 /* .decode = */ pt_qry_decode_psb,
58 const struct pt_decoder_function pt_decode_tip = {
59 /* .packet = */ pt_pkt_decode_tip,
60 /* .decode = */ pt_qry_decode_tip,
62 /* .flags = */ pdff_tip
65 const struct pt_decoder_function pt_decode_tnt_8 = {
66 /* .packet = */ pt_pkt_decode_tnt_8,
67 /* .decode = */ pt_qry_decode_tnt_8,
69 /* .flags = */ pdff_tnt
72 const struct pt_decoder_function pt_decode_tnt_64 = {
73 /* .packet = */ pt_pkt_decode_tnt_64,
74 /* .decode = */ pt_qry_decode_tnt_64,
76 /* .flags = */ pdff_tnt
79 const struct pt_decoder_function pt_decode_tip_pge = {
80 /* .packet = */ pt_pkt_decode_tip_pge,
81 /* .decode = */ pt_qry_decode_tip_pge,
83 /* .flags = */ pdff_event
86 const struct pt_decoder_function pt_decode_tip_pgd = {
87 /* .packet = */ pt_pkt_decode_tip_pgd,
88 /* .decode = */ pt_qry_decode_tip_pgd,
90 /* .flags = */ pdff_event
93 const struct pt_decoder_function pt_decode_fup = {
94 /* .packet = */ pt_pkt_decode_fup,
95 /* .decode = */ pt_qry_decode_fup,
96 /* .header = */ pt_qry_header_fup,
97 /* .flags = */ pdff_fup
100 const struct pt_decoder_function pt_decode_pip = {
101 /* .packet = */ pt_pkt_decode_pip,
102 /* .decode = */ pt_qry_decode_pip,
103 /* .header = */ pt_qry_header_pip,
104 /* .flags = */ pdff_event
107 const struct pt_decoder_function pt_decode_ovf = {
108 /* .packet = */ pt_pkt_decode_ovf,
109 /* .decode = */ pt_qry_decode_ovf,
110 /* .header = */ NULL,
111 /* .flags = */ pdff_psbend | pdff_event
114 const struct pt_decoder_function pt_decode_mode = {
115 /* .packet = */ pt_pkt_decode_mode,
116 /* .decode = */ pt_qry_decode_mode,
117 /* .header = */ pt_qry_header_mode,
118 /* .flags = */ pdff_event
121 const struct pt_decoder_function pt_decode_psbend = {
122 /* .packet = */ pt_pkt_decode_psbend,
123 /* .decode = */ pt_qry_decode_psbend,
124 /* .header = */ NULL,
125 /* .flags = */ pdff_psbend
128 const struct pt_decoder_function pt_decode_tsc = {
129 /* .packet = */ pt_pkt_decode_tsc,
130 /* .decode = */ pt_qry_decode_tsc,
131 /* .header = */ pt_qry_header_tsc,
132 /* .flags = */ pdff_timing
135 const struct pt_decoder_function pt_decode_cbr = {
136 /* .packet = */ pt_pkt_decode_cbr,
137 /* .decode = */ pt_qry_decode_cbr,
138 /* .header = */ pt_qry_header_cbr,
139 /* .flags = */ pdff_timing | pdff_event
142 const struct pt_decoder_function pt_decode_tma = {
143 /* .packet = */ pt_pkt_decode_tma,
144 /* .decode = */ pt_qry_decode_tma,
145 /* .header = */ pt_qry_decode_tma,
146 /* .flags = */ pdff_timing
149 const struct pt_decoder_function pt_decode_mtc = {
150 /* .packet = */ pt_pkt_decode_mtc,
151 /* .decode = */ pt_qry_decode_mtc,
152 /* .header = */ pt_qry_decode_mtc,
153 /* .flags = */ pdff_timing
156 const struct pt_decoder_function pt_decode_cyc = {
157 /* .packet = */ pt_pkt_decode_cyc,
158 /* .decode = */ pt_qry_decode_cyc,
159 /* .header = */ pt_qry_decode_cyc,
160 /* .flags = */ pdff_timing
163 const struct pt_decoder_function pt_decode_stop = {
164 /* .packet = */ pt_pkt_decode_stop,
165 /* .decode = */ pt_qry_decode_stop,
166 /* .header = */ NULL,
167 /* .flags = */ pdff_event
170 const struct pt_decoder_function pt_decode_vmcs = {
171 /* .packet = */ pt_pkt_decode_vmcs,
172 /* .decode = */ pt_qry_decode_vmcs,
173 /* .header = */ pt_qry_header_vmcs,
174 /* .flags = */ pdff_event
177 const struct pt_decoder_function pt_decode_mnt = {
178 /* .packet = */ pt_pkt_decode_mnt,
179 /* .decode = */ pt_qry_decode_mnt,
180 /* .header = */ pt_qry_header_mnt,
181 /* .flags = */ pdff_event
184 const struct pt_decoder_function pt_decode_exstop = {
185 /* .packet = */ pt_pkt_decode_exstop,
186 /* .decode = */ pt_qry_decode_exstop,
187 /* .header = */ NULL,
188 /* .flags = */ pdff_event
191 const struct pt_decoder_function pt_decode_mwait = {
192 /* .packet = */ pt_pkt_decode_mwait,
193 /* .decode = */ pt_qry_decode_mwait,
194 /* .header = */ NULL,
195 /* .flags = */ pdff_event
198 const struct pt_decoder_function pt_decode_pwre = {
199 /* .packet = */ pt_pkt_decode_pwre,
200 /* .decode = */ pt_qry_decode_pwre,
201 /* .header = */ NULL,
202 /* .flags = */ pdff_event
205 const struct pt_decoder_function pt_decode_pwrx = {
206 /* .packet = */ pt_pkt_decode_pwrx,
207 /* .decode = */ pt_qry_decode_pwrx,
208 /* .header = */ NULL,
209 /* .flags = */ pdff_event
212 const struct pt_decoder_function pt_decode_ptw = {
213 /* .packet = */ pt_pkt_decode_ptw,
214 /* .decode = */ pt_qry_decode_ptw,
215 /* .header = */ NULL,
216 /* .flags = */ pdff_event
220 int pt_df_fetch(const struct pt_decoder_function **dfun, const uint8_t *pos,
221 const struct pt_config *config)
223 const uint8_t *begin, *end;
224 uint8_t opc, ext, ext2;
226 if (!dfun || !config)
227 return -pte_internal;
229 /* Clear the decode function in case of errors. */
232 begin = config->begin;
235 if (!pos || (pos < begin) || (end < pos))
244 /* Check opcodes that require masking. */
245 if ((opc & pt_opm_tnt_8) == pt_opc_tnt_8) {
246 *dfun = &pt_decode_tnt_8;
250 if ((opc & pt_opm_cyc) == pt_opc_cyc) {
251 *dfun = &pt_decode_cyc;
255 if ((opc & pt_opm_tip) == pt_opc_tip) {
256 *dfun = &pt_decode_tip;
260 if ((opc & pt_opm_fup) == pt_opc_fup) {
261 *dfun = &pt_decode_fup;
265 if ((opc & pt_opm_tip) == pt_opc_tip_pge) {
266 *dfun = &pt_decode_tip_pge;
270 if ((opc & pt_opm_tip) == pt_opc_tip_pgd) {
271 *dfun = &pt_decode_tip_pgd;
275 *dfun = &pt_decode_unknown;
279 *dfun = &pt_decode_pad;
283 *dfun = &pt_decode_mode;
287 *dfun = &pt_decode_tsc;
291 *dfun = &pt_decode_mtc;
301 /* Check opcodes that require masking. */
302 if ((ext & pt_opm_ptw) == pt_ext_ptw) {
303 *dfun = &pt_decode_ptw;
307 *dfun = &pt_decode_unknown;
311 *dfun = &pt_decode_psb;
315 *dfun = &pt_decode_ovf;
319 *dfun = &pt_decode_tnt_64;
323 *dfun = &pt_decode_psbend;
327 *dfun = &pt_decode_cbr;
331 *dfun = &pt_decode_pip;
335 *dfun = &pt_decode_tma;
339 *dfun = &pt_decode_stop;
343 *dfun = &pt_decode_vmcs;
347 case pt_ext_exstop_ip:
348 *dfun = &pt_decode_exstop;
352 *dfun = &pt_decode_mwait;
356 *dfun = &pt_decode_pwre;
360 *dfun = &pt_decode_pwrx;
370 *dfun = &pt_decode_unknown;
374 *dfun = &pt_decode_mnt;