assembler.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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_notrace
  73. cpsid i
  74. .endm
  75. .macro enable_irq_notrace
  76. cpsie i
  77. .endm
  78. #else
  79. .macro disable_irq_notrace
  80. msr cpsr_c, #PSR_I_BIT | SVC_MODE
  81. .endm
  82. .macro enable_irq_notrace
  83. msr cpsr_c, #SVC_MODE
  84. .endm
  85. #endif
  86. .macro asm_trace_hardirqs_off
  87. #if defined(CONFIG_TRACE_IRQFLAGS)
  88. stmdb sp!, {r0-r3, ip, lr}
  89. bl trace_hardirqs_off
  90. ldmia sp!, {r0-r3, ip, lr}
  91. #endif
  92. .endm
  93. .macro asm_trace_hardirqs_on_cond, cond
  94. #if defined(CONFIG_TRACE_IRQFLAGS)
  95. /*
  96. * actually the registers should be pushed and pop'd conditionally, but
  97. * after bl the flags are certainly clobbered
  98. */
  99. stmdb sp!, {r0-r3, ip, lr}
  100. bl\cond trace_hardirqs_on
  101. ldmia sp!, {r0-r3, ip, lr}
  102. #endif
  103. .endm
  104. .macro asm_trace_hardirqs_on
  105. asm_trace_hardirqs_on_cond al
  106. .endm
  107. .macro disable_irq
  108. disable_irq_notrace
  109. asm_trace_hardirqs_off
  110. .endm
  111. .macro enable_irq
  112. asm_trace_hardirqs_on
  113. enable_irq_notrace
  114. .endm
  115. /*
  116. * Save the current IRQ state and disable IRQs. Note that this macro
  117. * assumes FIQs are enabled, and that the processor is in SVC mode.
  118. */
  119. .macro save_and_disable_irqs, oldcpsr
  120. mrs \oldcpsr, cpsr
  121. disable_irq
  122. .endm
  123. /*
  124. * Restore interrupt state previously stored in a register. We don't
  125. * guarantee that this will preserve the flags.
  126. */
  127. .macro restore_irqs_notrace, oldcpsr
  128. msr cpsr_c, \oldcpsr
  129. .endm
  130. .macro restore_irqs, oldcpsr
  131. tst \oldcpsr, #PSR_I_BIT
  132. asm_trace_hardirqs_on_cond eq
  133. restore_irqs_notrace \oldcpsr
  134. .endm
  135. #define USER(x...) \
  136. 9999: x; \
  137. .pushsection __ex_table,"a"; \
  138. .align 3; \
  139. .long 9999b,9001f; \
  140. .popsection
  141. #ifdef CONFIG_SMP
  142. #define ALT_SMP(instr...) \
  143. 9998: instr
  144. /*
  145. * Note: if you get assembler errors from ALT_UP() when building with
  146. * CONFIG_THUMB2_KERNEL, you almost certainly need to use
  147. * ALT_SMP( W(instr) ... )
  148. */
  149. #define ALT_UP(instr...) \
  150. .pushsection ".alt.smp.init", "a" ;\
  151. .long 9998b ;\
  152. 9997: instr ;\
  153. .if . - 9997b != 4 ;\
  154. .error "ALT_UP() content must assemble to exactly 4 bytes";\
  155. .endif ;\
  156. .popsection
  157. #define ALT_UP_B(label) \
  158. .equ up_b_offset, label - 9998b ;\
  159. .pushsection ".alt.smp.init", "a" ;\
  160. .long 9998b ;\
  161. W(b) . + up_b_offset ;\
  162. .popsection
  163. #else
  164. #define ALT_SMP(instr...)
  165. #define ALT_UP(instr...) instr
  166. #define ALT_UP_B(label) b label
  167. #endif
  168. /*
  169. * SMP data memory barrier
  170. */
  171. .macro smp_dmb mode
  172. #ifdef CONFIG_SMP
  173. #if __LINUX_ARM_ARCH__ >= 7
  174. .ifeqs "\mode","arm"
  175. ALT_SMP(dmb)
  176. .else
  177. ALT_SMP(W(dmb))
  178. .endif
  179. #elif __LINUX_ARM_ARCH__ == 6
  180. ALT_SMP(mcr p15, 0, r0, c7, c10, 5) @ dmb
  181. #else
  182. #error Incompatible SMP platform
  183. #endif
  184. .ifeqs "\mode","arm"
  185. ALT_UP(nop)
  186. .else
  187. ALT_UP(W(nop))
  188. .endif
  189. #endif
  190. .endm
  191. #ifdef CONFIG_THUMB2_KERNEL
  192. .macro setmode, mode, reg
  193. mov \reg, #\mode
  194. msr cpsr_c, \reg
  195. .endm
  196. #else
  197. .macro setmode, mode, reg
  198. msr cpsr_c, #\mode
  199. .endm
  200. #endif
  201. /*
  202. * STRT/LDRT access macros with ARM and Thumb-2 variants
  203. */
  204. #ifdef CONFIG_THUMB2_KERNEL
  205. .macro usraccoff, instr, reg, ptr, inc, off, cond, abort
  206. 9999:
  207. .if \inc == 1
  208. \instr\cond\()bt \reg, [\ptr, #\off]
  209. .elseif \inc == 4
  210. \instr\cond\()t \reg, [\ptr, #\off]
  211. .else
  212. .error "Unsupported inc macro argument"
  213. .endif
  214. .pushsection __ex_table,"a"
  215. .align 3
  216. .long 9999b, \abort
  217. .popsection
  218. .endm
  219. .macro usracc, instr, reg, ptr, inc, cond, rept, abort
  220. @ explicit IT instruction needed because of the label
  221. @ introduced by the USER macro
  222. .ifnc \cond,al
  223. .if \rept == 1
  224. itt \cond
  225. .elseif \rept == 2
  226. ittt \cond
  227. .else
  228. .error "Unsupported rept macro argument"
  229. .endif
  230. .endif
  231. @ Slightly optimised to avoid incrementing the pointer twice
  232. usraccoff \instr, \reg, \ptr, \inc, 0, \cond, \abort
  233. .if \rept == 2
  234. usraccoff \instr, \reg, \ptr, \inc, \inc, \cond, \abort
  235. .endif
  236. add\cond \ptr, #\rept * \inc
  237. .endm
  238. #else /* !CONFIG_THUMB2_KERNEL */
  239. .macro usracc, instr, reg, ptr, inc, cond, rept, abort
  240. .rept \rept
  241. 9999:
  242. .if \inc == 1
  243. \instr\cond\()bt \reg, [\ptr], #\inc
  244. .elseif \inc == 4
  245. \instr\cond\()t \reg, [\ptr], #\inc
  246. .else
  247. .error "Unsupported inc macro argument"
  248. .endif
  249. .pushsection __ex_table,"a"
  250. .align 3
  251. .long 9999b, \abort
  252. .popsection
  253. .endr
  254. .endm
  255. #endif /* CONFIG_THUMB2_KERNEL */
  256. .macro strusr, reg, ptr, inc, cond=al, rept=1, abort=9001f
  257. usracc str, \reg, \ptr, \inc, \cond, \rept, \abort
  258. .endm
  259. .macro ldrusr, reg, ptr, inc, cond=al, rept=1, abort=9001f
  260. usracc ldr, \reg, \ptr, \inc, \cond, \rept, \abort
  261. .endm