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.
30 #include "pti-imm-defs.h"
32 #include "pti-modrm-defs.h"
33 #include "pti-modrm.h"
34 #include "pti-disp-defs.h"
41 static uint8_t has_disp_regular[4][4][8];
43 static void init_has_disp_regular_table(void)
47 memset(has_disp_regular, 0, sizeof(has_disp_regular));
50 has_disp_regular[ptem_16bit][0][6] = 2;
51 for (rm = 0; rm < 8; rm++)
52 for (mod = 1; mod <= 2; mod++)
53 has_disp_regular[ptem_16bit][mod][rm] = mod;
56 has_disp_regular[ptem_32bit][0][5] = 4;
57 has_disp_regular[ptem_64bit][0][5] = 4;
58 for (rm = 0; rm < 8; rm++) {
59 has_disp_regular[ptem_32bit][1][rm] = 1;
60 has_disp_regular[ptem_32bit][2][rm] = 4;
62 has_disp_regular[ptem_64bit][1][rm] = 1;
63 has_disp_regular[ptem_64bit][2][rm] = 4;
67 static uint8_t eamode_table[2][4];
69 static void init_eamode_table(void)
71 eamode_table[0][ptem_unknown] = ptem_unknown;
72 eamode_table[0][ptem_16bit] = ptem_16bit;
73 eamode_table[0][ptem_32bit] = ptem_32bit;
74 eamode_table[0][ptem_64bit] = ptem_64bit;
76 eamode_table[1][ptem_unknown] = ptem_unknown;
77 eamode_table[1][ptem_16bit] = ptem_32bit;
78 eamode_table[1][ptem_32bit] = ptem_16bit;
79 eamode_table[1][ptem_64bit] = ptem_32bit;
82 static uint8_t has_sib_table[4][4][8];
84 static void init_has_sib_table(void)
88 memset(has_sib_table, 0, sizeof(has_sib_table));
90 /*for eamode32/64 there is sib byte for mod!=3 and rm==4 */
91 for (mod = 0; mod <= 2; mod++) {
92 has_sib_table[ptem_32bit][mod][4] = 1;
93 has_sib_table[ptem_64bit][mod][4] = 1;
99 static inline uint8_t get_byte(const struct pt_ild *ild, uint8_t i)
101 return ild->itext[i];
104 static inline uint8_t const *get_byte_ptr(const struct pt_ild *ild, uint8_t i)
106 return ild->itext + i;
109 static inline int mode_64b(const struct pt_ild *ild)
111 return ild->mode == ptem_64bit;
114 static inline int mode_32b(const struct pt_ild *ild)
116 return ild->mode == ptem_32bit;
119 static inline int bits_match(uint8_t x, uint8_t mask, uint8_t target)
121 return (x & mask) == target;
124 static inline enum pt_exec_mode
125 pti_get_nominal_eosz_non64(const struct pt_ild *ild)
137 static inline enum pt_exec_mode
138 pti_get_nominal_eosz(const struct pt_ild *ild)
147 return pti_get_nominal_eosz_non64(ild);
150 static inline enum pt_exec_mode
151 pti_get_nominal_eosz_df64(const struct pt_ild *ild)
158 /* only this next line of code is different relative
159 to pti_get_nominal_eosz(), above */
162 return pti_get_nominal_eosz_non64(ild);
165 static inline enum pt_exec_mode
166 pti_get_nominal_easz_non64(const struct pt_ild *ild)
178 static inline enum pt_exec_mode
179 pti_get_nominal_easz(const struct pt_ild *ild)
186 return pti_get_nominal_easz_non64(ild);
189 static inline int resolve_z(uint8_t *pbytes, enum pt_exec_mode eosz)
191 static const uint8_t bytes[] = { 2, 4, 4 };
195 return -pte_internal;
197 idx = (unsigned int) eosz - 1;
198 if (sizeof(bytes) <= idx)
199 return -pte_bad_insn;
201 *pbytes = bytes[idx];
205 static inline int resolve_v(uint8_t *pbytes, enum pt_exec_mode eosz)
207 static const uint8_t bytes[] = { 2, 4, 8 };
211 return -pte_internal;
213 idx = (unsigned int) eosz - 1;
214 if (sizeof(bytes) <= idx)
215 return -pte_bad_insn;
217 *pbytes = bytes[idx];
223 static int set_imm_bytes(struct pt_ild *ild)
225 /*: set ild->imm1_bytes and ild->imm2_bytes for maps 0/1 */
226 static uint8_t const *const map_map[] = {
227 /* map 0 */ imm_bytes_map_0x0,
228 /* map 1 */ imm_bytes_map_0x0F
230 uint8_t map, imm_code;
233 return -pte_internal;
237 if ((sizeof(map_map) / sizeof(*map_map)) <= map)
240 imm_code = map_map[map][ild->nominal_opcode];
243 case PTI_0_IMM_WIDTH_CONST_l2:
247 case PTI_UIMM8_IMM_WIDTH_CONST_l2:
251 case PTI_SIMM8_IMM_WIDTH_CONST_l2:
255 case PTI_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2:
257 return resolve_z(&ild->imm1_bytes, pti_get_nominal_eosz(ild));
259 case PTI_UIMMv_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2:
261 return resolve_v(&ild->imm1_bytes, pti_get_nominal_eosz(ild));
263 case PTI_UIMM16_IMM_WIDTH_CONST_l2:
267 case PTI_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_EOSZ_l2:
268 /* push defaults to eosz64 in 64b mode, then uses SIMMz */
269 return resolve_z(&ild->imm1_bytes,
270 pti_get_nominal_eosz_df64(ild));
272 case PTI_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf7_l1:
273 if (ild->map == PTI_MAP_0 && pti_get_modrm_reg(ild) < 2) {
274 return resolve_z(&ild->imm1_bytes,
275 pti_get_nominal_eosz(ild));
279 case PTI_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xc7_l1:
280 if (ild->map == PTI_MAP_0 && pti_get_modrm_reg(ild) == 0) {
281 return resolve_z(&ild->imm1_bytes,
282 pti_get_nominal_eosz(ild));
286 case PTI_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf6_l1:
287 if (ild->map == PTI_MAP_0 && pti_get_modrm_reg(ild) < 2)
292 case PTI_IMM_hasimm_map0x0_op0xc8_l1:
293 if (ild->map == PTI_MAP_0) {
294 /*enter -> imm1=2, imm2=1 */
300 case PTI_IMM_hasimm_map0x0F_op0x78_l1:
301 /* AMD SSE4a (insertq/extrq use osz/f2) vs vmread
304 if (ild->map == PTI_MAP_1) {
305 if (ild->u.s.osz || ild->u.s.last_f2f3 == 2) {
314 static int imm_dec(struct pt_ild *ild, uint8_t length)
319 return -pte_internal;
321 if (ild->map == PTI_MAP_AMD3DNOW) {
322 if (ild->max_bytes <= length)
323 return -pte_bad_insn;
325 ild->nominal_opcode = get_byte(ild, length);
329 errcode = set_imm_bytes(ild);
333 length += ild->imm1_bytes;
334 length += ild->imm2_bytes;
335 if (ild->max_bytes < length)
336 return -pte_bad_insn;
341 static int compute_disp_dec(struct pt_ild *ild)
343 /* set ild->disp_bytes for maps 0 and 1. */
344 static uint8_t const *const map_map[] = {
345 /* map 0 */ disp_bytes_map_0x0,
346 /* map 1 */ disp_bytes_map_0x0F
348 uint8_t map, disp_kind;
351 return -pte_internal;
353 if (0 < ild->disp_bytes)
358 if ((sizeof(map_map) / sizeof(*map_map)) <= map)
361 disp_kind = map_map[map][ild->nominal_opcode];
367 case PTI_PRESERVE_DEFAULT:
375 case PTI_DISP_BUCKET_0_l1:
376 /* BRDISPz(eosz) for 16/32 modes, and BRDISP32 for 64b mode */
382 return resolve_z(&ild->disp_bytes,
383 pti_get_nominal_eosz(ild));
385 case PTI_MEMDISPv_DISP_WIDTH_ASZ_NONTERM_EASZ_l2:
387 return resolve_v(&ild->disp_bytes, pti_get_nominal_easz(ild));
389 case PTI_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2:
390 /* BRDISPz(eosz) for 16/32/64 modes */
391 return resolve_z(&ild->disp_bytes, pti_get_nominal_eosz(ild));
393 case PTI_RESOLVE_BYREG_DISP_map0x0_op0xc7_l1:
394 /* reg=0 -> preserve, reg=7 -> BRDISPz(eosz) */
395 if (ild->map == PTI_MAP_0 && pti_get_modrm_reg(ild) == 7) {
396 return resolve_z(&ild->disp_bytes,
397 pti_get_nominal_eosz(ild));
402 return -pte_bad_insn;
406 static int disp_dec(struct pt_ild *ild, uint8_t length)
412 return -pte_internal;
414 errcode = compute_disp_dec(ild);
418 disp_bytes = ild->disp_bytes;
420 return imm_dec(ild, length);
422 if (length + disp_bytes > ild->max_bytes)
423 return -pte_bad_insn;
425 /*Record only position; must be able to re-read itext bytes for actual
426 value. (SMC/CMC issue). */
427 ild->disp_pos = length;
429 return imm_dec(ild, length + disp_bytes);
432 static int sib_dec(struct pt_ild *ild, uint8_t length)
437 return -pte_internal;
439 if (ild->max_bytes <= length)
440 return -pte_bad_insn;
442 sib = get_byte(ild, length);
443 if ((sib & 0x07) == 0x05 && pti_get_modrm_mod(ild) == 0)
446 return disp_dec(ild, length + 1);
449 static int modrm_dec(struct pt_ild *ild, uint8_t length)
451 static uint8_t const *const has_modrm_2d[2] = {
455 int has_modrm = PTI_MODRM_FALSE;
459 return -pte_internal;
461 map = pti_get_map(ild);
462 if (map >= PTI_MAP_2)
463 has_modrm = PTI_MODRM_TRUE;
465 has_modrm = has_modrm_2d[map][ild->nominal_opcode];
467 if (has_modrm == PTI_MODRM_FALSE || has_modrm == PTI_MODRM_UNDEF)
468 return disp_dec(ild, length);
470 /* really >= here because we have not eaten the byte yet */
471 if (length >= ild->max_bytes)
472 return -pte_bad_insn;
474 ild->modrm_byte = get_byte(ild, length);
476 if (has_modrm != PTI_MODRM_IGNORE_MOD) {
477 /* set disp_bytes and sib using simple tables */
479 uint8_t eamode = eamode_table[ild->u.s.asz][ild->mode];
480 uint8_t mod = (uint8_t) pti_get_modrm_mod(ild);
481 uint8_t rm = (uint8_t) pti_get_modrm_rm(ild);
484 ild->disp_bytes = has_disp_regular[eamode][mod][rm];
486 has_sib = has_sib_table[eamode][mod][rm];
488 return sib_dec(ild, length + 1);
491 return disp_dec(ild, length + 1);
494 static inline int get_next_as_opcode(struct pt_ild *ild, uint8_t length)
497 return -pte_internal;
499 if (ild->max_bytes <= length)
500 return -pte_bad_insn;
502 ild->nominal_opcode = get_byte(ild, length);
504 return modrm_dec(ild, length + 1);
507 static int opcode_dec(struct pt_ild *ild, uint8_t length)
512 return -pte_internal;
514 /*no need to check max_bytes - it was checked in previous scanners */
515 b = get_byte(ild, length);
516 if (b != 0x0F) { /* 1B opcodes, map 0 */
517 ild->map = PTI_MAP_0;
518 ild->nominal_opcode = b;
520 return modrm_dec(ild, length + 1);
523 length++; /* eat the 0x0F */
525 if (ild->max_bytes <= length)
526 return -pte_bad_insn;
528 /* 0x0F opcodes MAPS 1,2,3 */
529 m = get_byte(ild, length);
531 ild->map = PTI_MAP_2;
533 return get_next_as_opcode(ild, length + 1);
534 } else if (m == 0x3A) {
535 ild->map = PTI_MAP_3;
538 return get_next_as_opcode(ild, length + 1);
539 } else if (bits_match(m, 0xf8, 0x38)) {
540 ild->map = PTI_MAP_INVALID;
542 return get_next_as_opcode(ild, length + 1);
543 } else if (m == 0x0F) { /* 3dNow */
544 ild->map = PTI_MAP_AMD3DNOW;
546 /* real opcode is in immediate later on, but we need an
548 ild->nominal_opcode = 0x0F;
550 return modrm_dec(ild, length + 1);
551 } else { /* map 1 (simple two byte opcodes) */
552 ild->nominal_opcode = m;
553 ild->map = PTI_MAP_1;
555 return modrm_dec(ild, length + 1);
559 typedef int (*prefix_decoder)(struct pt_ild *ild, uint8_t length, uint8_t rex);
560 static prefix_decoder prefix_table[256];
562 static inline int prefix_decode(struct pt_ild *ild, uint8_t length, uint8_t rex)
567 return -pte_internal;
569 if (ild->max_bytes <= length)
570 return -pte_bad_insn;
572 byte = get_byte(ild, length);
574 return prefix_table[byte](ild, length, rex);
577 static inline int prefix_next(struct pt_ild *ild, uint8_t length, uint8_t rex)
579 return prefix_decode(ild, length + 1, rex);
582 static int prefix_osz(struct pt_ild *ild, uint8_t length, uint8_t rex)
587 return -pte_internal;
591 return prefix_next(ild, length, 0);
594 static int prefix_asz(struct pt_ild *ild, uint8_t length, uint8_t rex)
599 return -pte_internal;
603 return prefix_next(ild, length, 0);
606 static int prefix_lock(struct pt_ild *ild, uint8_t length, uint8_t rex)
611 return -pte_internal;
615 return prefix_next(ild, length, 0);
618 static int prefix_f2(struct pt_ild *ild, uint8_t length, uint8_t rex)
623 return -pte_internal;
626 ild->u.s.last_f2f3 = 2;
628 return prefix_next(ild, length, 0);
631 static int prefix_f3(struct pt_ild *ild, uint8_t length, uint8_t rex)
636 return -pte_internal;
639 ild->u.s.last_f2f3 = 3;
641 return prefix_next(ild, length, 0);
644 static int prefix_ignore(struct pt_ild *ild, uint8_t length, uint8_t rex)
648 return prefix_next(ild, length, 0);
651 static int prefix_done(struct pt_ild *ild, uint8_t length, uint8_t rex)
654 return -pte_internal;
661 return opcode_dec(ild, length);
664 static int prefix_rex(struct pt_ild *ild, uint8_t length, uint8_t rex)
669 return -pte_internal;
672 return prefix_next(ild, length, get_byte(ild, length));
674 return opcode_dec(ild, length);
677 static inline int prefix_vex_done(struct pt_ild *ild, uint8_t length)
680 return -pte_internal;
682 ild->nominal_opcode = get_byte(ild, length);
684 return modrm_dec(ild, length + 1);
687 static int prefix_vex_c5(struct pt_ild *ild, uint8_t length, uint8_t rex)
695 return -pte_internal;
697 max_bytes = ild->max_bytes;
699 /* Read the next byte to validate that this is indeed VEX. */
700 if (max_bytes <= (length + 1))
701 return -pte_bad_insn;
703 p1 = get_byte(ild, length + 1);
705 /* If p1[7:6] is not 11b in non-64-bit mode, this is LDS, not VEX. */
706 if (!mode_64b(ild) && !bits_match(p1, 0xc0, 0xc0))
707 return opcode_dec(ild, length);
709 /* We need at least 3 bytes
710 * - 2 for the VEX prefix and payload and
711 * - 1 for the opcode.
713 if (max_bytes < (length + 3))
714 return -pte_bad_insn;
720 ild->map = PTI_MAP_1;
724 return prefix_vex_done(ild, length);
727 static int prefix_vex_c4(struct pt_ild *ild, uint8_t length, uint8_t rex)
735 return -pte_internal;
737 max_bytes = ild->max_bytes;
739 /* Read the next byte to validate that this is indeed VEX. */
740 if (max_bytes <= (length + 1))
741 return -pte_bad_insn;
743 p1 = get_byte(ild, length + 1);
745 /* If p1[7:6] is not 11b in non-64-bit mode, this is LES, not VEX. */
746 if (!mode_64b(ild) && !bits_match(p1, 0xc0, 0xc0))
747 return opcode_dec(ild, length);
749 /* We need at least 4 bytes
750 * - 3 for the VEX prefix and payload and
751 * - 1 for the opcode.
753 if (max_bytes < (length + 4))
754 return -pte_bad_insn;
756 p2 = get_byte(ild, length + 2);
765 if (PTI_MAP_INVALID <= map)
766 return -pte_bad_insn;
769 if (map == PTI_MAP_3)
774 return prefix_vex_done(ild, length);
777 static int prefix_evex(struct pt_ild *ild, uint8_t length, uint8_t rex)
785 return -pte_internal;
787 max_bytes = ild->max_bytes;
789 /* Read the next byte to validate that this is indeed EVEX. */
790 if (max_bytes <= (length + 1))
791 return -pte_bad_insn;
793 p1 = get_byte(ild, length + 1);
795 /* If p1[7:6] is not 11b in non-64-bit mode, this is BOUND, not EVEX. */
796 if (!mode_64b(ild) && !bits_match(p1, 0xc0, 0xc0))
797 return opcode_dec(ild, length);
799 /* We need at least 5 bytes
800 * - 4 for the EVEX prefix and payload and
801 * - 1 for the opcode.
803 if (max_bytes < (length + 5))
804 return -pte_bad_insn;
806 p2 = get_byte(ild, length + 2);
817 if (map == PTI_MAP_3)
822 return prefix_vex_done(ild, length);
825 static void init_prefix_table(void)
829 for (byte = 0; byte <= 0xff; ++byte)
830 prefix_table[byte] = prefix_done;
832 prefix_table[0x66] = prefix_osz;
833 prefix_table[0x67] = prefix_asz;
835 /* Segment prefixes. */
836 prefix_table[0x2e] = prefix_ignore;
837 prefix_table[0x3e] = prefix_ignore;
838 prefix_table[0x26] = prefix_ignore;
839 prefix_table[0x36] = prefix_ignore;
840 prefix_table[0x64] = prefix_ignore;
841 prefix_table[0x65] = prefix_ignore;
843 prefix_table[0xf0] = prefix_lock;
844 prefix_table[0xf2] = prefix_f2;
845 prefix_table[0xf3] = prefix_f3;
847 for (byte = 0x40; byte <= 0x4f; ++byte)
848 prefix_table[byte] = prefix_rex;
850 prefix_table[0xc4] = prefix_vex_c4;
851 prefix_table[0xc5] = prefix_vex_c5;
852 prefix_table[0x62] = prefix_evex;
855 static int decode(struct pt_ild *ild)
857 return prefix_decode(ild, 0, 0);
860 static int set_branch_target(struct pt_insn_ext *iext, const struct pt_ild *ild)
863 return -pte_internal;
865 iext->variant.branch.is_direct = 1;
867 if (ild->disp_bytes == 1) {
868 const int8_t *b = (const int8_t *)
869 get_byte_ptr(ild, ild->disp_pos);
871 iext->variant.branch.displacement = *b;
872 } else if (ild->disp_bytes == 2) {
873 const int16_t *w = (const int16_t *)
874 get_byte_ptr(ild, ild->disp_pos);
876 iext->variant.branch.displacement = *w;
877 } else if (ild->disp_bytes == 4) {
878 const int32_t *d = (const int32_t *)
879 get_byte_ptr(ild, ild->disp_pos);
881 iext->variant.branch.displacement = *d;
883 return -pte_bad_insn;
888 /* MAIN ENTRY POINTS */
890 void pt_ild_init(void)
891 { /* initialization */
892 init_has_disp_regular_table();
893 init_has_sib_table();
898 static int pt_instruction_length_decode(struct pt_ild *ild)
901 return -pte_internal;
908 ild->map = PTI_MAP_INVALID;
911 return -pte_bad_insn;
916 static int pt_instruction_decode(struct pt_insn *insn, struct pt_insn_ext *iext,
917 const struct pt_ild *ild)
922 return -pte_internal;
924 iext->iclass = PTI_INST_INVALID;
925 memset(&iext->variant, 0, sizeof(iext->variant));
927 insn->iclass = ptic_other;
929 opcode = ild->nominal_opcode;
933 return 0; /* uninteresting */
935 return 0; /* uninteresting */
937 /* PTI_INST_JCC, 70...7F, 0F (0x80...0x8F) */
938 if (opcode >= 0x70 && opcode <= 0x7F) {
939 if (map == PTI_MAP_0) {
940 insn->iclass = ptic_cond_jump;
941 iext->iclass = PTI_INST_JCC;
943 return set_branch_target(iext, ild);
947 if (opcode >= 0x80 && opcode <= 0x8F) {
948 if (map == PTI_MAP_1) {
949 insn->iclass = ptic_cond_jump;
950 iext->iclass = PTI_INST_JCC;
952 return set_branch_target(iext, ild);
957 switch (ild->nominal_opcode) {
959 if (map == PTI_MAP_0) {
960 insn->iclass = ptic_far_call;
961 iext->iclass = PTI_INST_CALL_9A;
966 if (map == PTI_MAP_0) {
967 uint8_t reg = pti_get_modrm_reg(ild);
970 insn->iclass = ptic_call;
971 iext->iclass = PTI_INST_CALL_FFr2;
972 } else if (reg == 3) {
973 insn->iclass = ptic_far_call;
974 iext->iclass = PTI_INST_CALL_FFr3;
975 } else if (reg == 4) {
976 insn->iclass = ptic_jump;
977 iext->iclass = PTI_INST_JMP_FFr4;
978 } else if (reg == 5) {
979 insn->iclass = ptic_far_jump;
980 iext->iclass = PTI_INST_JMP_FFr5;
986 if (map == PTI_MAP_0) {
987 insn->iclass = ptic_call;
988 iext->iclass = PTI_INST_CALL_E8;
990 return set_branch_target(iext, ild);
995 if (map == PTI_MAP_0) {
996 insn->iclass = ptic_far_call;
997 iext->iclass = PTI_INST_INT;
1003 if (map == PTI_MAP_0) {
1004 insn->iclass = ptic_far_call;
1005 iext->iclass = PTI_INST_INT3;
1011 if (map == PTI_MAP_0) {
1012 insn->iclass = ptic_far_call;
1013 iext->iclass = PTI_INST_INTO;
1019 if (map == PTI_MAP_0) {
1020 insn->iclass = ptic_far_call;
1021 iext->iclass = PTI_INST_INT1;
1027 if (map == PTI_MAP_0) {
1028 insn->iclass = ptic_far_return;
1029 iext->iclass = PTI_INST_IRET;
1034 if (map == PTI_MAP_0) {
1035 insn->iclass = ptic_jump;
1036 iext->iclass = PTI_INST_JMP_E9;
1038 return set_branch_target(iext, ild);
1043 if (map == PTI_MAP_0) {
1044 /* Far jumps are treated as indirect jumps. */
1045 insn->iclass = ptic_far_jump;
1046 iext->iclass = PTI_INST_JMP_EA;
1051 if (map == PTI_MAP_0) {
1052 insn->iclass = ptic_jump;
1053 iext->iclass = PTI_INST_JMP_EB;
1055 return set_branch_target(iext, ild);
1060 if (map == PTI_MAP_0) {
1061 insn->iclass = ptic_cond_jump;
1062 iext->iclass = PTI_INST_JrCXZ;
1064 return set_branch_target(iext, ild);
1069 if (map == PTI_MAP_0) {
1070 insn->iclass = ptic_cond_jump;
1071 iext->iclass = PTI_INST_LOOPNE;
1073 return set_branch_target(iext, ild);
1078 if (map == PTI_MAP_0) {
1079 insn->iclass = ptic_cond_jump;
1080 iext->iclass = PTI_INST_LOOPE;
1082 return set_branch_target(iext, ild);
1087 if (map == PTI_MAP_0) {
1088 insn->iclass = ptic_cond_jump;
1089 iext->iclass = PTI_INST_LOOP;
1091 return set_branch_target(iext, ild);
1096 if (map == PTI_MAP_1)
1097 if (pti_get_modrm_reg(ild) == 3)
1098 if (!ild->u.s.rex_r)
1099 iext->iclass = PTI_INST_MOV_CR3;
1104 if (map == PTI_MAP_0) {
1105 insn->iclass = ptic_return;
1106 iext->iclass = PTI_INST_RET_C3;
1111 if (map == PTI_MAP_0) {
1112 insn->iclass = ptic_return;
1113 iext->iclass = PTI_INST_RET_C2;
1118 if (map == PTI_MAP_0) {
1119 insn->iclass = ptic_far_return;
1120 iext->iclass = PTI_INST_RET_CB;
1125 if (map == PTI_MAP_0) {
1126 insn->iclass = ptic_far_return;
1127 iext->iclass = PTI_INST_RET_CA;
1132 if (map == PTI_MAP_1) {
1133 insn->iclass = ptic_far_call;
1134 iext->iclass = PTI_INST_SYSCALL;
1139 if (map == PTI_MAP_1) {
1140 insn->iclass = ptic_far_call;
1141 iext->iclass = PTI_INST_SYSENTER;
1146 if (map == PTI_MAP_1) {
1147 insn->iclass = ptic_far_return;
1148 iext->iclass = PTI_INST_SYSEXIT;
1153 if (map == PTI_MAP_1) {
1154 insn->iclass = ptic_far_return;
1155 iext->iclass = PTI_INST_SYSRET;
1160 if (map == PTI_MAP_1) {
1161 switch (ild->modrm_byte) {
1163 insn->iclass = ptic_far_call;
1164 iext->iclass = PTI_INST_VMCALL;
1168 insn->iclass = ptic_far_return;
1169 iext->iclass = PTI_INST_VMLAUNCH;
1173 insn->iclass = ptic_far_return;
1174 iext->iclass = PTI_INST_VMRESUME;
1184 if (map == PTI_MAP_1 &&
1185 pti_get_modrm_mod(ild) != 3 &&
1186 pti_get_modrm_reg(ild) == 6)
1187 iext->iclass = PTI_INST_VMPTRLD;
1192 if (map == PTI_MAP_1 && ild->u.s.f3 && !ild->u.s.osz &&
1193 pti_get_modrm_reg(ild) == 4) {
1194 insn->iclass = ptic_ptwrite;
1195 iext->iclass = PTI_INST_PTWRITE;
1204 int pt_ild_decode(struct pt_insn *insn, struct pt_insn_ext *iext)
1210 return -pte_internal;
1212 ild.mode = insn->mode;
1213 ild.itext = insn->raw;
1214 ild.max_bytes = insn->size;
1216 size = pt_instruction_length_decode(&ild);
1220 insn->size = (uint8_t) size;
1222 return pt_instruction_decode(insn, iext, &ild);