assembler.h 3.0 KB

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