inat.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "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. int inat_get_last_prefix_id(insn_byte_t last_pfx)
  30. {
  31. insn_attr_t lpfx_attr;
  32. lpfx_attr = inat_get_opcode_attribute(last_pfx);
  33. return inat_last_prefix_id(lpfx_attr);
  34. }
  35. insn_attr_t inat_get_escape_attribute(insn_byte_t opcode, int lpfx_id,
  36. insn_attr_t esc_attr)
  37. {
  38. const insn_attr_t *table;
  39. int n;
  40. n = inat_escape_id(esc_attr);
  41. table = inat_escape_tables[n][0];
  42. if (!table)
  43. return 0;
  44. if (inat_has_variant(table[opcode]) && lpfx_id) {
  45. table = inat_escape_tables[n][lpfx_id];
  46. if (!table)
  47. return 0;
  48. }
  49. return table[opcode];
  50. }
  51. insn_attr_t inat_get_group_attribute(insn_byte_t modrm, int lpfx_id,
  52. insn_attr_t grp_attr)
  53. {
  54. const insn_attr_t *table;
  55. int n;
  56. n = inat_group_id(grp_attr);
  57. table = inat_group_tables[n][0];
  58. if (!table)
  59. return inat_group_common_attribute(grp_attr);
  60. if (inat_has_variant(table[X86_MODRM_REG(modrm)]) && lpfx_id) {
  61. table = inat_group_tables[n][lpfx_id];
  62. if (!table)
  63. return inat_group_common_attribute(grp_attr);
  64. }
  65. return table[X86_MODRM_REG(modrm)] |
  66. inat_group_common_attribute(grp_attr);
  67. }
  68. insn_attr_t inat_get_avx_attribute(insn_byte_t opcode, insn_byte_t vex_m,
  69. insn_byte_t vex_p)
  70. {
  71. const insn_attr_t *table;
  72. if (vex_m > X86_VEX_M_MAX || vex_p > INAT_LSTPFX_MAX)
  73. return 0;
  74. /* At first, this checks the master table */
  75. table = inat_avx_tables[vex_m][0];
  76. if (!table)
  77. return 0;
  78. if (!inat_is_group(table[opcode]) && vex_p) {
  79. /* If this is not a group, get attribute directly */
  80. table = inat_avx_tables[vex_m][vex_p];
  81. if (!table)
  82. return 0;
  83. }
  84. return table[opcode];
  85. }