iwmmxt.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*
  2. * linux/arch/arm/kernel/iwmmxt.S
  3. *
  4. * XScale iWMMXt (Concan) context switching and handling
  5. *
  6. * Initial code:
  7. * Copyright (c) 2003, Intel Corporation
  8. *
  9. * Full lazy switching support, optimizations and more, by Nicolas Pitre
  10. * Copyright (c) 2003-2004, MontaVista Software, Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/linkage.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/thread_info.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/assembler.h>
  21. #if defined(CONFIG_CPU_PJ4) || defined(CONFIG_CPU_PJ4B)
  22. #define PJ4(code...) code
  23. #define XSC(code...)
  24. #elif defined(CONFIG_CPU_MOHAWK) || \
  25. defined(CONFIG_CPU_XSC3) || \
  26. defined(CONFIG_CPU_XSCALE)
  27. #define PJ4(code...)
  28. #define XSC(code...) code
  29. #else
  30. #error "Unsupported iWMMXt architecture"
  31. #endif
  32. #define MMX_WR0 (0x00)
  33. #define MMX_WR1 (0x08)
  34. #define MMX_WR2 (0x10)
  35. #define MMX_WR3 (0x18)
  36. #define MMX_WR4 (0x20)
  37. #define MMX_WR5 (0x28)
  38. #define MMX_WR6 (0x30)
  39. #define MMX_WR7 (0x38)
  40. #define MMX_WR8 (0x40)
  41. #define MMX_WR9 (0x48)
  42. #define MMX_WR10 (0x50)
  43. #define MMX_WR11 (0x58)
  44. #define MMX_WR12 (0x60)
  45. #define MMX_WR13 (0x68)
  46. #define MMX_WR14 (0x70)
  47. #define MMX_WR15 (0x78)
  48. #define MMX_WCSSF (0x80)
  49. #define MMX_WCASF (0x84)
  50. #define MMX_WCGR0 (0x88)
  51. #define MMX_WCGR1 (0x8C)
  52. #define MMX_WCGR2 (0x90)
  53. #define MMX_WCGR3 (0x94)
  54. #define MMX_SIZE (0x98)
  55. .text
  56. .arm
  57. /*
  58. * Lazy switching of Concan coprocessor context
  59. *
  60. * r10 = struct thread_info pointer
  61. * r9 = ret_from_exception
  62. * lr = undefined instr exit
  63. *
  64. * called from prefetch exception handler with interrupts enabled
  65. */
  66. ENTRY(iwmmxt_task_enable)
  67. inc_preempt_count r10, r3
  68. XSC(mrc p15, 0, r2, c15, c1, 0)
  69. PJ4(mrc p15, 0, r2, c1, c0, 2)
  70. @ CP0 and CP1 accessible?
  71. XSC(tst r2, #0x3)
  72. PJ4(tst r2, #0xf)
  73. bne 4f @ if so no business here
  74. @ enable access to CP0 and CP1
  75. XSC(orr r2, r2, #0x3)
  76. XSC(mcr p15, 0, r2, c15, c1, 0)
  77. PJ4(orr r2, r2, #0xf)
  78. PJ4(mcr p15, 0, r2, c1, c0, 2)
  79. ldr r3, =concan_owner
  80. add r0, r10, #TI_IWMMXT_STATE @ get task Concan save area
  81. ldr r2, [sp, #60] @ current task pc value
  82. ldr r1, [r3] @ get current Concan owner
  83. str r0, [r3] @ this task now owns Concan regs
  84. sub r2, r2, #4 @ adjust pc back
  85. str r2, [sp, #60]
  86. mrc p15, 0, r2, c2, c0, 0
  87. mov r2, r2 @ cpwait
  88. bl concan_save
  89. #ifdef CONFIG_PREEMPT_COUNT
  90. get_thread_info r10
  91. #endif
  92. 4: dec_preempt_count r10, r3
  93. ret r9 @ normal exit from exception
  94. concan_save:
  95. teq r1, #0 @ test for last ownership
  96. beq concan_load @ no owner, skip save
  97. tmrc r2, wCon
  98. @ CUP? wCx
  99. tst r2, #0x1
  100. beq 1f
  101. concan_dump:
  102. wstrw wCSSF, [r1, #MMX_WCSSF]
  103. wstrw wCASF, [r1, #MMX_WCASF]
  104. wstrw wCGR0, [r1, #MMX_WCGR0]
  105. wstrw wCGR1, [r1, #MMX_WCGR1]
  106. wstrw wCGR2, [r1, #MMX_WCGR2]
  107. wstrw wCGR3, [r1, #MMX_WCGR3]
  108. 1: @ MUP? wRn
  109. tst r2, #0x2
  110. beq 2f
  111. wstrd wR0, [r1, #MMX_WR0]
  112. wstrd wR1, [r1, #MMX_WR1]
  113. wstrd wR2, [r1, #MMX_WR2]
  114. wstrd wR3, [r1, #MMX_WR3]
  115. wstrd wR4, [r1, #MMX_WR4]
  116. wstrd wR5, [r1, #MMX_WR5]
  117. wstrd wR6, [r1, #MMX_WR6]
  118. wstrd wR7, [r1, #MMX_WR7]
  119. wstrd wR8, [r1, #MMX_WR8]
  120. wstrd wR9, [r1, #MMX_WR9]
  121. wstrd wR10, [r1, #MMX_WR10]
  122. wstrd wR11, [r1, #MMX_WR11]
  123. wstrd wR12, [r1, #MMX_WR12]
  124. wstrd wR13, [r1, #MMX_WR13]
  125. wstrd wR14, [r1, #MMX_WR14]
  126. wstrd wR15, [r1, #MMX_WR15]
  127. 2: teq r0, #0 @ anything to load?
  128. reteq lr @ if not, return
  129. concan_load:
  130. @ Load wRn
  131. wldrd wR0, [r0, #MMX_WR0]
  132. wldrd wR1, [r0, #MMX_WR1]
  133. wldrd wR2, [r0, #MMX_WR2]
  134. wldrd wR3, [r0, #MMX_WR3]
  135. wldrd wR4, [r0, #MMX_WR4]
  136. wldrd wR5, [r0, #MMX_WR5]
  137. wldrd wR6, [r0, #MMX_WR6]
  138. wldrd wR7, [r0, #MMX_WR7]
  139. wldrd wR8, [r0, #MMX_WR8]
  140. wldrd wR9, [r0, #MMX_WR9]
  141. wldrd wR10, [r0, #MMX_WR10]
  142. wldrd wR11, [r0, #MMX_WR11]
  143. wldrd wR12, [r0, #MMX_WR12]
  144. wldrd wR13, [r0, #MMX_WR13]
  145. wldrd wR14, [r0, #MMX_WR14]
  146. wldrd wR15, [r0, #MMX_WR15]
  147. @ Load wCx
  148. wldrw wCSSF, [r0, #MMX_WCSSF]
  149. wldrw wCASF, [r0, #MMX_WCASF]
  150. wldrw wCGR0, [r0, #MMX_WCGR0]
  151. wldrw wCGR1, [r0, #MMX_WCGR1]
  152. wldrw wCGR2, [r0, #MMX_WCGR2]
  153. wldrw wCGR3, [r0, #MMX_WCGR3]
  154. @ clear CUP/MUP (only if r1 != 0)
  155. teq r1, #0
  156. mov r2, #0
  157. reteq lr
  158. tmcr wCon, r2
  159. ret lr
  160. ENDPROC(iwmmxt_task_enable)
  161. /*
  162. * Back up Concan regs to save area and disable access to them
  163. * (mainly for gdb or sleep mode usage)
  164. *
  165. * r0 = struct thread_info pointer of target task or NULL for any
  166. */
  167. ENTRY(iwmmxt_task_disable)
  168. stmfd sp!, {r4, lr}
  169. mrs ip, cpsr
  170. orr r2, ip, #PSR_I_BIT @ disable interrupts
  171. msr cpsr_c, r2
  172. ldr r3, =concan_owner
  173. add r2, r0, #TI_IWMMXT_STATE @ get task Concan save area
  174. ldr r1, [r3] @ get current Concan owner
  175. teq r1, #0 @ any current owner?
  176. beq 1f @ no: quit
  177. teq r0, #0 @ any owner?
  178. teqne r1, r2 @ or specified one?
  179. bne 1f @ no: quit
  180. @ enable access to CP0 and CP1
  181. XSC(mrc p15, 0, r4, c15, c1, 0)
  182. XSC(orr r4, r4, #0x3)
  183. XSC(mcr p15, 0, r4, c15, c1, 0)
  184. PJ4(mrc p15, 0, r4, c1, c0, 2)
  185. PJ4(orr r4, r4, #0xf)
  186. PJ4(mcr p15, 0, r4, c1, c0, 2)
  187. mov r0, #0 @ nothing to load
  188. str r0, [r3] @ no more current owner
  189. mrc p15, 0, r2, c2, c0, 0
  190. mov r2, r2 @ cpwait
  191. bl concan_save
  192. @ disable access to CP0 and CP1
  193. XSC(bic r4, r4, #0x3)
  194. XSC(mcr p15, 0, r4, c15, c1, 0)
  195. PJ4(bic r4, r4, #0xf)
  196. PJ4(mcr p15, 0, r4, c1, c0, 2)
  197. mrc p15, 0, r2, c2, c0, 0
  198. mov r2, r2 @ cpwait
  199. 1: msr cpsr_c, ip @ restore interrupt mode
  200. ldmfd sp!, {r4, pc}
  201. ENDPROC(iwmmxt_task_disable)
  202. /*
  203. * Copy Concan state to given memory address
  204. *
  205. * r0 = struct thread_info pointer of target task
  206. * r1 = memory address where to store Concan state
  207. *
  208. * this is called mainly in the creation of signal stack frames
  209. */
  210. ENTRY(iwmmxt_task_copy)
  211. mrs ip, cpsr
  212. orr r2, ip, #PSR_I_BIT @ disable interrupts
  213. msr cpsr_c, r2
  214. ldr r3, =concan_owner
  215. add r2, r0, #TI_IWMMXT_STATE @ get task Concan save area
  216. ldr r3, [r3] @ get current Concan owner
  217. teq r2, r3 @ does this task own it...
  218. beq 1f
  219. @ current Concan values are in the task save area
  220. msr cpsr_c, ip @ restore interrupt mode
  221. mov r0, r1
  222. mov r1, r2
  223. mov r2, #MMX_SIZE
  224. b memcpy
  225. 1: @ this task owns Concan regs -- grab a copy from there
  226. mov r0, #0 @ nothing to load
  227. mov r2, #3 @ save all regs
  228. mov r3, lr @ preserve return address
  229. bl concan_dump
  230. msr cpsr_c, ip @ restore interrupt mode
  231. ret r3
  232. ENDPROC(iwmmxt_task_copy)
  233. /*
  234. * Restore Concan state from given memory address
  235. *
  236. * r0 = struct thread_info pointer of target task
  237. * r1 = memory address where to get Concan state from
  238. *
  239. * this is used to restore Concan state when unwinding a signal stack frame
  240. */
  241. ENTRY(iwmmxt_task_restore)
  242. mrs ip, cpsr
  243. orr r2, ip, #PSR_I_BIT @ disable interrupts
  244. msr cpsr_c, r2
  245. ldr r3, =concan_owner
  246. add r2, r0, #TI_IWMMXT_STATE @ get task Concan save area
  247. ldr r3, [r3] @ get current Concan owner
  248. bic r2, r2, #0x7 @ 64-bit alignment
  249. teq r2, r3 @ does this task own it...
  250. beq 1f
  251. @ this task doesn't own Concan regs -- use its save area
  252. msr cpsr_c, ip @ restore interrupt mode
  253. mov r0, r2
  254. mov r2, #MMX_SIZE
  255. b memcpy
  256. 1: @ this task owns Concan regs -- load them directly
  257. mov r0, r1
  258. mov r1, #0 @ don't clear CUP/MUP
  259. mov r3, lr @ preserve return address
  260. bl concan_load
  261. msr cpsr_c, ip @ restore interrupt mode
  262. ret r3
  263. ENDPROC(iwmmxt_task_restore)
  264. /*
  265. * Concan handling on task switch
  266. *
  267. * r0 = next thread_info pointer
  268. *
  269. * Called only from the iwmmxt notifier with task preemption disabled.
  270. */
  271. ENTRY(iwmmxt_task_switch)
  272. XSC(mrc p15, 0, r1, c15, c1, 0)
  273. PJ4(mrc p15, 0, r1, c1, c0, 2)
  274. @ CP0 and CP1 accessible?
  275. XSC(tst r1, #0x3)
  276. PJ4(tst r1, #0xf)
  277. bne 1f @ yes: block them for next task
  278. ldr r2, =concan_owner
  279. add r3, r0, #TI_IWMMXT_STATE @ get next task Concan save area
  280. ldr r2, [r2] @ get current Concan owner
  281. teq r2, r3 @ next task owns it?
  282. retne lr @ no: leave Concan disabled
  283. 1: @ flip Concan access
  284. XSC(eor r1, r1, #0x3)
  285. XSC(mcr p15, 0, r1, c15, c1, 0)
  286. PJ4(eor r1, r1, #0xf)
  287. PJ4(mcr p15, 0, r1, c1, c0, 2)
  288. mrc p15, 0, r1, c2, c0, 0
  289. sub pc, lr, r1, lsr #32 @ cpwait and return
  290. ENDPROC(iwmmxt_task_switch)
  291. /*
  292. * Remove Concan ownership of given task
  293. *
  294. * r0 = struct thread_info pointer
  295. */
  296. ENTRY(iwmmxt_task_release)
  297. mrs r2, cpsr
  298. orr ip, r2, #PSR_I_BIT @ disable interrupts
  299. msr cpsr_c, ip
  300. ldr r3, =concan_owner
  301. add r0, r0, #TI_IWMMXT_STATE @ get task Concan save area
  302. ldr r1, [r3] @ get current Concan owner
  303. eors r0, r0, r1 @ if equal...
  304. streq r0, [r3] @ then clear ownership
  305. msr cpsr_c, r2 @ restore interrupts
  306. ret lr
  307. ENDPROC(iwmmxt_task_release)
  308. .data
  309. concan_owner:
  310. .word 0