inst.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Generate .byte code for some instructions not supported by old
  3. * binutils.
  4. */
  5. #ifndef X86_ASM_INST_H
  6. #define X86_ASM_INST_H
  7. #ifdef __ASSEMBLY__
  8. #define REG_NUM_INVALID 100
  9. #define REG_TYPE_R64 0
  10. #define REG_TYPE_XMM 1
  11. #define REG_TYPE_INVALID 100
  12. .macro R64_NUM opd r64
  13. \opd = REG_NUM_INVALID
  14. .ifc \r64,%rax
  15. \opd = 0
  16. .endif
  17. .ifc \r64,%rcx
  18. \opd = 1
  19. .endif
  20. .ifc \r64,%rdx
  21. \opd = 2
  22. .endif
  23. .ifc \r64,%rbx
  24. \opd = 3
  25. .endif
  26. .ifc \r64,%rsp
  27. \opd = 4
  28. .endif
  29. .ifc \r64,%rbp
  30. \opd = 5
  31. .endif
  32. .ifc \r64,%rsi
  33. \opd = 6
  34. .endif
  35. .ifc \r64,%rdi
  36. \opd = 7
  37. .endif
  38. .ifc \r64,%r8
  39. \opd = 8
  40. .endif
  41. .ifc \r64,%r9
  42. \opd = 9
  43. .endif
  44. .ifc \r64,%r10
  45. \opd = 10
  46. .endif
  47. .ifc \r64,%r11
  48. \opd = 11
  49. .endif
  50. .ifc \r64,%r12
  51. \opd = 12
  52. .endif
  53. .ifc \r64,%r13
  54. \opd = 13
  55. .endif
  56. .ifc \r64,%r14
  57. \opd = 14
  58. .endif
  59. .ifc \r64,%r15
  60. \opd = 15
  61. .endif
  62. .endm
  63. .macro XMM_NUM opd xmm
  64. \opd = REG_NUM_INVALID
  65. .ifc \xmm,%xmm0
  66. \opd = 0
  67. .endif
  68. .ifc \xmm,%xmm1
  69. \opd = 1
  70. .endif
  71. .ifc \xmm,%xmm2
  72. \opd = 2
  73. .endif
  74. .ifc \xmm,%xmm3
  75. \opd = 3
  76. .endif
  77. .ifc \xmm,%xmm4
  78. \opd = 4
  79. .endif
  80. .ifc \xmm,%xmm5
  81. \opd = 5
  82. .endif
  83. .ifc \xmm,%xmm6
  84. \opd = 6
  85. .endif
  86. .ifc \xmm,%xmm7
  87. \opd = 7
  88. .endif
  89. .ifc \xmm,%xmm8
  90. \opd = 8
  91. .endif
  92. .ifc \xmm,%xmm9
  93. \opd = 9
  94. .endif
  95. .ifc \xmm,%xmm10
  96. \opd = 10
  97. .endif
  98. .ifc \xmm,%xmm11
  99. \opd = 11
  100. .endif
  101. .ifc \xmm,%xmm12
  102. \opd = 12
  103. .endif
  104. .ifc \xmm,%xmm13
  105. \opd = 13
  106. .endif
  107. .ifc \xmm,%xmm14
  108. \opd = 14
  109. .endif
  110. .ifc \xmm,%xmm15
  111. \opd = 15
  112. .endif
  113. .endm
  114. .macro REG_TYPE type reg
  115. R64_NUM reg_type_r64 \reg
  116. XMM_NUM reg_type_xmm \reg
  117. .if reg_type_r64 <> REG_NUM_INVALID
  118. \type = REG_TYPE_R64
  119. .elseif reg_type_xmm <> REG_NUM_INVALID
  120. \type = REG_TYPE_XMM
  121. .else
  122. \type = REG_TYPE_INVALID
  123. .endif
  124. .endm
  125. .macro PFX_OPD_SIZE
  126. .byte 0x66
  127. .endm
  128. .macro PFX_REX opd1 opd2 W=0
  129. .if ((\opd1 | \opd2) & 8) || \W
  130. .byte 0x40 | ((\opd1 & 8) >> 3) | ((\opd2 & 8) >> 1) | (\W << 3)
  131. .endif
  132. .endm
  133. .macro MODRM mod opd1 opd2
  134. .byte \mod | (\opd1 & 7) | ((\opd2 & 7) << 3)
  135. .endm
  136. .macro PSHUFB_XMM xmm1 xmm2
  137. XMM_NUM pshufb_opd1 \xmm1
  138. XMM_NUM pshufb_opd2 \xmm2
  139. PFX_OPD_SIZE
  140. PFX_REX pshufb_opd1 pshufb_opd2
  141. .byte 0x0f, 0x38, 0x00
  142. MODRM 0xc0 pshufb_opd1 pshufb_opd2
  143. .endm
  144. .macro PCLMULQDQ imm8 xmm1 xmm2
  145. XMM_NUM clmul_opd1 \xmm1
  146. XMM_NUM clmul_opd2 \xmm2
  147. PFX_OPD_SIZE
  148. PFX_REX clmul_opd1 clmul_opd2
  149. .byte 0x0f, 0x3a, 0x44
  150. MODRM 0xc0 clmul_opd1 clmul_opd2
  151. .byte \imm8
  152. .endm
  153. .macro AESKEYGENASSIST rcon xmm1 xmm2
  154. XMM_NUM aeskeygen_opd1 \xmm1
  155. XMM_NUM aeskeygen_opd2 \xmm2
  156. PFX_OPD_SIZE
  157. PFX_REX aeskeygen_opd1 aeskeygen_opd2
  158. .byte 0x0f, 0x3a, 0xdf
  159. MODRM 0xc0 aeskeygen_opd1 aeskeygen_opd2
  160. .byte \rcon
  161. .endm
  162. .macro AESIMC xmm1 xmm2
  163. XMM_NUM aesimc_opd1 \xmm1
  164. XMM_NUM aesimc_opd2 \xmm2
  165. PFX_OPD_SIZE
  166. PFX_REX aesimc_opd1 aesimc_opd2
  167. .byte 0x0f, 0x38, 0xdb
  168. MODRM 0xc0 aesimc_opd1 aesimc_opd2
  169. .endm
  170. .macro AESENC xmm1 xmm2
  171. XMM_NUM aesenc_opd1 \xmm1
  172. XMM_NUM aesenc_opd2 \xmm2
  173. PFX_OPD_SIZE
  174. PFX_REX aesenc_opd1 aesenc_opd2
  175. .byte 0x0f, 0x38, 0xdc
  176. MODRM 0xc0 aesenc_opd1 aesenc_opd2
  177. .endm
  178. .macro AESENCLAST xmm1 xmm2
  179. XMM_NUM aesenclast_opd1 \xmm1
  180. XMM_NUM aesenclast_opd2 \xmm2
  181. PFX_OPD_SIZE
  182. PFX_REX aesenclast_opd1 aesenclast_opd2
  183. .byte 0x0f, 0x38, 0xdd
  184. MODRM 0xc0 aesenclast_opd1 aesenclast_opd2
  185. .endm
  186. .macro AESDEC xmm1 xmm2
  187. XMM_NUM aesdec_opd1 \xmm1
  188. XMM_NUM aesdec_opd2 \xmm2
  189. PFX_OPD_SIZE
  190. PFX_REX aesdec_opd1 aesdec_opd2
  191. .byte 0x0f, 0x38, 0xde
  192. MODRM 0xc0 aesdec_opd1 aesdec_opd2
  193. .endm
  194. .macro AESDECLAST xmm1 xmm2
  195. XMM_NUM aesdeclast_opd1 \xmm1
  196. XMM_NUM aesdeclast_opd2 \xmm2
  197. PFX_OPD_SIZE
  198. PFX_REX aesdeclast_opd1 aesdeclast_opd2
  199. .byte 0x0f, 0x38, 0xdf
  200. MODRM 0xc0 aesdeclast_opd1 aesdeclast_opd2
  201. .endm
  202. .macro MOVQ_R64_XMM opd1 opd2
  203. REG_TYPE movq_r64_xmm_opd1_type \opd1
  204. .if movq_r64_xmm_opd1_type == REG_TYPE_XMM
  205. XMM_NUM movq_r64_xmm_opd1 \opd1
  206. R64_NUM movq_r64_xmm_opd2 \opd2
  207. .else
  208. R64_NUM movq_r64_xmm_opd1 \opd1
  209. XMM_NUM movq_r64_xmm_opd2 \opd2
  210. .endif
  211. PFX_OPD_SIZE
  212. PFX_REX movq_r64_xmm_opd1 movq_r64_xmm_opd2 1
  213. .if movq_r64_xmm_opd1_type == REG_TYPE_XMM
  214. .byte 0x0f, 0x7e
  215. .else
  216. .byte 0x0f, 0x6e
  217. .endif
  218. MODRM 0xc0 movq_r64_xmm_opd1 movq_r64_xmm_opd2
  219. .endm
  220. #endif
  221. #endif