asm.h 4.9 KB

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