PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/x86/lib/inat.c

http://github.com/torvalds/linux
C | 83 lines | 61 code | 12 blank | 10 comment | 14 complexity | bc2c9ef3afa3d96a0a779d6a86415eba MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * x86 instruction attribute tables
  4. *
  5. * Written by Masami Hiramatsu <mhiramat@redhat.com>
  6. */
  7. #include <asm/insn.h>
  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. }