2 * Copyright (c) 2013-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 #if !defined(PT_ILD_H)
38 PTI_MAP_0, /* 1-byte opcodes. may have modrm */
39 PTI_MAP_1, /* 2-byte opcodes (0x0f). may have modrm */
40 PTI_MAP_2, /* 3-byte opcodes (0x0f38). has modrm */
41 PTI_MAP_3, /* 3-byte opcodes (0x0f3a). has modrm */
42 PTI_MAP_AMD3DNOW, /* 3d-now opcodes (0x0f0f). has modrm */
49 uint8_t max_bytes; /*1..15 bytes */
50 enum pt_exec_mode mode;
59 uint32_t last_f2f3:2; /* 2 or 3 */
60 /* The vex bit is set for c4/c5 VEX and EVEX. */
62 /* The REX.R and REX.W bits in REX, VEX, or EVEX. */
68 uint8_t imm1_bytes; /* # of bytes in 1st immediate */
69 uint8_t imm2_bytes; /* # of bytes in 2nd immediate */
70 uint8_t disp_bytes; /* # of displacement bytes */
72 /* 5b but valid values= 0,1,2,3 could be in bit union */
74 uint8_t rex; /* 0b0100wrxb */
75 uint8_t nominal_opcode;
77 /* imm_pos can be derived from disp_pos + disp_bytes. */
80 static inline pti_map_enum_t pti_get_map(const struct pt_ild *ild)
82 return (pti_map_enum_t) ild->map;
85 static inline uint8_t pti_get_modrm_mod(const struct pt_ild *ild)
87 return ild->modrm_byte >> 6;
90 static inline uint8_t pti_get_modrm_reg(const struct pt_ild *ild)
92 return (ild->modrm_byte >> 3) & 7;
95 static inline uint8_t pti_get_modrm_rm(const struct pt_ild *ild)
97 return ild->modrm_byte & 7;
100 /* MAIN ENTRANCE POINTS */
102 /* one time call. not thread safe init. call when single threaded. */
103 extern void pt_ild_init(void);
105 /* all decoding is multithread safe. */
107 /* Decode one instruction.
111 * @insn->ip: the virtual address of the instruction
112 * @insn->raw: the memory at that virtual address
113 * @insn->size: the maximal size of the instruction
114 * @insn->mode: the execution mode
118 * @insn->size: the actual size of the instruction
119 * @insn->iclass: a coarse classification
121 * @iext->iclass: a finer grain classification
122 * @iext->variant: instruction class dependent information
124 * Returns zero on success, a negative error code otherwise.
126 extern int pt_ild_decode(struct pt_insn *insn, struct pt_insn_ext *iext);
128 #endif /* PT_ILD_H */