assembler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Based on arch/arm/include/asm/assembler.h
  3. *
  4. * Copyright (C) 1996-2000 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASSEMBLY__
  20. #error "Only include this from assembly code"
  21. #endif
  22. #ifndef __ASM_ASSEMBLER_H
  23. #define __ASM_ASSEMBLER_H
  24. #include <asm/ptrace.h>
  25. #include <asm/thread_info.h>
  26. /*
  27. * Stack pushing/popping (register pairs only). Equivalent to store decrement
  28. * before, load increment after.
  29. */
  30. .macro push, xreg1, xreg2
  31. stp \xreg1, \xreg2, [sp, #-16]!
  32. .endm
  33. .macro pop, xreg1, xreg2
  34. ldp \xreg1, \xreg2, [sp], #16
  35. .endm
  36. /*
  37. * Enable and disable interrupts.
  38. */
  39. .macro disable_irq
  40. msr daifset, #2
  41. .endm
  42. .macro enable_irq
  43. msr daifclr, #2
  44. .endm
  45. /*
  46. * Enable and disable debug exceptions.
  47. */
  48. .macro disable_dbg
  49. msr daifset, #8
  50. .endm
  51. .macro enable_dbg
  52. msr daifclr, #8
  53. .endm
  54. .macro disable_step_tsk, flgs, tmp
  55. tbz \flgs, #TIF_SINGLESTEP, 9990f
  56. mrs \tmp, mdscr_el1
  57. bic \tmp, \tmp, #1
  58. msr mdscr_el1, \tmp
  59. isb // Synchronise with enable_dbg
  60. 9990:
  61. .endm
  62. .macro enable_step_tsk, flgs, tmp
  63. tbz \flgs, #TIF_SINGLESTEP, 9990f
  64. disable_dbg
  65. mrs \tmp, mdscr_el1
  66. orr \tmp, \tmp, #1
  67. msr mdscr_el1, \tmp
  68. 9990:
  69. .endm
  70. /*
  71. * Enable both debug exceptions and interrupts. This is likely to be
  72. * faster than two daifclr operations, since writes to this register
  73. * are self-synchronising.
  74. */
  75. .macro enable_dbg_and_irq
  76. msr daifclr, #(8 | 2)
  77. .endm
  78. /*
  79. * SMP data memory barrier
  80. */
  81. .macro smp_dmb, opt
  82. dmb \opt
  83. .endm
  84. /*
  85. * Emit an entry into the exception table
  86. */
  87. .macro _asm_extable, from, to
  88. .pushsection __ex_table, "a"
  89. .align 3
  90. .long (\from - .), (\to - .)
  91. .popsection
  92. .endm
  93. #define USER(l, x...) \
  94. 9999: x; \
  95. _asm_extable 9999b, l
  96. /*
  97. * Register aliases.
  98. */
  99. lr .req x30 // link register
  100. /*
  101. * Vector entry
  102. */
  103. .macro ventry label
  104. .align 7
  105. b \label
  106. .endm
  107. /*
  108. * Select code when configured for BE.
  109. */
  110. #ifdef CONFIG_CPU_BIG_ENDIAN
  111. #define CPU_BE(code...) code
  112. #else
  113. #define CPU_BE(code...)
  114. #endif
  115. /*
  116. * Select code when configured for LE.
  117. */
  118. #ifdef CONFIG_CPU_BIG_ENDIAN
  119. #define CPU_LE(code...)
  120. #else
  121. #define CPU_LE(code...) code
  122. #endif
  123. /*
  124. * Define a macro that constructs a 64-bit value by concatenating two
  125. * 32-bit registers. Note that on big endian systems the order of the
  126. * registers is swapped.
  127. */
  128. #ifndef CONFIG_CPU_BIG_ENDIAN
  129. .macro regs_to_64, rd, lbits, hbits
  130. #else
  131. .macro regs_to_64, rd, hbits, lbits
  132. #endif
  133. orr \rd, \lbits, \hbits, lsl #32
  134. .endm
  135. /*
  136. * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
  137. * <symbol> is within the range +/- 4 GB of the PC.
  138. */
  139. /*
  140. * @dst: destination register (64 bit wide)
  141. * @sym: name of the symbol
  142. * @tmp: optional scratch register to be used if <dst> == sp, which
  143. * is not allowed in an adrp instruction
  144. */
  145. .macro adr_l, dst, sym, tmp=
  146. .ifb \tmp
  147. adrp \dst, \sym
  148. add \dst, \dst, :lo12:\sym
  149. .else
  150. adrp \tmp, \sym
  151. add \dst, \tmp, :lo12:\sym
  152. .endif
  153. .endm
  154. /*
  155. * @dst: destination register (32 or 64 bit wide)
  156. * @sym: name of the symbol
  157. * @tmp: optional 64-bit scratch register to be used if <dst> is a
  158. * 32-bit wide register, in which case it cannot be used to hold
  159. * the address
  160. */
  161. .macro ldr_l, dst, sym, tmp=
  162. .ifb \tmp
  163. adrp \dst, \sym
  164. ldr \dst, [\dst, :lo12:\sym]
  165. .else
  166. adrp \tmp, \sym
  167. ldr \dst, [\tmp, :lo12:\sym]
  168. .endif
  169. .endm
  170. /*
  171. * @src: source register (32 or 64 bit wide)
  172. * @sym: name of the symbol
  173. * @tmp: mandatory 64-bit scratch register to calculate the address
  174. * while <src> needs to be preserved.
  175. */
  176. .macro str_l, src, sym, tmp
  177. adrp \tmp, \sym
  178. str \src, [\tmp, :lo12:\sym]
  179. .endm
  180. /*
  181. * @sym: The name of the per-cpu variable
  182. * @reg: Result of per_cpu(sym, smp_processor_id())
  183. * @tmp: scratch register
  184. */
  185. .macro this_cpu_ptr, sym, reg, tmp
  186. adr_l \reg, \sym
  187. mrs \tmp, tpidr_el1
  188. add \reg, \reg, \tmp
  189. .endm
  190. /*
  191. * Annotate a function as position independent, i.e., safe to be called before
  192. * the kernel virtual mapping is activated.
  193. */
  194. #define ENDPIPROC(x) \
  195. .globl __pi_##x; \
  196. .type __pi_##x, %function; \
  197. .set __pi_##x, x; \
  198. .size __pi_##x, . - x; \
  199. ENDPROC(x)
  200. /*
  201. * Emit a 64-bit absolute little endian symbol reference in a way that
  202. * ensures that it will be resolved at build time, even when building a
  203. * PIE binary. This requires cooperation from the linker script, which
  204. * must emit the lo32/hi32 halves individually.
  205. */
  206. .macro le64sym, sym
  207. .long \sym\()_lo32
  208. .long \sym\()_hi32
  209. .endm
  210. #endif /* __ASM_ASSEMBLER_H */