1 /***************************************************************************************************
3 Zyan Disassembler Library (Zydis)
5 Original Author : Florian Bernd
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 ***************************************************************************************************/
27 #include <Zydis/Internal/SharedData.h>
29 /* ============================================================================================== */
31 /* ============================================================================================== */
33 /* ---------------------------------------------------------------------------------------------- */
34 /* Instruction definitions */
35 /* ---------------------------------------------------------------------------------------------- */
37 #ifdef ZYDIS_MINIMAL_MODE
38 # define ZYDIS_NOTMIN(x)
40 # define ZYDIS_NOTMIN(x) , x
43 #include <Generated/InstructionDefinitions.inc>
47 /* ---------------------------------------------------------------------------------------------- */
48 /* Operand definitions */
49 /* ---------------------------------------------------------------------------------------------- */
51 #define ZYDIS_OPERAND_DEFINITION(type, encoding, access) \
52 { type, encoding, access }
54 #include <Generated/OperandDefinitions.inc>
56 #undef ZYDIS_OPERAND_DEFINITION
58 /* ---------------------------------------------------------------------------------------------- */
59 /* Accessed CPU flags */
60 /* ---------------------------------------------------------------------------------------------- */
62 #include <Generated/AccessedFlags.inc>
64 /* ---------------------------------------------------------------------------------------------- */
66 /* ============================================================================================== */
68 /* ============================================================================================== */
70 /* ---------------------------------------------------------------------------------------------- */
71 /* Instruction definition */
72 /* ---------------------------------------------------------------------------------------------- */
74 void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding
, ZyanU16 id
,
75 const ZydisInstructionDefinition
** definition
)
79 case ZYDIS_INSTRUCTION_ENCODING_LEGACY
:
80 *definition
= (ZydisInstructionDefinition
*)&ISTR_DEFINITIONS_LEGACY
[id
];
82 case ZYDIS_INSTRUCTION_ENCODING_3DNOW
:
83 *definition
= (ZydisInstructionDefinition
*)&ISTR_DEFINITIONS_3DNOW
[id
];
85 case ZYDIS_INSTRUCTION_ENCODING_XOP
:
86 *definition
= (ZydisInstructionDefinition
*)&ISTR_DEFINITIONS_XOP
[id
];
88 case ZYDIS_INSTRUCTION_ENCODING_VEX
:
89 *definition
= (ZydisInstructionDefinition
*)&ISTR_DEFINITIONS_VEX
[id
];
91 #ifndef ZYDIS_DISABLE_AVX512
92 case ZYDIS_INSTRUCTION_ENCODING_EVEX
:
93 *definition
= (ZydisInstructionDefinition
*)&ISTR_DEFINITIONS_EVEX
[id
];
96 #ifndef ZYDIS_DISABLE_KNC
97 case ZYDIS_INSTRUCTION_ENCODING_MVEX
:
98 *definition
= (ZydisInstructionDefinition
*)&ISTR_DEFINITIONS_MVEX
[id
];
106 /* ---------------------------------------------------------------------------------------------- */
107 /* Operand definition */
108 /* ---------------------------------------------------------------------------------------------- */
110 #ifndef ZYDIS_MINIMAL_MODE
111 const ZydisOperandDefinition
* ZydisGetOperandDefinitions(
112 const ZydisInstructionDefinition
* definition
)
114 if (definition
->operand_count
== 0)
118 ZYAN_ASSERT(definition
->operand_reference
!= 0xFFFF);
119 return &OPERAND_DEFINITIONS
[definition
->operand_reference
];
123 /* ---------------------------------------------------------------------------------------------- */
125 /* ---------------------------------------------------------------------------------------------- */
127 #ifndef ZYDIS_MINIMAL_MODE
128 void ZydisGetElementInfo(ZydisInternalElementType element
, ZydisElementType
* type
,
129 ZydisElementSize
* size
)
133 ZydisElementType type
;
134 ZydisElementSize size
;
135 } lookup
[ZYDIS_IELEMENT_TYPE_MAX_VALUE
+ 1] =
137 { ZYDIS_ELEMENT_TYPE_INVALID
, 0 },
138 { ZYDIS_ELEMENT_TYPE_INVALID
, 0 },
139 { ZYDIS_ELEMENT_TYPE_STRUCT
, 0 },
140 { ZYDIS_ELEMENT_TYPE_INT
, 0 },
141 { ZYDIS_ELEMENT_TYPE_UINT
, 0 },
142 { ZYDIS_ELEMENT_TYPE_INT
, 1 },
143 { ZYDIS_ELEMENT_TYPE_INT
, 8 },
144 { ZYDIS_ELEMENT_TYPE_INT
, 16 },
145 { ZYDIS_ELEMENT_TYPE_INT
, 32 },
146 { ZYDIS_ELEMENT_TYPE_INT
, 64 },
147 { ZYDIS_ELEMENT_TYPE_UINT
, 8 },
148 { ZYDIS_ELEMENT_TYPE_UINT
, 16 },
149 { ZYDIS_ELEMENT_TYPE_UINT
, 32 },
150 { ZYDIS_ELEMENT_TYPE_UINT
, 64 },
151 { ZYDIS_ELEMENT_TYPE_UINT
, 128 },
152 { ZYDIS_ELEMENT_TYPE_UINT
, 256 },
153 { ZYDIS_ELEMENT_TYPE_FLOAT16
, 16 },
154 { ZYDIS_ELEMENT_TYPE_FLOAT16
, 32 }, // TODO: Should indicate 2 float16 elements
155 { ZYDIS_ELEMENT_TYPE_FLOAT32
, 32 },
156 { ZYDIS_ELEMENT_TYPE_FLOAT64
, 64 },
157 { ZYDIS_ELEMENT_TYPE_FLOAT80
, 80 },
158 { ZYDIS_ELEMENT_TYPE_LONGBCD
, 80 },
159 { ZYDIS_ELEMENT_TYPE_CC
, 3 },
160 { ZYDIS_ELEMENT_TYPE_CC
, 5 }
163 ZYAN_ASSERT((ZyanUSize
)element
< ZYAN_ARRAY_LENGTH(lookup
));
165 *type
= lookup
[element
].type
;
166 *size
= lookup
[element
].size
;
170 /* ---------------------------------------------------------------------------------------------- */
171 /* Accessed CPU flags */
172 /* ---------------------------------------------------------------------------------------------- */
174 #ifndef ZYDIS_MINIMAL_MODE
175 ZyanBool
ZydisGetAccessedFlags(const ZydisInstructionDefinition
* definition
,
176 const ZydisDefinitionAccessedFlags
** flags
)
178 ZYAN_ASSERT(definition
->flags_reference
< ZYAN_ARRAY_LENGTH(ACCESSED_FLAGS
));
179 *flags
= &ACCESSED_FLAGS
[definition
->flags_reference
];
180 return (definition
->flags_reference
!= 0);
184 /* ---------------------------------------------------------------------------------------------- */
186 /* ============================================================================================== */