asm.h 3.8 KB

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