assembler.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * Save/disable and restore interrupts.
  47. */
  48. .macro save_and_disable_irqs, olddaif
  49. mrs \olddaif, daif
  50. disable_irq
  51. .endm
  52. .macro restore_irqs, olddaif
  53. msr daif, \olddaif
  54. .endm
  55. /*
  56. * Enable and disable debug exceptions.
  57. */
  58. .macro disable_dbg
  59. msr daifset, #8
  60. .endm
  61. .macro enable_dbg
  62. msr daifclr, #8
  63. .endm
  64. .macro disable_step_tsk, flgs, tmp
  65. tbz \flgs, #TIF_SINGLESTEP, 9990f
  66. mrs \tmp, mdscr_el1
  67. bic \tmp, \tmp, #1
  68. msr mdscr_el1, \tmp
  69. isb // Synchronise with enable_dbg
  70. 9990:
  71. .endm
  72. .macro enable_step_tsk, flgs, tmp
  73. tbz \flgs, #TIF_SINGLESTEP, 9990f
  74. disable_dbg
  75. mrs \tmp, mdscr_el1
  76. orr \tmp, \tmp, #1
  77. msr mdscr_el1, \tmp
  78. 9990:
  79. .endm
  80. /*
  81. * Enable both debug exceptions and interrupts. This is likely to be
  82. * faster than two daifclr operations, since writes to this register
  83. * are self-synchronising.
  84. */
  85. .macro enable_dbg_and_irq
  86. msr daifclr, #(8 | 2)
  87. .endm
  88. /*
  89. * SMP data memory barrier
  90. */
  91. .macro smp_dmb, opt
  92. #ifdef CONFIG_SMP
  93. dmb \opt
  94. #endif
  95. .endm
  96. #define USER(l, x...) \
  97. 9999: x; \
  98. .section __ex_table,"a"; \
  99. .align 3; \
  100. .quad 9999b,l; \
  101. .previous
  102. /*
  103. * Register aliases.
  104. */
  105. lr .req x30 // link register
  106. /*
  107. * Vector entry
  108. */
  109. .macro ventry label
  110. .align 7
  111. b \label
  112. .endm
  113. /*
  114. * Select code when configured for BE.
  115. */
  116. #ifdef CONFIG_CPU_BIG_ENDIAN
  117. #define CPU_BE(code...) code
  118. #else
  119. #define CPU_BE(code...)
  120. #endif
  121. /*
  122. * Select code when configured for LE.
  123. */
  124. #ifdef CONFIG_CPU_BIG_ENDIAN
  125. #define CPU_LE(code...)
  126. #else
  127. #define CPU_LE(code...) code
  128. #endif
  129. /*
  130. * Define a macro that constructs a 64-bit value by concatenating two
  131. * 32-bit registers. Note that on big endian systems the order of the
  132. * registers is swapped.
  133. */
  134. #ifndef CONFIG_CPU_BIG_ENDIAN
  135. .macro regs_to_64, rd, lbits, hbits
  136. #else
  137. .macro regs_to_64, rd, hbits, lbits
  138. #endif
  139. orr \rd, \lbits, \hbits, lsl #32
  140. .endm
  141. #endif /* __ASM_ASSEMBLER_H */