blob: 12539fca75c4ae72437e2d2c1e3332faebd09c3d [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Masami Hiramatsueb132962009-08-13 16:34:13 -04002/*
3 * x86 instruction attribute tables
4 *
5 * Written by Masami Hiramatsu <mhiramat@redhat.com>
Masami Hiramatsueb132962009-08-13 16:34:13 -04006 */
7#include <asm/insn.h>
8
9/* Attribute tables are generated from opcode map */
10#include "inat-tables.c"
11
12/* Attribute search APIs */
13insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode)
14{
15 return inat_primary_table[opcode];
16}
17
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090018int inat_get_last_prefix_id(insn_byte_t last_pfx)
19{
20 insn_attr_t lpfx_attr;
21
22 lpfx_attr = inat_get_opcode_attribute(last_pfx);
23 return inat_last_prefix_id(lpfx_attr);
24}
25
26insn_attr_t inat_get_escape_attribute(insn_byte_t opcode, int lpfx_id,
Masami Hiramatsueb132962009-08-13 16:34:13 -040027 insn_attr_t esc_attr)
28{
29 const insn_attr_t *table;
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090030 int n;
Masami Hiramatsueb132962009-08-13 16:34:13 -040031
32 n = inat_escape_id(esc_attr);
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090033
Masami Hiramatsueb132962009-08-13 16:34:13 -040034 table = inat_escape_tables[n][0];
35 if (!table)
36 return 0;
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090037 if (inat_has_variant(table[opcode]) && lpfx_id) {
38 table = inat_escape_tables[n][lpfx_id];
Masami Hiramatsueb132962009-08-13 16:34:13 -040039 if (!table)
40 return 0;
41 }
42 return table[opcode];
43}
44
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090045insn_attr_t inat_get_group_attribute(insn_byte_t modrm, int lpfx_id,
Masami Hiramatsueb132962009-08-13 16:34:13 -040046 insn_attr_t grp_attr)
47{
48 const insn_attr_t *table;
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090049 int n;
Masami Hiramatsueb132962009-08-13 16:34:13 -040050
51 n = inat_group_id(grp_attr);
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090052
Masami Hiramatsueb132962009-08-13 16:34:13 -040053 table = inat_group_tables[n][0];
54 if (!table)
55 return inat_group_common_attribute(grp_attr);
Masami Hiramatsuf8d98f12012-02-10 14:33:40 +090056 if (inat_has_variant(table[X86_MODRM_REG(modrm)]) && lpfx_id) {
57 table = inat_group_tables[n][lpfx_id];
Masami Hiramatsueb132962009-08-13 16:34:13 -040058 if (!table)
59 return inat_group_common_attribute(grp_attr);
60 }
61 return table[X86_MODRM_REG(modrm)] |
62 inat_group_common_attribute(grp_attr);
63}
64
Masami Hiramatsue0e492e2009-10-27 16:42:27 -040065insn_attr_t inat_get_avx_attribute(insn_byte_t opcode, insn_byte_t vex_m,
66 insn_byte_t vex_p)
67{
68 const insn_attr_t *table;
69 if (vex_m > X86_VEX_M_MAX || vex_p > INAT_LSTPFX_MAX)
70 return 0;
Masami Hiramatsu130b78b2011-12-05 21:05:39 +090071 /* At first, this checks the master table */
72 table = inat_avx_tables[vex_m][0];
Masami Hiramatsue0e492e2009-10-27 16:42:27 -040073 if (!table)
74 return 0;
Masami Hiramatsu130b78b2011-12-05 21:05:39 +090075 if (!inat_is_group(table[opcode]) && vex_p) {
76 /* If this is not a group, get attribute directly */
77 table = inat_avx_tables[vex_m][vex_p];
78 if (!table)
79 return 0;
80 }
Masami Hiramatsue0e492e2009-10-27 16:42:27 -040081 return table[opcode];
82}
83