xref: /freebsd/contrib/processor-trace/libipt/internal/include/pt_insn_decoder.h (revision 85f87cf491bec6f90948a85b10f5523ea24db9e3)
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_INSN_DECODER_H
30 #define PT_INSN_DECODER_H
31 
32 #include "pt_query_decoder.h"
33 #include "pt_image.h"
34 #include "pt_retstack.h"
35 #include "pt_ild.h"
36 #include "pt_msec_cache.h"
37 
38 #include <inttypes.h>
39 
40 
41 struct pt_insn_decoder {
42 	/* The Intel(R) Processor Trace query decoder. */
43 	struct pt_query_decoder query;
44 
45 	/* The configuration flags.
46 	 *
47 	 * Those are our flags set by the user.  In @query.config.flags, we set
48 	 * the flags we need for the query decoder.
49 	 */
50 	struct pt_conf_flags flags;
51 
52 	/* The default image. */
53 	struct pt_image default_image;
54 
55 	/* The image. */
56 	struct pt_image *image;
57 
58 	/* The current cached section. */
59 	struct pt_msec_cache scache;
60 
61 	/* The current address space. */
62 	struct pt_asid asid;
63 
64 	/* The current Intel(R) Processor Trace event. */
65 	struct pt_event event;
66 
67 	/* The call/return stack for ret compression. */
68 	struct pt_retstack retstack;
69 
70 	/* The current instruction.
71 	 *
72 	 * This is only valid if @process_insn is set.
73 	 */
74 	struct pt_insn insn;
75 	struct pt_insn_ext iext;
76 
77 	/* The current IP.
78 	 *
79 	 * If tracing is disabled, this is the IP at which we assume tracing to
80 	 * be resumed.
81 	 */
82 	uint64_t ip;
83 
84 	/* The current execution mode. */
85 	enum pt_exec_mode mode;
86 
87 	/* The status of the last successful decoder query.
88 	 *
89 	 * Errors are reported directly; the status is always a non-negative
90 	 * pt_status_flag bit-vector.
91 	 */
92 	int status;
93 
94 	/* A collection of flags defining how to proceed flow reconstruction:
95 	 *
96 	 * - tracing is enabled.
97 	 */
98 	uint32_t enabled:1;
99 
100 	/* - process @event. */
101 	uint32_t process_event:1;
102 
103 	/* - instructions are executed speculatively. */
104 	uint32_t speculative:1;
105 
106 	/* - process @insn/@iext.
107 	 *
108 	 *   We have started processing events binding to @insn/@iext.  We have
109 	 *   not yet proceeded past it.
110 	 *
111 	 *   We will do so in pt_insn_event() after processing all events that
112 	 *   bind to it.
113 	 */
114 	uint32_t process_insn:1;
115 
116 	/* - a paging event has already been bound to @insn/@iext. */
117 	uint32_t bound_paging:1;
118 
119 	/* - a vmcs event has already been bound to @insn/@iext. */
120 	uint32_t bound_vmcs:1;
121 
122 	/* - a ptwrite event has already been bound to @insn/@iext. */
123 	uint32_t bound_ptwrite:1;
124 };
125 
126 
127 /* Initialize an instruction flow decoder.
128  *
129  * Returns zero on success; a negative error code otherwise.
130  * Returns -pte_internal, if @decoder is NULL.
131  * Returns -pte_invalid, if @config is NULL.
132  */
133 extern int pt_insn_decoder_init(struct pt_insn_decoder *decoder,
134 				const struct pt_config *config);
135 
136 /* Finalize an instruction flow decoder. */
137 extern void pt_insn_decoder_fini(struct pt_insn_decoder *decoder);
138 
139 #endif /* PT_INSN_DECODER_H */
140