coprocessor.S 7.1 KB

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