assembler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #define USER(l, x...) \
  85. 9999: x; \
  86. .section __ex_table,"a"; \
  87. .align 3; \
  88. .quad 9999b,l; \
  89. .previous
  90. /*
  91. * Register aliases.
  92. */
  93. lr .req x30 // link register
  94. /*
  95. * Vector entry
  96. */
  97. .macro ventry label
  98. .align 7
  99. b \label
  100. .endm
  101. /*
  102. * Select code when configured for BE.
  103. */
  104. #ifdef CONFIG_CPU_BIG_ENDIAN
  105. #define CPU_BE(code...) code
  106. #else
  107. #define CPU_BE(code...)
  108. #endif
  109. /*
  110. * Select code when configured for LE.
  111. */
  112. #ifdef CONFIG_CPU_BIG_ENDIAN
  113. #define CPU_LE(code...)
  114. #else
  115. #define CPU_LE(code...) code
  116. #endif
  117. /*
  118. * Define a macro that constructs a 64-bit value by concatenating two
  119. * 32-bit registers. Note that on big endian systems the order of the
  120. * registers is swapped.
  121. */
  122. #ifndef CONFIG_CPU_BIG_ENDIAN
  123. .macro regs_to_64, rd, lbits, hbits
  124. #else
  125. .macro regs_to_64, rd, hbits, lbits
  126. #endif
  127. orr \rd, \lbits, \hbits, lsl #32
  128. .endm
  129. /*
  130. * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
  131. * <symbol> is within the range +/- 4 GB of the PC.
  132. */
  133. /*
  134. * @dst: destination register (64 bit wide)
  135. * @sym: name of the symbol
  136. * @tmp: optional scratch register to be used if <dst> == sp, which
  137. * is not allowed in an adrp instruction
  138. */
  139. .macro adr_l, dst, sym, tmp=
  140. .ifb \tmp
  141. adrp \dst, \sym
  142. add \dst, \dst, :lo12:\sym
  143. .else
  144. adrp \tmp, \sym
  145. add \dst, \tmp, :lo12:\sym
  146. .endif
  147. .endm
  148. /*
  149. * @dst: destination register (32 or 64 bit wide)
  150. * @sym: name of the symbol
  151. * @tmp: optional 64-bit scratch register to be used if <dst> is a
  152. * 32-bit wide register, in which case it cannot be used to hold
  153. * the address
  154. */
  155. .macro ldr_l, dst, sym, tmp=
  156. .ifb \tmp
  157. adrp \dst, \sym
  158. ldr \dst, [\dst, :lo12:\sym]
  159. .else
  160. adrp \tmp, \sym
  161. ldr \dst, [\tmp, :lo12:\sym]
  162. .endif
  163. .endm
  164. /*
  165. * @src: source register (32 or 64 bit wide)
  166. * @sym: name of the symbol
  167. * @tmp: mandatory 64-bit scratch register to calculate the address
  168. * while <src> needs to be preserved.
  169. */
  170. .macro str_l, src, sym, tmp
  171. adrp \tmp, \sym
  172. str \src, [\tmp, :lo12:\sym]
  173. .endm
  174. #endif /* __ASM_ASSEMBLER_H */