iwmmxt.S 8.3 KB

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