assembler.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * arch/arm/include/asm/assembler.h
  3. *
  4. * Copyright (C) 1996-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This file contains arm architecture specific defines
  11. * for the different processors.
  12. *
  13. * Do not include any C declarations in this file - it is included by
  14. * assembler source.
  15. */
  16. #ifndef __ASSEMBLY__
  17. #error "Only include this from assembly code"
  18. #endif
  19. #include <asm/ptrace.h>
  20. /*
  21. * Endian independent macros for shifting bytes within registers.
  22. */
  23. #ifndef __ARMEB__
  24. #define pull lsr
  25. #define push lsl
  26. #define get_byte_0 lsl #0
  27. #define get_byte_1 lsr #8
  28. #define get_byte_2 lsr #16
  29. #define get_byte_3 lsr #24
  30. #define put_byte_0 lsl #0
  31. #define put_byte_1 lsl #8
  32. #define put_byte_2 lsl #16
  33. #define put_byte_3 lsl #24
  34. #else
  35. #define pull lsl
  36. #define push lsr
  37. #define get_byte_0 lsr #24
  38. #define get_byte_1 lsr #16
  39. #define get_byte_2 lsr #8
  40. #define get_byte_3 lsl #0
  41. #define put_byte_0 lsl #24
  42. #define put_byte_1 lsl #16
  43. #define put_byte_2 lsl #8
  44. #define put_byte_3 lsl #0
  45. #endif
  46. /*
  47. * Data preload for architectures that support it
  48. */
  49. #if __LINUX_ARM_ARCH__ >= 5
  50. #define PLD(code...) code
  51. #else
  52. #define PLD(code...)
  53. #endif
  54. /*
  55. * This can be used to enable code to cacheline align the destination
  56. * pointer when bulk writing to memory. Experiments on StrongARM and
  57. * XScale didn't show this a worthwhile thing to do when the cache is not
  58. * set to write-allocate (this would need further testing on XScale when WA
  59. * is used).
  60. *
  61. * On Feroceon there is much to gain however, regardless of cache mode.
  62. */
  63. #ifdef CONFIG_CPU_FEROCEON
  64. #define CALGN(code...) code
  65. #else
  66. #define CALGN(code...)
  67. #endif
  68. /*
  69. * Enable and disable interrupts
  70. */
  71. #if __LINUX_ARM_ARCH__ >= 6
  72. .macro disable_irq
  73. cpsid i
  74. .endm
  75. .macro enable_irq
  76. cpsie i
  77. .endm
  78. #else
  79. .macro disable_irq
  80. msr cpsr_c, #PSR_I_BIT | SVC_MODE
  81. .endm
  82. .macro enable_irq
  83. msr cpsr_c, #SVC_MODE
  84. .endm
  85. #endif
  86. /*
  87. * Save the current IRQ state and disable IRQs. Note that this macro
  88. * assumes FIQs are enabled, and that the processor is in SVC mode.
  89. */
  90. .macro save_and_disable_irqs, oldcpsr
  91. mrs \oldcpsr, cpsr
  92. disable_irq
  93. .endm
  94. /*
  95. * Restore interrupt state previously stored in a register. We don't
  96. * guarantee that this will preserve the flags.
  97. */
  98. .macro restore_irqs, oldcpsr
  99. msr cpsr_c, \oldcpsr
  100. .endm
  101. #define USER(x...) \
  102. 9999: x; \
  103. .section __ex_table,"a"; \
  104. .align 3; \
  105. .long 9999b,9001f; \
  106. .previous
  107. /*
  108. * SMP data memory barrier
  109. */
  110. .macro smp_dmb
  111. #ifdef CONFIG_SMP
  112. #if __LINUX_ARM_ARCH__ >= 7
  113. dmb
  114. #elif __LINUX_ARM_ARCH__ == 6
  115. mcr p15, 0, r0, c7, c10, 5 @ dmb
  116. #endif
  117. #endif
  118. .endm
  119. #ifdef CONFIG_THUMB2_KERNEL
  120. .macro setmode, mode, reg
  121. mov \reg, #\mode
  122. msr cpsr_c, \reg
  123. .endm
  124. #else
  125. .macro setmode, mode, reg
  126. msr cpsr_c, #\mode
  127. .endm
  128. #endif
  129. /*
  130. * STRT/LDRT access macros with ARM and Thumb-2 variants
  131. */
  132. #ifdef CONFIG_THUMB2_KERNEL
  133. .macro usraccoff, instr, reg, ptr, inc, off, cond, abort
  134. 9999:
  135. .if \inc == 1
  136. \instr\cond\()bt \reg, [\ptr, #\off]
  137. .elseif \inc == 4
  138. \instr\cond\()t \reg, [\ptr, #\off]
  139. .else
  140. .error "Unsupported inc macro argument"
  141. .endif
  142. .section __ex_table,"a"
  143. .align 3
  144. .long 9999b, \abort
  145. .previous
  146. .endm
  147. .macro usracc, instr, reg, ptr, inc, cond, rept, abort
  148. @ explicit IT instruction needed because of the label
  149. @ introduced by the USER macro
  150. .ifnc \cond,al
  151. .if \rept == 1
  152. itt \cond
  153. .elseif \rept == 2
  154. ittt \cond
  155. .else
  156. .error "Unsupported rept macro argument"
  157. .endif
  158. .endif
  159. @ Slightly optimised to avoid incrementing the pointer twice
  160. usraccoff \instr, \reg, \ptr, \inc, 0, \cond, \abort
  161. .if \rept == 2
  162. usraccoff \instr, \reg, \ptr, \inc, 4, \cond, \abort
  163. .endif
  164. add\cond \ptr, #\rept * \inc
  165. .endm
  166. #else /* !CONFIG_THUMB2_KERNEL */
  167. .macro usracc, instr, reg, ptr, inc, cond, rept, abort
  168. .rept \rept
  169. 9999:
  170. .if \inc == 1
  171. \instr\cond\()bt \reg, [\ptr], #\inc
  172. .elseif \inc == 4
  173. \instr\cond\()t \reg, [\ptr], #\inc
  174. .else
  175. .error "Unsupported inc macro argument"
  176. .endif
  177. .section __ex_table,"a"
  178. .align 3
  179. .long 9999b, \abort
  180. .previous
  181. .endr
  182. .endm
  183. #endif /* CONFIG_THUMB2_KERNEL */
  184. .macro strusr, reg, ptr, inc, cond=al, rept=1, abort=9001f
  185. usracc str, \reg, \ptr, \inc, \cond, \rept, \abort
  186. .endm
  187. .macro ldrusr, reg, ptr, inc, cond=al, rept=1, abort=9001f
  188. usracc ldr, \reg, \ptr, \inc, \cond, \rept, \abort
  189. .endm