coprocessor.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * arch/xtensa/kernel/coprocessor.S
  3. *
  4. * Xtensa processor configuration-specific table of coprocessor and
  5. * other custom register layout information.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. *
  11. * Copyright (C) 2003 - 2007 Tensilica Inc.
  12. */
  13. #include <linux/linkage.h>
  14. #include <asm/asm-offsets.h>
  15. #include <asm/processor.h>
  16. #include <asm/coprocessor.h>
  17. #include <asm/thread_info.h>
  18. #include <asm/asm-uaccess.h>
  19. #include <asm/unistd.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/current.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/page.h>
  24. #include <asm/signal.h>
  25. #include <asm/tlbflush.h>
  26. #if XTENSA_HAVE_COPROCESSORS
  27. /*
  28. * Macros for lazy context switch.
  29. */
  30. #define SAVE_CP_REGS(x) \
  31. .align 4; \
  32. .Lsave_cp_regs_cp##x: \
  33. .if XTENSA_HAVE_COPROCESSOR(x); \
  34. xchal_cp##x##_store a2 a4 a5 a6 a7; \
  35. .endif; \
  36. jx a0
  37. #define SAVE_CP_REGS_TAB(x) \
  38. .if XTENSA_HAVE_COPROCESSOR(x); \
  39. .long .Lsave_cp_regs_cp##x - .Lsave_cp_regs_jump_table; \
  40. .else; \
  41. .long 0; \
  42. .endif; \
  43. .long THREAD_XTREGS_CP##x
  44. #define LOAD_CP_REGS(x) \
  45. .align 4; \
  46. .Lload_cp_regs_cp##x: \
  47. .if XTENSA_HAVE_COPROCESSOR(x); \
  48. xchal_cp##x##_load a2 a4 a5 a6 a7; \
  49. .endif; \
  50. jx a0
  51. #define LOAD_CP_REGS_TAB(x) \
  52. .if XTENSA_HAVE_COPROCESSOR(x); \
  53. .long .Lload_cp_regs_cp##x - .Lload_cp_regs_jump_table; \
  54. .else; \
  55. .long 0; \
  56. .endif; \
  57. .long THREAD_XTREGS_CP##x
  58. SAVE_CP_REGS(0)
  59. SAVE_CP_REGS(1)
  60. SAVE_CP_REGS(2)
  61. SAVE_CP_REGS(3)
  62. SAVE_CP_REGS(4)
  63. SAVE_CP_REGS(5)
  64. SAVE_CP_REGS(6)
  65. SAVE_CP_REGS(7)
  66. LOAD_CP_REGS(0)
  67. LOAD_CP_REGS(1)
  68. LOAD_CP_REGS(2)
  69. LOAD_CP_REGS(3)
  70. LOAD_CP_REGS(4)
  71. LOAD_CP_REGS(5)
  72. LOAD_CP_REGS(6)
  73. LOAD_CP_REGS(7)
  74. .align 4
  75. .Lsave_cp_regs_jump_table:
  76. SAVE_CP_REGS_TAB(0)
  77. SAVE_CP_REGS_TAB(1)
  78. SAVE_CP_REGS_TAB(2)
  79. SAVE_CP_REGS_TAB(3)
  80. SAVE_CP_REGS_TAB(4)
  81. SAVE_CP_REGS_TAB(5)
  82. SAVE_CP_REGS_TAB(6)
  83. SAVE_CP_REGS_TAB(7)
  84. .Lload_cp_regs_jump_table:
  85. LOAD_CP_REGS_TAB(0)
  86. LOAD_CP_REGS_TAB(1)
  87. LOAD_CP_REGS_TAB(2)
  88. LOAD_CP_REGS_TAB(3)
  89. LOAD_CP_REGS_TAB(4)
  90. LOAD_CP_REGS_TAB(5)
  91. LOAD_CP_REGS_TAB(6)
  92. LOAD_CP_REGS_TAB(7)
  93. /*
  94. * coprocessor_save(buffer, index)
  95. * a2 a3
  96. * coprocessor_load(buffer, index)
  97. * a2 a3
  98. *
  99. * Save or load coprocessor registers for coprocessor 'index'.
  100. * The register values are saved to or loaded from them 'buffer' address.
  101. *
  102. * Note that these functions don't update the coprocessor_owner information!
  103. *
  104. */
  105. ENTRY(coprocessor_save)
  106. entry a1, 32
  107. s32i a0, a1, 0
  108. movi a0, .Lsave_cp_regs_jump_table
  109. addx8 a3, a3, a0
  110. l32i a3, a3, 0
  111. beqz a3, 1f
  112. add a0, a0, a3
  113. callx0 a0
  114. 1: l32i a0, a1, 0
  115. retw
  116. ENDPROC(coprocessor_save)
  117. ENTRY(coprocessor_load)
  118. entry a1, 32
  119. s32i a0, a1, 0
  120. movi a0, .Lload_cp_regs_jump_table
  121. addx4 a3, a3, a0
  122. l32i a3, a3, 0
  123. beqz a3, 1f
  124. add a0, a0, a3
  125. callx0 a0
  126. 1: l32i a0, a1, 0
  127. retw
  128. ENDPROC(coprocessor_load)
  129. /*
  130. * coprocessor_flush(struct task_info*, index)
  131. * a2 a3
  132. * coprocessor_restore(struct task_info*, index)
  133. * a2 a3
  134. *
  135. * Save or load coprocessor registers for coprocessor 'index'.
  136. * The register values are saved to or loaded from the coprocessor area
  137. * inside the task_info structure.
  138. *
  139. * Note that these functions don't update the coprocessor_owner information!
  140. *
  141. */
  142. ENTRY(coprocessor_flush)
  143. entry a1, 32
  144. s32i a0, a1, 0
  145. movi a0, .Lsave_cp_regs_jump_table
  146. addx8 a3, a3, a0
  147. l32i a4, a3, 4
  148. l32i a3, a3, 0
  149. add a2, a2, a4
  150. beqz a3, 1f
  151. add a0, a0, a3
  152. callx0 a0
  153. 1: l32i a0, a1, 0
  154. retw
  155. ENDPROC(coprocessor_flush)
  156. ENTRY(coprocessor_restore)
  157. entry a1, 32
  158. s32i a0, a1, 0
  159. movi a0, .Lload_cp_regs_jump_table
  160. addx4 a3, a3, a0
  161. l32i a4, a3, 4
  162. l32i a3, a3, 0
  163. add a2, a2, a4
  164. beqz a3, 1f
  165. add a0, a0, a3
  166. callx0 a0
  167. 1: l32i a0, a1, 0
  168. retw
  169. ENDPROC(coprocessor_restore)
  170. /*
  171. * Entry condition:
  172. *
  173. * a0: trashed, original value saved on stack (PT_AREG0)
  174. * a1: a1
  175. * a2: new stack pointer, original in DEPC
  176. * a3: a3
  177. * depc: a2, original value saved on stack (PT_DEPC)
  178. * excsave_1: dispatch table
  179. *
  180. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  181. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  182. */
  183. ENTRY(fast_coprocessor_double)
  184. wsr a0, excsave1
  185. call0 unrecoverable_exception
  186. ENDPROC(fast_coprocessor_double)
  187. ENTRY(fast_coprocessor)
  188. /* Save remaining registers a1-a3 and SAR */
  189. s32i a3, a2, PT_AREG3
  190. rsr a3, sar
  191. s32i a1, a2, PT_AREG1
  192. s32i a3, a2, PT_SAR
  193. mov a1, a2
  194. rsr a2, depc
  195. s32i a2, a1, PT_AREG2
  196. /*
  197. * The hal macros require up to 4 temporary registers. We use a3..a6.
  198. */
  199. s32i a4, a1, PT_AREG4
  200. s32i a5, a1, PT_AREG5
  201. s32i a6, a1, PT_AREG6
  202. /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */
  203. rsr a3, exccause
  204. addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
  205. /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/
  206. ssl a3 # SAR: 32 - coprocessor_number
  207. movi a2, 1
  208. rsr a0, cpenable
  209. sll a2, a2
  210. or a0, a0, a2
  211. wsr a0, cpenable
  212. rsync
  213. /* Retrieve previous owner. (a3 still holds CP number) */
  214. movi a0, coprocessor_owner # list of owners
  215. addx4 a0, a3, a0 # entry for CP
  216. l32i a4, a0, 0
  217. beqz a4, 1f # skip 'save' if no previous owner
  218. /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */
  219. l32i a5, a4, THREAD_CPENABLE
  220. xor a5, a5, a2 # (1 << cp-id) still in a2
  221. s32i a5, a4, THREAD_CPENABLE
  222. /*
  223. * Get context save area and 'call' save routine.
  224. * (a4 still holds previous owner (thread_info), a3 CP number)
  225. */
  226. movi a5, .Lsave_cp_regs_jump_table
  227. movi a0, 2f # a0: 'return' address
  228. addx8 a3, a3, a5 # a3: coprocessor number
  229. l32i a2, a3, 4 # a2: xtregs offset
  230. l32i a3, a3, 0 # a3: jump offset
  231. add a2, a2, a4
  232. add a4, a3, a5 # a4: address of save routine
  233. jx a4
  234. /* Note that only a0 and a1 were preserved. */
  235. 2: rsr a3, exccause
  236. addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
  237. movi a0, coprocessor_owner
  238. addx4 a0, a3, a0
  239. /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */
  240. 1: GET_THREAD_INFO (a4, a1)
  241. s32i a4, a0, 0
  242. /* Get context save area and 'call' load routine. */
  243. movi a5, .Lload_cp_regs_jump_table
  244. movi a0, 1f
  245. addx8 a3, a3, a5
  246. l32i a2, a3, 4 # a2: xtregs offset
  247. l32i a3, a3, 0 # a3: jump offset
  248. add a2, a2, a4
  249. add a4, a3, a5
  250. jx a4
  251. /* Restore all registers and return from exception handler. */
  252. 1: l32i a6, a1, PT_AREG6
  253. l32i a5, a1, PT_AREG5
  254. l32i a4, a1, PT_AREG4
  255. l32i a0, a1, PT_SAR
  256. l32i a3, a1, PT_AREG3
  257. l32i a2, a1, PT_AREG2
  258. wsr a0, sar
  259. l32i a0, a1, PT_AREG0
  260. l32i a1, a1, PT_AREG1
  261. rfe
  262. ENDPROC(fast_coprocessor)
  263. .data
  264. ENTRY(coprocessor_owner)
  265. .fill XCHAL_CP_MAX, 4, 0
  266. END(coprocessor_owner)
  267. #endif /* XTENSA_HAVE_COPROCESSORS */