coprocessor.S 7.3 KB

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