2 * Copyright (c) 2016-2018, 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 #ifndef PT_BLOCK_DECODER_H
30 #define PT_BLOCK_DECODER_H
32 #include "pt_query_decoder.h"
34 #include "pt_retstack.h"
36 #include "pt_msec_cache.h"
41 * It decodes Intel(R) Processor Trace into a sequence of instruction blocks
42 * such that the instructions in each block can be decoded without further need
45 struct pt_block_decoder {
46 /* The Intel(R) Processor Trace query decoder. */
47 struct pt_query_decoder query;
49 /* The configuration flags.
51 * Those are our flags set by the user. In @query.config.flags, we set
52 * the flags we need for the query decoder.
54 struct pt_conf_flags flags;
56 /* The default image. */
57 struct pt_image default_image;
60 struct pt_image *image;
62 /* The current cached section. */
63 struct pt_msec_cache scache;
65 /* The current address space. */
68 /* The current Intel(R) Processor Trace event. */
69 struct pt_event event;
71 /* The call/return stack for ret compression. */
72 struct pt_retstack retstack;
74 /* The current instruction.
76 * This is only valid if @process_insn is set.
79 struct pt_insn_ext iext;
81 /* The start IP of the next block.
83 * If tracing is disabled, this is the IP at which we assume tracing to
88 /* The current execution mode. */
89 enum pt_exec_mode mode;
91 /* The status of the last successful decoder query.
93 * Errors are reported directly; the status is always a non-negative
94 * pt_status_flag bit-vector.
98 /* A collection of flags defining how to proceed flow reconstruction:
100 * - tracing is enabled.
104 /* - process @event. */
105 uint32_t process_event:1;
107 /* - instructions are executed speculatively. */
108 uint32_t speculative:1;
110 /* - process @insn/@iext.
112 * We have started processing events binding to @insn/@iext. The
113 * instruction has been accounted for in the previous block, but we
114 * have not yet proceeded past it.
116 * We will do so in pt_blk_event() after processing all events that
119 uint32_t process_insn:1;
121 /* - a paging event has already been bound to @insn/@iext. */
122 uint32_t bound_paging:1;
124 /* - a vmcs event has already been bound to @insn/@iext. */
125 uint32_t bound_vmcs:1;
127 /* - a ptwrite event has already been bound to @insn/@iext. */
128 uint32_t bound_ptwrite:1;
132 /* Initialize a block decoder.
134 * Returns zero on success; a negative error code otherwise.
135 * Returns -pte_internal, if @decoder or @config is NULL.
137 extern int pt_blk_decoder_init(struct pt_block_decoder *decoder,
138 const struct pt_config *config);
140 /* Finalize a block decoder. */
141 extern void pt_blk_decoder_fini(struct pt_block_decoder *decoder);
143 #endif /* PT_BLOCK_DECODER_H */