inst.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Generate .byte code for some instructions not supported by old
  4. * binutils.
  5. */
  6. #ifndef X86_ASM_INST_H
  7. #define X86_ASM_INST_H
  8. #ifdef __ASSEMBLY__
  9. #define REG_NUM_INVALID 100
  10. #define REG_TYPE_R32 0
  11. #define REG_TYPE_R64 1
  12. #define REG_TYPE_INVALID 100
  13. .macro R32_NUM opd r32
  14. \opd = REG_NUM_INVALID
  15. .ifc \r32,%eax
  16. \opd = 0
  17. .endif
  18. .ifc \r32,%ecx
  19. \opd = 1
  20. .endif
  21. .ifc \r32,%edx
  22. \opd = 2
  23. .endif
  24. .ifc \r32,%ebx
  25. \opd = 3
  26. .endif
  27. .ifc \r32,%esp
  28. \opd = 4
  29. .endif
  30. .ifc \r32,%ebp
  31. \opd = 5
  32. .endif
  33. .ifc \r32,%esi
  34. \opd = 6
  35. .endif
  36. .ifc \r32,%edi
  37. \opd = 7
  38. .endif
  39. #ifdef CONFIG_X86_64
  40. .ifc \r32,%r8d
  41. \opd = 8
  42. .endif
  43. .ifc \r32,%r9d
  44. \opd = 9
  45. .endif
  46. .ifc \r32,%r10d
  47. \opd = 10
  48. .endif
  49. .ifc \r32,%r11d
  50. \opd = 11
  51. .endif
  52. .ifc \r32,%r12d
  53. \opd = 12
  54. .endif
  55. .ifc \r32,%r13d
  56. \opd = 13
  57. .endif
  58. .ifc \r32,%r14d
  59. \opd = 14
  60. .endif
  61. .ifc \r32,%r15d
  62. \opd = 15
  63. .endif
  64. #endif
  65. .endm
  66. .macro R64_NUM opd r64
  67. \opd = REG_NUM_INVALID
  68. #ifdef CONFIG_X86_64
  69. .ifc \r64,%rax
  70. \opd = 0
  71. .endif
  72. .ifc \r64,%rcx
  73. \opd = 1
  74. .endif
  75. .ifc \r64,%rdx
  76. \opd = 2
  77. .endif
  78. .ifc \r64,%rbx
  79. \opd = 3
  80. .endif
  81. .ifc \r64,%rsp
  82. \opd = 4
  83. .endif
  84. .ifc \r64,%rbp
  85. \opd = 5
  86. .endif
  87. .ifc \r64,%rsi
  88. \opd = 6
  89. .endif
  90. .ifc \r64,%rdi
  91. \opd = 7
  92. .endif
  93. .ifc \r64,%r8
  94. \opd = 8
  95. .endif
  96. .ifc \r64,%r9
  97. \opd = 9
  98. .endif
  99. .ifc \r64,%r10
  100. \opd = 10
  101. .endif
  102. .ifc \r64,%r11
  103. \opd = 11
  104. .endif
  105. .ifc \r64,%r12
  106. \opd = 12
  107. .endif
  108. .ifc \r64,%r13
  109. \opd = 13
  110. .endif
  111. .ifc \r64,%r14
  112. \opd = 14
  113. .endif
  114. .ifc \r64,%r15
  115. \opd = 15
  116. .endif
  117. #endif
  118. .endm
  119. .macro REG_TYPE type reg
  120. R32_NUM reg_type_r32 \reg
  121. R64_NUM reg_type_r64 \reg
  122. .if reg_type_r64 <> REG_NUM_INVALID
  123. \type = REG_TYPE_R64
  124. .elseif reg_type_r32 <> REG_NUM_INVALID
  125. \type = REG_TYPE_R32
  126. .else
  127. \type = REG_TYPE_INVALID
  128. .endif
  129. .endm
  130. .macro PFX_REX opd1 opd2 W=0
  131. .if ((\opd1 | \opd2) & 8) || \W
  132. .byte 0x40 | ((\opd1 & 8) >> 3) | ((\opd2 & 8) >> 1) | (\W << 3)
  133. .endif
  134. .endm
  135. .macro MODRM mod opd1 opd2
  136. .byte \mod | (\opd1 & 7) | ((\opd2 & 7) << 3)
  137. .endm
  138. #endif
  139. #endif