xref: /freebsd/contrib/processor-trace/libipt/internal/include/pt_encoder.h (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 /*
2  * Copyright (c) 2014-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_ENCODER_H
30 #define PT_ENCODER_H
31 
32 #include "intel-pt.h"
33 
34 
35 /* An Intel PT packet encoder. */
36 struct pt_encoder {
37 	/* The encoder configuration. */
38 	struct pt_config config;
39 
40 	/** The current position in the trace buffer. */
41 	uint8_t *pos;
42 };
43 
44 
45 /* Initialize the packet encoder.
46  *
47  * Returns zero on success, a negative error code otherwise.
48  */
49 extern int pt_encoder_init(struct pt_encoder *, const struct pt_config *);
50 
51 /* Finalize the packet encoder. */
52 extern void pt_encoder_fini(struct pt_encoder *);
53 
54 
55 /* The below functions are convenience wrappers around pt_enc_next(). */
56 
57 /* Encode a Padding (pad) packet. */
58 extern int pt_encode_pad(struct pt_encoder *);
59 
60 /* Encode a Packet Stream Boundary (psb) packet. */
61 extern int pt_encode_psb(struct pt_encoder *);
62 
63 /* Encode an End PSB (psbend) packet. */
64 extern int pt_encode_psbend(struct pt_encoder *);
65 
66 /* Encode a Target Instruction Pointer (tip) packet. */
67 extern int pt_encode_tip(struct pt_encoder *, uint64_t ip,
68 			 enum pt_ip_compression ipc);
69 
70 /* Encode a Taken Not Taken (tnt) packet - 8-bit version. */
71 extern int pt_encode_tnt_8(struct pt_encoder *, uint8_t tnt, int size);
72 
73 /* Encode a Taken Not Taken (tnt) packet - 64-bit version. */
74 extern int pt_encode_tnt_64(struct pt_encoder *, uint64_t tnt, int size);
75 
76 /* Encode a Packet Generation Enable (tip.pge) packet. */
77 extern int pt_encode_tip_pge(struct pt_encoder *, uint64_t ip,
78 			     enum pt_ip_compression ipc);
79 
80 /* Encode a Packet Generation Disable (tip.pgd) packet. */
81 extern int pt_encode_tip_pgd(struct pt_encoder *, uint64_t ip,
82 			     enum pt_ip_compression ipc);
83 
84 /* Encode a Flow Update Packet (fup). */
85 extern int pt_encode_fup(struct pt_encoder *, uint64_t ip,
86 			 enum pt_ip_compression ipc);
87 
88 /* Encode a Paging Information Packet (pip). */
89 extern int pt_encode_pip(struct pt_encoder *, uint64_t cr3, uint8_t flags);
90 
91 /* Encode a Overflow Packet (ovf). */
92 extern int pt_encode_ovf(struct pt_encoder *);
93 
94 /* Encode a Mode Exec Packet (mode.exec). */
95 extern int pt_encode_mode_exec(struct pt_encoder *, enum pt_exec_mode);
96 
97 /* Encode a Mode Tsx Packet (mode.tsx). */
98 extern int pt_encode_mode_tsx(struct pt_encoder *, uint8_t);
99 
100 /* Encode a Time Stamp Counter (tsc) packet. */
101 extern int pt_encode_tsc(struct pt_encoder *, uint64_t);
102 
103 /* Encode a Core Bus Ratio (cbr) packet. */
104 extern int pt_encode_cbr(struct pt_encoder *, uint8_t);
105 
106 /* Encode a TSC/MTC Alignment (tma) packet. */
107 extern int pt_encode_tma(struct pt_encoder *, uint16_t ctc,
108 				   uint16_t fc);
109 
110 /* Encode a Mini Time Counter (mtc) packet. */
111 extern int pt_encode_mtc(struct pt_encoder *, uint8_t ctc);
112 
113 /* Encode a Cycle Count (cyc) packet. */
114 extern int pt_encode_cyc(struct pt_encoder *, uint32_t cyc);
115 
116 /* Encode a TraceStop Packet (stop). */
117 extern int pt_encode_stop(struct pt_encoder *);
118 
119 /* Encode a VMCS packet. */
120 extern int pt_encode_vmcs(struct pt_encoder *, uint64_t);
121 
122 /* Encode a Maintenance (mnt) packet. */
123 extern int pt_encode_mnt(struct pt_encoder *, uint64_t);
124 
125 #endif /* PT_ENCODER_H */
126