inat.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * x86 instruction attribute tables
  4. *
  5. * Written by Masami Hiramatsu <[email protected]>
  6. */
  7. #include <asm/insn.h> /* __ignore_sync_check__ */
  8. /* Attribute tables are generated from opcode map */
  9. #include "inat-tables.c"
  10. /* Attribute search APIs */
  11. insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode)
  12. {
  13. return inat_primary_table[opcode];
  14. }
  15. int inat_get_last_prefix_id(insn_byte_t last_pfx)
  16. {
  17. insn_attr_t lpfx_attr;
  18. lpfx_attr = inat_get_opcode_attribute(last_pfx);
  19. return inat_last_prefix_id(lpfx_attr);
  20. }
  21. insn_attr_t inat_get_escape_attribute(insn_byte_t opcode, int lpfx_id,
  22. insn_attr_t esc_attr)
  23. {
  24. const insn_attr_t *table;
  25. int n;
  26. n = inat_escape_id(esc_attr);
  27. table = inat_escape_tables[n][0];
  28. if (!table)
  29. return 0;
  30. if (inat_has_variant(table[opcode]) && lpfx_id) {
  31. table = inat_escape_tables[n][lpfx_id];
  32. if (!table)
  33. return 0;
  34. }
  35. return table[opcode];
  36. }
  37. insn_attr_t inat_get_group_attribute(insn_byte_t modrm, int lpfx_id,
  38. insn_attr_t grp_attr)
  39. {
  40. const insn_attr_t *table;
  41. int n;
  42. n = inat_group_id(grp_attr);
  43. table = inat_group_tables[n][0];
  44. if (!table)
  45. return inat_group_common_attribute(grp_attr);
  46. if (inat_has_variant(table[X86_MODRM_REG(modrm)]) && lpfx_id) {
  47. table = inat_group_tables[n][lpfx_id];
  48. if (!table)
  49. return inat_group_common_attribute(grp_attr);
  50. }
  51. return table[X86_MODRM_REG(modrm)] |
  52. inat_group_common_attribute(grp_attr);
  53. }
  54. insn_attr_t inat_get_avx_attribute(insn_byte_t opcode, insn_byte_t vex_m,
  55. insn_byte_t vex_p)
  56. {
  57. const insn_attr_t *table;
  58. if (vex_m > X86_VEX_M_MAX || vex_p > INAT_LSTPFX_MAX)
  59. return 0;
  60. /* At first, this checks the master table */
  61. table = inat_avx_tables[vex_m][0];
  62. if (!table)
  63. return 0;
  64. if (!inat_is_group(table[opcode]) && vex_p) {
  65. /* If this is not a group, get attribute directly */
  66. table = inat_avx_tables[vex_m][vex_p];
  67. if (!table)
  68. return 0;
  69. }
  70. return table[opcode];
  71. }