xref: /freebsd/contrib/processor-trace/libipt/internal/include/pt_decoder_function.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*
2  * Copyright (c) 2013-2019, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
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.
15  *
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.
27  */
28 
29 #ifndef PT_DECODER_FUNCTION_H
30 #define PT_DECODER_FUNCTION_H
31 
32 #include <stdint.h>
33 
34 struct pt_query_decoder;
35 struct pt_packet_decoder;
36 struct pt_packet;
37 struct pt_config;
38 
39 
40 /* Intel(R) Processor Trace decoder function flags. */
41 enum pt_decoder_function_flag {
42 	/* The decoded packet contains an unconditional branch destination. */
43 	pdff_tip	= 1 << 0,
44 
45 	/* The decode packet contains unconditional branch destinations. */
46 	pdff_tnt	= 1 << 1,
47 
48 	/* The decoded packet contains an event. */
49 	pdff_event	= 1 << 2,
50 
51 	/* The decoded packet marks the end of a PSB header. */
52 	pdff_psbend	= 1 << 3,
53 
54 	/* The decoded packet contains a non-branch IP update. */
55 	pdff_fup	= 1 << 4,
56 
57 	/* The decoded packet is unknown to the decoder. */
58 	pdff_unknown	= 1 << 5,
59 
60 	/* The decoded packet contains timing information. */
61 	pdff_timing	= 1 << 6,
62 
63 	/* The decoded packet contains padding. */
64 	pdff_pad	= 1 << 7
65 };
66 
67 /* An Intel(R) Processor Trace decoder function. */
68 struct pt_decoder_function {
69 	/* The function to analyze the next packet. */
70 	int (*packet)(struct pt_packet_decoder *, struct pt_packet *);
71 
72 	/* The function to decode the next packet. */
73 	int (*decode)(struct pt_query_decoder *);
74 
75 	/* The function to decode the next packet in segment header
76 	 * context, i.e. between PSB and ENDPSB.
77 	 */
78 	int (*header)(struct pt_query_decoder *);
79 
80 	/* Decoder function flags. */
81 	int flags;
82 };
83 
84 
85 /* Fetch the decoder function.
86  *
87  * Sets @dfun to the decoder function for decoding the packet at @pos.
88  *
89  * Returns 0 on success.
90  * Returns -pte_internal if @dfun or @config is NULL.
91  * Returns -pte_nosync if @pos is NULL or outside @config's trace buffer.
92  * Returns -pte_eos if the opcode is incomplete or missing.
93  */
94 extern int pt_df_fetch(const struct pt_decoder_function **dfun,
95 		       const uint8_t *pos, const struct pt_config *config);
96 
97 
98 /* Decoder functions for the various packet types.
99  *
100  * Do not call those functions directly!
101  */
102 extern const struct pt_decoder_function pt_decode_unknown;
103 extern const struct pt_decoder_function pt_decode_pad;
104 extern const struct pt_decoder_function pt_decode_psb;
105 extern const struct pt_decoder_function pt_decode_tip;
106 extern const struct pt_decoder_function pt_decode_tnt_8;
107 extern const struct pt_decoder_function pt_decode_tnt_64;
108 extern const struct pt_decoder_function pt_decode_tip_pge;
109 extern const struct pt_decoder_function pt_decode_tip_pgd;
110 extern const struct pt_decoder_function pt_decode_fup;
111 extern const struct pt_decoder_function pt_decode_pip;
112 extern const struct pt_decoder_function pt_decode_ovf;
113 extern const struct pt_decoder_function pt_decode_mode;
114 extern const struct pt_decoder_function pt_decode_psbend;
115 extern const struct pt_decoder_function pt_decode_tsc;
116 extern const struct pt_decoder_function pt_decode_cbr;
117 extern const struct pt_decoder_function pt_decode_tma;
118 extern const struct pt_decoder_function pt_decode_mtc;
119 extern const struct pt_decoder_function pt_decode_cyc;
120 extern const struct pt_decoder_function pt_decode_stop;
121 extern const struct pt_decoder_function pt_decode_vmcs;
122 extern const struct pt_decoder_function pt_decode_mnt;
123 extern const struct pt_decoder_function pt_decode_exstop;
124 extern const struct pt_decoder_function pt_decode_mwait;
125 extern const struct pt_decoder_function pt_decode_pwre;
126 extern const struct pt_decoder_function pt_decode_pwrx;
127 extern const struct pt_decoder_function pt_decode_ptw;
128 
129 #endif /* PT_DECODER_FUNCTION_H */
130