asm.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Some useful macros for LoongArch assembler code
  4. *
  5. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  6. *
  7. * Derived from MIPS:
  8. * Copyright (C) 1995, 1996, 1997, 1999, 2001 by Ralf Baechle
  9. * Copyright (C) 1999 by Silicon Graphics, Inc.
  10. * Copyright (C) 2001 MIPS Technologies, Inc.
  11. * Copyright (C) 2002 Maciej W. Rozycki
  12. */
  13. #ifndef __ASM_ASM_H
  14. #define __ASM_ASM_H
  15. /* LoongArch pref instruction. */
  16. #ifdef CONFIG_CPU_HAS_PREFETCH
  17. #define PREF(hint, addr, offs) \
  18. preld hint, addr, offs; \
  19. #define PREFX(hint, addr, index) \
  20. preldx hint, addr, index; \
  21. #else /* !CONFIG_CPU_HAS_PREFETCH */
  22. #define PREF(hint, addr, offs)
  23. #define PREFX(hint, addr, index)
  24. #endif /* !CONFIG_CPU_HAS_PREFETCH */
  25. /*
  26. * Stack alignment
  27. */
  28. #define STACK_ALIGN ~(0xf)
  29. /*
  30. * Macros to handle different pointer/register sizes for 32/64-bit code
  31. */
  32. /*
  33. * Size of a register
  34. */
  35. #ifndef __loongarch64
  36. #define SZREG 4
  37. #else
  38. #define SZREG 8
  39. #endif
  40. /*
  41. * Use the following macros in assemblercode to load/store registers,
  42. * pointers etc.
  43. */
  44. #if (SZREG == 4)
  45. #define REG_L ld.w
  46. #define REG_S st.w
  47. #define REG_ADD add.w
  48. #define REG_SUB sub.w
  49. #else /* SZREG == 8 */
  50. #define REG_L ld.d
  51. #define REG_S st.d
  52. #define REG_ADD add.d
  53. #define REG_SUB sub.d
  54. #endif
  55. /*
  56. * How to add/sub/load/store/shift C int variables.
  57. */
  58. #if (__SIZEOF_INT__ == 4)
  59. #define INT_ADD add.w
  60. #define INT_ADDI addi.w
  61. #define INT_SUB sub.w
  62. #define INT_L ld.w
  63. #define INT_S st.w
  64. #define INT_SLLI slli.w
  65. #define INT_SLLV sll.w
  66. #define INT_SRLI srli.w
  67. #define INT_SRLV srl.w
  68. #define INT_SRAI srai.w
  69. #define INT_SRAV sra.w
  70. #endif
  71. #if (__SIZEOF_INT__ == 8)
  72. #define INT_ADD add.d
  73. #define INT_ADDI addi.d
  74. #define INT_SUB sub.d
  75. #define INT_L ld.d
  76. #define INT_S st.d
  77. #define INT_SLLI slli.d
  78. #define INT_SLLV sll.d
  79. #define INT_SRLI srli.d
  80. #define INT_SRLV srl.d
  81. #define INT_SRAI srai.d
  82. #define INT_SRAV sra.d
  83. #endif
  84. /*
  85. * How to add/sub/load/store/shift C long variables.
  86. */
  87. #if (__SIZEOF_LONG__ == 4)
  88. #define LONG_ADD add.w
  89. #define LONG_ADDI addi.w
  90. #define LONG_ALSL alsl.w
  91. #define LONG_BSTRINS bstrins.w
  92. #define LONG_BSTRPICK bstrpick.w
  93. #define LONG_SUB sub.w
  94. #define LONG_L ld.w
  95. #define LONG_LI li.w
  96. #define LONG_LPTR ld.w
  97. #define LONG_S st.w
  98. #define LONG_SPTR st.w
  99. #define LONG_SLLI slli.w
  100. #define LONG_SLLV sll.w
  101. #define LONG_SRLI srli.w
  102. #define LONG_SRLV srl.w
  103. #define LONG_SRAI srai.w
  104. #define LONG_SRAV sra.w
  105. #define LONG_ROTR rotr.w
  106. #define LONG_ROTRI rotri.w
  107. #ifdef __ASSEMBLER__
  108. #define LONG .word
  109. #endif
  110. #define LONGSIZE 4
  111. #define LONGMASK 3
  112. #define LONGLOG 2
  113. #endif
  114. #if (__SIZEOF_LONG__ == 8)
  115. #define LONG_ADD add.d
  116. #define LONG_ADDI addi.d
  117. #define LONG_ALSL alsl.d
  118. #define LONG_BSTRINS bstrins.d
  119. #define LONG_BSTRPICK bstrpick.d
  120. #define LONG_SUB sub.d
  121. #define LONG_L ld.d
  122. #define LONG_LI li.d
  123. #define LONG_LPTR ldptr.d
  124. #define LONG_S st.d
  125. #define LONG_SPTR stptr.d
  126. #define LONG_SLLI slli.d
  127. #define LONG_SLLV sll.d
  128. #define LONG_SRLI srli.d
  129. #define LONG_SRLV srl.d
  130. #define LONG_SRAI srai.d
  131. #define LONG_SRAV sra.d
  132. #define LONG_ROTR rotr.d
  133. #define LONG_ROTRI rotri.d
  134. #ifdef __ASSEMBLER__
  135. #define LONG .dword
  136. #endif
  137. #define LONGSIZE 8
  138. #define LONGMASK 7
  139. #define LONGLOG 3
  140. #endif
  141. /*
  142. * How to add/sub/load/store/shift pointers.
  143. */
  144. #if (__SIZEOF_POINTER__ == 4)
  145. #define PTR_ADD add.w
  146. #define PTR_ADDI addi.w
  147. #define PTR_ALSL alsl.w
  148. #define PTR_BSTRINS bstrins.w
  149. #define PTR_BSTRPICK bstrpick.w
  150. #define PTR_SUB sub.w
  151. #define PTR_L ld.w
  152. #define PTR_LI li.w
  153. #define PTR_LPTR ld.w
  154. #define PTR_S st.w
  155. #define PTR_SPTR st.w
  156. #define PTR_SLLI slli.w
  157. #define PTR_SLLV sll.w
  158. #define PTR_SRLI srli.w
  159. #define PTR_SRLV srl.w
  160. #define PTR_SRAI srai.w
  161. #define PTR_SRAV sra.w
  162. #define PTR_ROTR rotr.w
  163. #define PTR_ROTRI rotri.w
  164. #define PTR_SCALESHIFT 2
  165. #ifdef __ASSEMBLER__
  166. #define PTR .word
  167. #endif
  168. #define PTRSIZE 4
  169. #define PTRLOG 2
  170. #endif
  171. #if (__SIZEOF_POINTER__ == 8)
  172. #define PTR_ADD add.d
  173. #define PTR_ADDI addi.d
  174. #define PTR_ALSL alsl.d
  175. #define PTR_BSTRINS bstrins.d
  176. #define PTR_BSTRPICK bstrpick.d
  177. #define PTR_SUB sub.d
  178. #define PTR_L ld.d
  179. #define PTR_LI li.d
  180. #define PTR_LPTR ldptr.d
  181. #define PTR_S st.d
  182. #define PTR_SPTR stptr.d
  183. #define PTR_SLLI slli.d
  184. #define PTR_SLLV sll.d
  185. #define PTR_SRLI srli.d
  186. #define PTR_SRLV srl.d
  187. #define PTR_SRAI srai.d
  188. #define PTR_SRAV sra.d
  189. #define PTR_ROTR rotr.d
  190. #define PTR_ROTRI rotri.d
  191. #define PTR_SCALESHIFT 3
  192. #ifdef __ASSEMBLER__
  193. #define PTR .dword
  194. #endif
  195. #define PTRSIZE 8
  196. #define PTRLOG 3
  197. #endif
  198. /* Annotate a function as being unsuitable for kprobes. */
  199. #ifdef CONFIG_KPROBES
  200. #ifdef CONFIG_32BIT
  201. #define _ASM_NOKPROBE(name) \
  202. .pushsection "_kprobe_blacklist", "aw"; \
  203. .long name; \
  204. .popsection
  205. #else
  206. #define _ASM_NOKPROBE(name) \
  207. .pushsection "_kprobe_blacklist", "aw"; \
  208. .quad name; \
  209. .popsection
  210. #endif
  211. #else
  212. #define _ASM_NOKPROBE(name)
  213. #endif
  214. #endif /* __ASM_ASM_H */