22 #include <linux/string.h>
30 #define validate_next(t, insn, n) \
31 ((insn)->next_byte + sizeof(t) + n - (insn)->kaddr <= MAX_INSN_SIZE)
33 #define __get_next(t, insn) \
34 ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
36 #define __peek_nbyte_next(t, insn, n) \
37 ({ t r = *(t*)((insn)->next_byte + n); r; })
39 #define get_next(t, insn) \
40 ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
42 #define peek_nbyte_next(t, insn, n) \
43 ({ if (unlikely(!validate_next(t, insn, n))) goto err_out; __peek_nbyte_next(t, insn, n); })
45 #define peek_next(t, insn) peek_nbyte_next(t, insn, 0)
55 memset(insn, 0,
sizeof(*insn));
58 insn->
x86_64 = x86_64 ? 1 : 0;
88 while (inat_is_legacy_prefix(attr)) {
90 for (i = 0; i < nb; i++)
91 if (prefixes->
bytes[i] == b)
97 if (inat_is_address_size_prefix(attr)) {
103 }
else if (inat_is_operand_size_prefix(attr)) {
115 if (lb && lb != insn->
prefixes.bytes[3]) {
119 for (i = 0; i < nb; i++)
120 if (prefixes->
bytes[i] == lb)
130 if (inat_is_rex_prefix(attr)) {
144 if (inat_is_vex_prefix(attr)) {
157 if (inat_is_vex3_prefix(attr)) {
205 if (insn_is_avx(insn)) {
207 m = insn_vex_m_bits(insn);
208 p = insn_vex_p_bits(insn);
210 if (!inat_accept_vex(insn->
attr) && !inat_is_group(insn->
attr))
216 while (inat_is_escape(insn->
attr)) {
220 pfx_id = insn_last_prefix_id(insn);
223 if (inat_must_vex(insn->
attr))
249 if (inat_has_modrm(insn->
attr)) {
253 if (inat_is_group(insn->
attr)) {
254 pfx_id = insn_last_prefix_id(insn);
257 if (insn_is_avx(insn) && !inat_accept_vex(insn->
attr))
262 if (insn->
x86_64 && inat_is_force64(insn->
attr))
290 return (modrm->
nbytes && (modrm->
value & 0xc7) == 0x5);
306 if (!insn->
modrm.got)
308 if (insn->
modrm.nbytes) {
313 insn->
sib.nbytes = 1;
339 if (insn->
modrm.nbytes) {
366 if ((mod == 0 && rm == 6) || mod == 2) {
372 if ((mod == 0 && rm == 5) || mod == 2 ||
373 (mod == 0 && base == 5)) {
387 static int __get_moffset(
struct insn *
insn)
416 static int __get_immv32(
struct insn *insn)
439 static int __get_immv(
struct insn *insn)
467 static int __get_immptr(
struct insn *insn)
509 if (inat_has_moffset(insn->
attr)) {
510 if (!__get_moffset(insn))
515 if (!inat_has_immediate(insn->
attr))
519 switch (inat_immediate_size(insn->
attr)) {
539 if (!__get_immptr(insn))
543 if (!__get_immv32(insn))
547 if (!__get_immv(insn))
554 if (inat_has_second_immediate(insn->
attr)) {