Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * x86 instruction attribute tables
0004  *
0005  * Written by Masami Hiramatsu <mhiramat@redhat.com>
0006  */
0007 #include "../include/asm/insn.h" /* __ignore_sync_check__ */
0008 
0009 /* Attribute tables are generated from opcode map */
0010 #include "inat-tables.c"
0011 
0012 /* Attribute search APIs */
0013 insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode)
0014 {
0015     return inat_primary_table[opcode];
0016 }
0017 
0018 int inat_get_last_prefix_id(insn_byte_t last_pfx)
0019 {
0020     insn_attr_t lpfx_attr;
0021 
0022     lpfx_attr = inat_get_opcode_attribute(last_pfx);
0023     return inat_last_prefix_id(lpfx_attr);
0024 }
0025 
0026 insn_attr_t inat_get_escape_attribute(insn_byte_t opcode, int lpfx_id,
0027                       insn_attr_t esc_attr)
0028 {
0029     const insn_attr_t *table;
0030     int n;
0031 
0032     n = inat_escape_id(esc_attr);
0033 
0034     table = inat_escape_tables[n][0];
0035     if (!table)
0036         return 0;
0037     if (inat_has_variant(table[opcode]) && lpfx_id) {
0038         table = inat_escape_tables[n][lpfx_id];
0039         if (!table)
0040             return 0;
0041     }
0042     return table[opcode];
0043 }
0044 
0045 insn_attr_t inat_get_group_attribute(insn_byte_t modrm, int lpfx_id,
0046                      insn_attr_t grp_attr)
0047 {
0048     const insn_attr_t *table;
0049     int n;
0050 
0051     n = inat_group_id(grp_attr);
0052 
0053     table = inat_group_tables[n][0];
0054     if (!table)
0055         return inat_group_common_attribute(grp_attr);
0056     if (inat_has_variant(table[X86_MODRM_REG(modrm)]) && lpfx_id) {
0057         table = inat_group_tables[n][lpfx_id];
0058         if (!table)
0059             return inat_group_common_attribute(grp_attr);
0060     }
0061     return table[X86_MODRM_REG(modrm)] |
0062            inat_group_common_attribute(grp_attr);
0063 }
0064 
0065 insn_attr_t inat_get_avx_attribute(insn_byte_t opcode, insn_byte_t vex_m,
0066                    insn_byte_t vex_p)
0067 {
0068     const insn_attr_t *table;
0069     if (vex_m > X86_VEX_M_MAX || vex_p > INAT_LSTPFX_MAX)
0070         return 0;
0071     /* At first, this checks the master table */
0072     table = inat_avx_tables[vex_m][0];
0073     if (!table)
0074         return 0;
0075     if (!inat_is_group(table[opcode]) && vex_p) {
0076         /* If this is not a group, get attribute directly */
0077         table = inat_avx_tables[vex_m][vex_p];
0078         if (!table)
0079             return 0;
0080     }
0081     return table[opcode];
0082 }
0083