asm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef _ASM_X86_ASM_H
  2. #define _ASM_X86_ASM_H
  3. #ifdef __ASSEMBLY__
  4. # define __ASM_FORM(x) x
  5. # define __ASM_FORM_RAW(x) x
  6. # define __ASM_FORM_COMMA(x) x,
  7. #else
  8. # define __ASM_FORM(x) " " #x " "
  9. # define __ASM_FORM_RAW(x) #x
  10. # define __ASM_FORM_COMMA(x) " " #x ","
  11. #endif
  12. #ifndef __x86_64__
  13. /* 32 bit */
  14. # define __ASM_SEL(a,b) __ASM_FORM(a)
  15. # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
  16. #else
  17. /* 64 bit */
  18. # define __ASM_SEL(a,b) __ASM_FORM(b)
  19. # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
  20. #endif
  21. #define __ASM_SIZE(inst, ...) __ASM_SEL(inst##l##__VA_ARGS__, \
  22. inst##q##__VA_ARGS__)
  23. #define __ASM_REG(reg) __ASM_SEL_RAW(e##reg, r##reg)
  24. #define _ASM_PTR __ASM_SEL(.long, .quad)
  25. #define _ASM_ALIGN __ASM_SEL(.balign 4, .balign 8)
  26. #define _ASM_MOV __ASM_SIZE(mov)
  27. #define _ASM_INC __ASM_SIZE(inc)
  28. #define _ASM_DEC __ASM_SIZE(dec)
  29. #define _ASM_ADD __ASM_SIZE(add)
  30. #define _ASM_SUB __ASM_SIZE(sub)
  31. #define _ASM_XADD __ASM_SIZE(xadd)
  32. #define _ASM_MUL __ASM_SIZE(mul)
  33. #define _ASM_AX __ASM_REG(ax)
  34. #define _ASM_BX __ASM_REG(bx)
  35. #define _ASM_CX __ASM_REG(cx)
  36. #define _ASM_DX __ASM_REG(dx)
  37. #define _ASM_SP __ASM_REG(sp)
  38. #define _ASM_BP __ASM_REG(bp)
  39. #define _ASM_SI __ASM_REG(si)
  40. #define _ASM_DI __ASM_REG(di)
  41. /*
  42. * Macros to generate condition code outputs from inline assembly,
  43. * The output operand must be type "bool".
  44. */
  45. #ifdef __GCC_ASM_FLAG_OUTPUTS__
  46. # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
  47. # define CC_OUT(c) "=@cc" #c
  48. #else
  49. # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
  50. # define CC_OUT(c) [_cc_ ## c] "=qm"
  51. #endif
  52. /* Exception table entry */
  53. #ifdef __ASSEMBLY__
  54. # define _ASM_EXTABLE_HANDLE(from, to, handler) \
  55. .pushsection "__ex_table","a" ; \
  56. .balign 4 ; \
  57. .long (from) - . ; \
  58. .long (to) - . ; \
  59. .long (handler) - . ; \
  60. .popsection
  61. # define _ASM_EXTABLE(from, to) \
  62. _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
  63. # define _ASM_EXTABLE_FAULT(from, to) \
  64. _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
  65. # define _ASM_EXTABLE_EX(from, to) \
  66. _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
  67. # define _ASM_EXTABLE_REFCOUNT(from, to) \
  68. _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
  69. # define _ASM_NOKPROBE(entry) \
  70. .pushsection "_kprobe_blacklist","aw" ; \
  71. _ASM_ALIGN ; \
  72. _ASM_PTR (entry); \
  73. .popsection
  74. .macro ALIGN_DESTINATION
  75. /* check for bad alignment of destination */
  76. movl %edi,%ecx
  77. andl $7,%ecx
  78. jz 102f /* already aligned */
  79. subl $8,%ecx
  80. negl %ecx
  81. subl %ecx,%edx
  82. 100: movb (%rsi),%al
  83. 101: movb %al,(%rdi)
  84. incq %rsi
  85. incq %rdi
  86. decl %ecx
  87. jnz 100b
  88. 102:
  89. .section .fixup,"ax"
  90. 103: addl %ecx,%edx /* ecx is zerorest also */
  91. jmp copy_user_handle_tail
  92. .previous
  93. _ASM_EXTABLE(100b,103b)
  94. _ASM_EXTABLE(101b,103b)
  95. .endm
  96. #else
  97. # define _EXPAND_EXTABLE_HANDLE(x) #x
  98. # define _ASM_EXTABLE_HANDLE(from, to, handler) \
  99. " .pushsection \"__ex_table\",\"a\"\n" \
  100. " .balign 4\n" \
  101. " .long (" #from ") - .\n" \
  102. " .long (" #to ") - .\n" \
  103. " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \
  104. " .popsection\n"
  105. # define _ASM_EXTABLE(from, to) \
  106. _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
  107. # define _ASM_EXTABLE_FAULT(from, to) \
  108. _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
  109. # define _ASM_EXTABLE_EX(from, to) \
  110. _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
  111. # define _ASM_EXTABLE_REFCOUNT(from, to) \
  112. _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
  113. /* For C file, we already have NOKPROBE_SYMBOL macro */
  114. #endif
  115. #ifndef __ASSEMBLY__
  116. /*
  117. * This output constraint should be used for any inline asm which has a "call"
  118. * instruction. Otherwise the asm may be inserted before the frame pointer
  119. * gets set up by the containing function. If you forget to do this, objtool
  120. * may print a "call without frame pointer save/setup" warning.
  121. */
  122. register unsigned long current_stack_pointer asm(_ASM_SP);
  123. #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
  124. #endif
  125. #endif /* _ASM_X86_ASM_H */