iwmmxt.S 8.0 KB

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