asm.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_ASM_H
  3. #define _ASM_X86_ASM_H
  4. #ifdef __ASSEMBLY__
  5. # define __ASM_FORM(x) x
  6. # define __ASM_FORM_RAW(x) x
  7. # define __ASM_FORM_COMMA(x) x,
  8. #else
  9. # define __ASM_FORM(x) " " #x " "
  10. # define __ASM_FORM_RAW(x) #x
  11. # define __ASM_FORM_COMMA(x) " " #x ","
  12. #endif
  13. #ifndef __x86_64__
  14. /* 32 bit */
  15. # define __ASM_SEL(a,b) __ASM_FORM(a)
  16. # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
  17. #else
  18. /* 64 bit */
  19. # define __ASM_SEL(a,b) __ASM_FORM(b)
  20. # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
  21. #endif
  22. #define __ASM_SIZE(inst, ...) __ASM_SEL(inst##l##__VA_ARGS__, \
  23. inst##q##__VA_ARGS__)
  24. #define __ASM_REG(reg) __ASM_SEL_RAW(e##reg, r##reg)
  25. #define _ASM_PTR __ASM_SEL(.long, .quad)
  26. #define _ASM_ALIGN __ASM_SEL(.balign 4, .balign 8)
  27. #define _ASM_MOV __ASM_SIZE(mov)
  28. #define _ASM_INC __ASM_SIZE(inc)
  29. #define _ASM_DEC __ASM_SIZE(dec)
  30. #define _ASM_ADD __ASM_SIZE(add)
  31. #define _ASM_SUB __ASM_SIZE(sub)
  32. #define _ASM_XADD __ASM_SIZE(xadd)
  33. #define _ASM_MUL __ASM_SIZE(mul)
  34. #define _ASM_AX __ASM_REG(ax)
  35. #define _ASM_BX __ASM_REG(bx)
  36. #define _ASM_CX __ASM_REG(cx)
  37. #define _ASM_DX __ASM_REG(dx)
  38. #define _ASM_SP __ASM_REG(sp)
  39. #define _ASM_BP __ASM_REG(bp)
  40. #define _ASM_SI __ASM_REG(si)
  41. #define _ASM_DI __ASM_REG(di)
  42. #ifndef __x86_64__
  43. /* 32 bit */
  44. #define _ASM_ARG1 _ASM_AX
  45. #define _ASM_ARG2 _ASM_DX
  46. #define _ASM_ARG3 _ASM_CX
  47. #define _ASM_ARG1L eax
  48. #define _ASM_ARG2L edx
  49. #define _ASM_ARG3L ecx
  50. #define _ASM_ARG1W ax
  51. #define _ASM_ARG2W dx
  52. #define _ASM_ARG3W cx
  53. #define _ASM_ARG1B al
  54. #define _ASM_ARG2B dl
  55. #define _ASM_ARG3B cl
  56. #else
  57. /* 64 bit */
  58. #define _ASM_ARG1 _ASM_DI
  59. #define _ASM_ARG2 _ASM_SI
  60. #define _ASM_ARG3 _ASM_DX
  61. #define _ASM_ARG4 _ASM_CX
  62. #define _ASM_ARG5 r8
  63. #define _ASM_ARG6 r9
  64. #define _ASM_ARG1Q rdi
  65. #define _ASM_ARG2Q rsi
  66. #define _ASM_ARG3Q rdx
  67. #define _ASM_ARG4Q rcx
  68. #define _ASM_ARG5Q r8
  69. #define _ASM_ARG6Q r9
  70. #define _ASM_ARG1L edi
  71. #define _ASM_ARG2L esi
  72. #define _ASM_ARG3L edx
  73. #define _ASM_ARG4L ecx
  74. #define _ASM_ARG5L r8d
  75. #define _ASM_ARG6L r9d
  76. #define _ASM_ARG1W di
  77. #define _ASM_ARG2W si
  78. #define _ASM_ARG3W dx
  79. #define _ASM_ARG4W cx
  80. #define _ASM_ARG5W r8w
  81. #define _ASM_ARG6W r9w
  82. #define _ASM_ARG1B dil
  83. #define _ASM_ARG2B sil
  84. #define _ASM_ARG3B dl
  85. #define _ASM_ARG4B cl
  86. #define _ASM_ARG5B r8b
  87. #define _ASM_ARG6B r9b
  88. #endif
  89. /*
  90. * Macros to generate condition code outputs from inline assembly,
  91. * The output operand must be type "bool".
  92. */
  93. #ifdef __GCC_ASM_FLAG_OUTPUTS__
  94. # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
  95. # define CC_OUT(c) "=@cc" #c
  96. #else
  97. # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
  98. # define CC_OUT(c) [_cc_ ## c] "=qm"
  99. #endif
  100. /* Exception table entry */
  101. #ifdef __ASSEMBLY__
  102. # define _ASM_EXTABLE_HANDLE(from, to, handler) \
  103. .pushsection "__ex_table","a" ; \
  104. .balign 4 ; \
  105. .long (from) - . ; \
  106. .long (to) - . ; \
  107. .long (handler) - . ; \
  108. .popsection
  109. # define _ASM_EXTABLE(from, to) \
  110. _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
  111. # define _ASM_EXTABLE_FAULT(from, to) \
  112. _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
  113. # define _ASM_EXTABLE_EX(from, to) \
  114. _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
  115. # define _ASM_EXTABLE_REFCOUNT(from, to) \
  116. _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
  117. # define _ASM_NOKPROBE(entry) \
  118. .pushsection "_kprobe_blacklist","aw" ; \
  119. _ASM_ALIGN ; \
  120. _ASM_PTR (entry); \
  121. .popsection
  122. .macro ALIGN_DESTINATION
  123. /* check for bad alignment of destination */
  124. movl %edi,%ecx
  125. andl $7,%ecx
  126. jz 102f /* already aligned */
  127. subl $8,%ecx
  128. negl %ecx
  129. subl %ecx,%edx
  130. 100: movb (%rsi),%al
  131. 101: movb %al,(%rdi)
  132. incq %rsi
  133. incq %rdi
  134. decl %ecx
  135. jnz 100b
  136. 102:
  137. .section .fixup,"ax"
  138. 103: addl %ecx,%edx /* ecx is zerorest also */
  139. jmp copy_user_handle_tail
  140. .previous
  141. _ASM_EXTABLE(100b,103b)
  142. _ASM_EXTABLE(101b,103b)
  143. .endm
  144. #else
  145. # define _EXPAND_EXTABLE_HANDLE(x) #x
  146. # define _ASM_EXTABLE_HANDLE(from, to, handler) \
  147. " .pushsection \"__ex_table\",\"a\"\n" \
  148. " .balign 4\n" \
  149. " .long (" #from ") - .\n" \
  150. " .long (" #to ") - .\n" \
  151. " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \
  152. " .popsection\n"
  153. # define _ASM_EXTABLE(from, to) \
  154. _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
  155. # define _ASM_EXTABLE_FAULT(from, to) \
  156. _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
  157. # define _ASM_EXTABLE_EX(from, to) \
  158. _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
  159. # define _ASM_EXTABLE_REFCOUNT(from, to) \
  160. _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
  161. /* For C file, we already have NOKPROBE_SYMBOL macro */
  162. #endif
  163. #ifndef __ASSEMBLY__
  164. /*
  165. * This output constraint should be used for any inline asm which has a "call"
  166. * instruction. Otherwise the asm may be inserted before the frame pointer
  167. * gets set up by the containing function. If you forget to do this, objtool
  168. * may print a "call without frame pointer save/setup" warning.
  169. */
  170. register unsigned long current_stack_pointer asm(_ASM_SP);
  171. #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
  172. #endif
  173. #endif /* _ASM_X86_ASM_H */