asm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /*
  43. * Macros to generate condition code outputs from inline assembly,
  44. * The output operand must be type "bool".
  45. */
  46. #ifdef __GCC_ASM_FLAG_OUTPUTS__
  47. # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
  48. # define CC_OUT(c) "=@cc" #c
  49. #else
  50. # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
  51. # define CC_OUT(c) [_cc_ ## c] "=qm"
  52. #endif
  53. /* Exception table entry */
  54. #ifdef __ASSEMBLY__
  55. # define _ASM_EXTABLE_HANDLE(from, to, handler) \
  56. .pushsection "__ex_table","a" ; \
  57. .balign 4 ; \
  58. .long (from) - . ; \
  59. .long (to) - . ; \
  60. .long (handler) - . ; \
  61. .popsection
  62. # define _ASM_EXTABLE(from, to) \
  63. _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
  64. # define _ASM_EXTABLE_FAULT(from, to) \
  65. _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
  66. # define _ASM_EXTABLE_EX(from, to) \
  67. _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
  68. # define _ASM_EXTABLE_REFCOUNT(from, to) \
  69. _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
  70. # define _ASM_NOKPROBE(entry) \
  71. .pushsection "_kprobe_blacklist","aw" ; \
  72. _ASM_ALIGN ; \
  73. _ASM_PTR (entry); \
  74. .popsection
  75. .macro ALIGN_DESTINATION
  76. /* check for bad alignment of destination */
  77. movl %edi,%ecx
  78. andl $7,%ecx
  79. jz 102f /* already aligned */
  80. subl $8,%ecx
  81. negl %ecx
  82. subl %ecx,%edx
  83. 100: movb (%rsi),%al
  84. 101: movb %al,(%rdi)
  85. incq %rsi
  86. incq %rdi
  87. decl %ecx
  88. jnz 100b
  89. 102:
  90. .section .fixup,"ax"
  91. 103: addl %ecx,%edx /* ecx is zerorest also */
  92. jmp copy_user_handle_tail
  93. .previous
  94. _ASM_EXTABLE(100b,103b)
  95. _ASM_EXTABLE(101b,103b)
  96. .endm
  97. #else
  98. # define _EXPAND_EXTABLE_HANDLE(x) #x
  99. # define _ASM_EXTABLE_HANDLE(from, to, handler) \
  100. " .pushsection \"__ex_table\",\"a\"\n" \
  101. " .balign 4\n" \
  102. " .long (" #from ") - .\n" \
  103. " .long (" #to ") - .\n" \
  104. " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \
  105. " .popsection\n"
  106. # define _ASM_EXTABLE(from, to) \
  107. _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
  108. # define _ASM_EXTABLE_FAULT(from, to) \
  109. _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
  110. # define _ASM_EXTABLE_EX(from, to) \
  111. _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
  112. # define _ASM_EXTABLE_REFCOUNT(from, to) \
  113. _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
  114. /* For C file, we already have NOKPROBE_SYMBOL macro */
  115. #endif
  116. #ifndef __ASSEMBLY__
  117. /*
  118. * This output constraint should be used for any inline asm which has a "call"
  119. * instruction. Otherwise the asm may be inserted before the frame pointer
  120. * gets set up by the containing function. If you forget to do this, objtool
  121. * may print a "call without frame pointer save/setup" warning.
  122. */
  123. register unsigned long current_stack_pointer asm(_ASM_SP);
  124. #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
  125. #endif
  126. #endif /* _ASM_X86_ASM_H */