inat.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * x86 instruction attribute tables
  3. *
  4. * Written by Masami Hiramatsu <mhiramat@redhat.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. *
  20. */
  21. #include <asm/insn.h>
  22. /* Attribute tables are generated from opcode map */
  23. #include "inat-tables.c"
  24. /* Attribute search APIs */
  25. insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode)
  26. {
  27. return inat_primary_table[opcode];
  28. }
  29. insn_attr_t inat_get_escape_attribute(insn_byte_t opcode, insn_byte_t last_pfx,
  30. insn_attr_t esc_attr)
  31. {
  32. const insn_attr_t *table;
  33. insn_attr_t lpfx_attr;
  34. int n, m = 0;
  35. n = inat_escape_id(esc_attr);
  36. if (last_pfx) {
  37. lpfx_attr = inat_get_opcode_attribute(last_pfx);
  38. m = inat_last_prefix_id(lpfx_attr);
  39. }
  40. table = inat_escape_tables[n][0];
  41. if (!table)
  42. return 0;
  43. if (inat_has_variant(table[opcode]) && m) {
  44. table = inat_escape_tables[n][m];
  45. if (!table)
  46. return 0;
  47. }
  48. return table[opcode];
  49. }
  50. insn_attr_t inat_get_group_attribute(insn_byte_t modrm, insn_byte_t last_pfx,
  51. insn_attr_t grp_attr)
  52. {
  53. const insn_attr_t *table;
  54. insn_attr_t lpfx_attr;
  55. int n, m = 0;
  56. n = inat_group_id(grp_attr);
  57. if (last_pfx) {
  58. lpfx_attr = inat_get_opcode_attribute(last_pfx);
  59. m = inat_last_prefix_id(lpfx_attr);
  60. }
  61. table = inat_group_tables[n][0];
  62. if (!table)
  63. return inat_group_common_attribute(grp_attr);
  64. if (inat_has_variant(table[X86_MODRM_REG(modrm)]) && m) {
  65. table = inat_group_tables[n][m];
  66. if (!table)
  67. return inat_group_common_attribute(grp_attr);
  68. }
  69. return table[X86_MODRM_REG(modrm)] |
  70. inat_group_common_attribute(grp_attr);
  71. }
  72. insn_attr_t inat_get_avx_attribute(insn_byte_t opcode, insn_byte_t vex_m,
  73. insn_byte_t vex_p)
  74. {
  75. const insn_attr_t *table;
  76. if (vex_m > X86_VEX_M_MAX || vex_p > INAT_LSTPFX_MAX)
  77. return 0;
  78. table = inat_avx_tables[vex_m][vex_p];
  79. if (!table)
  80. return 0;
  81. return table[opcode];
  82. }