xtensa_context.S 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*******************************************************************************
  2. Copyright (c) 2006-2015 Cadence Design Systems Inc.
  3. Permission is hereby granted, free of charge, to any person obtaining
  4. a copy of this software and associated documentation files (the
  5. "Software"), to deal in the Software without restriction, including
  6. without limitation the rights to use, copy, modify, merge, publish,
  7. distribute, sublicense, and/or sell copies of the Software, and to
  8. permit persons to whom the Software is furnished to do so, subject to
  9. the following conditions:
  10. The above copyright notice and this permission notice shall be included
  11. in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  16. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  17. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  18. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. --------------------------------------------------------------------------------
  20. XTENSA CONTEXT SAVE AND RESTORE ROUTINES
  21. Low-level Call0 functions for handling generic context save and restore of
  22. registers not specifically addressed by the interrupt vectors and handlers.
  23. Those registers (not handled by these functions) are PC, PS, A0, A1 (SP).
  24. Except for the calls to RTOS functions, this code is generic to Xtensa.
  25. Note that in Call0 ABI, interrupt handlers are expected to preserve the callee-
  26. save regs (A12-A15), which is always the case if the handlers are coded in C.
  27. However A12, A13 are made available as scratch registers for interrupt dispatch
  28. code, so are presumed saved anyway, and are always restored even in Call0 ABI.
  29. Only A14, A15 are truly handled as callee-save regs.
  30. Because Xtensa is a configurable architecture, this port supports all user
  31. generated configurations (except restrictions stated in the release notes).
  32. This is accomplished by conditional compilation using macros and functions
  33. defined in the Xtensa HAL (hardware adaptation layer) for your configuration.
  34. Only the processor state included in your configuration is saved and restored,
  35. including any processor state added by user configuration options or TIE.
  36. *******************************************************************************/
  37. /* Warn nicely if this file gets named with a lowercase .s instead of .S: */
  38. #define NOERROR #
  39. NOERROR: .error "C preprocessor needed for this file: make sure its filename\
  40. ends in uppercase .S, or use xt-xcc's -x assembler-with-cpp option."
  41. #include "xtensa_rtos.h"
  42. #include "xtensa_context.h"
  43. #include "xt_asm_utils.h"
  44. #ifdef XT_USE_OVLY
  45. #include <xtensa/overlay_os_asm.h>
  46. #endif
  47. .text
  48. /*******************************************************************************
  49. _xt_context_save
  50. !! MUST BE CALLED ONLY BY 'CALL0' INSTRUCTION !!
  51. Saves all Xtensa processor state except PC, PS, A0, A1 (SP), A12, A13, in the
  52. interrupt stack frame defined in xtensa_rtos.h.
  53. Its counterpart is _xt_context_restore (which also restores A12, A13).
  54. Caller is expected to have saved PC, PS, A0, A1 (SP), A12, A13 in the frame.
  55. This function preserves A12 & A13 in order to provide the caller with 2 scratch
  56. regs that need not be saved over the call to this function. The choice of which
  57. 2 regs to provide is governed by xthal_window_spill_nw and xthal_save_extra_nw,
  58. to avoid moving data more than necessary. Caller can assign regs accordingly.
  59. Entry Conditions:
  60. A0 = Return address in caller.
  61. A1 = Stack pointer of interrupted thread or handler ("interruptee").
  62. Original A12, A13 have already been saved in the interrupt stack frame.
  63. Other processor state except PC, PS, A0, A1 (SP), A12, A13, is as at the
  64. point of interruption.
  65. If windowed ABI, PS.EXCM = 1 (exceptions disabled).
  66. Exit conditions:
  67. A0 = Return address in caller.
  68. A1 = Stack pointer of interrupted thread or handler ("interruptee").
  69. A12, A13 as at entry (preserved).
  70. If windowed ABI, PS.EXCM = 1 (exceptions disabled).
  71. *******************************************************************************/
  72. .global _xt_context_save
  73. .type _xt_context_save,@function
  74. .align 4
  75. .literal_position
  76. .align 4
  77. _xt_context_save:
  78. s32i a2, sp, XT_STK_A2
  79. s32i a3, sp, XT_STK_A3
  80. s32i a4, sp, XT_STK_A4
  81. s32i a5, sp, XT_STK_A5
  82. s32i a6, sp, XT_STK_A6
  83. s32i a7, sp, XT_STK_A7
  84. s32i a8, sp, XT_STK_A8
  85. s32i a9, sp, XT_STK_A9
  86. s32i a10, sp, XT_STK_A10
  87. s32i a11, sp, XT_STK_A11
  88. /*
  89. Call0 ABI callee-saved regs a12-15 do not need to be saved here.
  90. a12-13 are the caller's responsibility so it can use them as scratch.
  91. So only need to save a14-a15 here for Windowed ABI (not Call0).
  92. */
  93. #ifndef __XTENSA_CALL0_ABI__
  94. s32i a14, sp, XT_STK_A14
  95. s32i a15, sp, XT_STK_A15
  96. #endif
  97. rsr a3, SAR
  98. s32i a3, sp, XT_STK_SAR
  99. #if XCHAL_HAVE_LOOPS
  100. rsr a3, LBEG
  101. s32i a3, sp, XT_STK_LBEG
  102. rsr a3, LEND
  103. s32i a3, sp, XT_STK_LEND
  104. rsr a3, LCOUNT
  105. s32i a3, sp, XT_STK_LCOUNT
  106. #endif
  107. #ifdef XT_USE_SWPRI
  108. /* Save virtual priority mask */
  109. movi a3, _xt_vpri_mask
  110. l32i a3, a3, 0
  111. s32i a3, sp, XT_STK_VPRI
  112. #endif
  113. #if XCHAL_EXTRA_SA_SIZE > 0 || !defined(__XTENSA_CALL0_ABI__)
  114. mov a9, a0 /* preserve ret addr */
  115. #endif
  116. s32i a12, sp, XT_STK_TMP0 /* temp. save stuff in stack frame */
  117. s32i a13, sp, XT_STK_TMP1
  118. s32i a9, sp, XT_STK_TMP2
  119. l32i a12, sp, XT_STK_A12 /* recover original a9,12,13 */
  120. l32i a13, sp, XT_STK_A13
  121. l32i a9, sp, XT_STK_A9
  122. #if XCHAL_EXTRA_SA_SIZE > 0
  123. addi a2, sp, XT_STK_EXTRA /* where to save it */
  124. # if XCHAL_EXTRA_SA_ALIGN > 16
  125. movi a3, -XCHAL_EXTRA_SA_ALIGN
  126. and a2, a2, a3 /* align dynamically >16 bytes */
  127. # endif
  128. call0 xthal_save_extra_nw /* destroys a0,2,3 */
  129. #endif
  130. #ifndef __XTENSA_CALL0_ABI__
  131. #ifdef XT_USE_OVLY
  132. l32i a9, sp, XT_STK_PC /* recover saved PC */
  133. _xt_overlay_get_state a9, a12, a13
  134. s32i a9, sp, XT_STK_OVLY /* save overlay state */
  135. #endif
  136. /* SPILL_ALL_WINDOWS macro requires window overflow exceptions to be enabled,
  137. * i.e. PS.EXCM cleared and PS.WOE set.
  138. * Since we are going to clear PS.EXCM, we also need to increase INTLEVEL
  139. * at least to XCHAL_EXCM_LEVEL. This matches that value of effective INTLEVEL
  140. * at entry (CINTLEVEL=max(PS.INTLEVEL, XCHAL_EXCM_LEVEL) when PS.EXCM is set.
  141. * Since WindowOverflow exceptions will trigger inside SPILL_ALL_WINDOWS,
  142. * need to save/restore EPC1 as well.
  143. * Note: even though a4-a15 are saved into the exception frame, we should not
  144. * clobber them until after SPILL_ALL_WINDOWS. This is because these registers
  145. * may contain live windows belonging to previous frames in the call stack.
  146. * These frames will be spilled by SPILL_ALL_WINDOWS, and if the register was
  147. * used as a temporary by this code, the temporary value would get stored
  148. * onto the stack, instead of the real value.
  149. */
  150. rsr a2, PS /* to be restored after SPILL_ALL_WINDOWS */
  151. movi a0, PS_INTLEVEL_MASK
  152. and a3, a2, a0 /* get the current INTLEVEL */
  153. bgeui a3, XCHAL_EXCM_LEVEL, 1f /* calculate max(INTLEVEL, XCHAL_EXCM_LEVEL) */
  154. movi a3, XCHAL_EXCM_LEVEL
  155. 1:
  156. movi a0, PS_UM | PS_WOE /* clear EXCM, enable window overflow, set new INTLEVEL */
  157. or a3, a3, a0
  158. wsr a3, ps
  159. rsr a0, EPC1 /* to be restored after SPILL_ALL_WINDOWS */
  160. addi sp, sp, XT_STK_FRMSZ /* go back to spill register region */
  161. SPILL_ALL_WINDOWS /* place the live register windows there */
  162. addi sp, sp, -XT_STK_FRMSZ /* return the current stack pointer and proceed with context save*/
  163. wsr a2, PS /* restore to the value at entry */
  164. rsync
  165. wsr a0, EPC1 /* likewise */
  166. #endif /* __XTENSA_CALL0_ABI__ */
  167. l32i a12, sp, XT_STK_TMP0 /* restore the temp saved registers */
  168. l32i a13, sp, XT_STK_TMP1 /* our return address is there */
  169. l32i a9, sp, XT_STK_TMP2
  170. #if XCHAL_EXTRA_SA_SIZE > 0 || !defined(__XTENSA_CALL0_ABI__)
  171. mov a0, a9 /* retrieve ret addr */
  172. #endif
  173. ret
  174. /*******************************************************************************
  175. _xt_context_restore
  176. !! MUST BE CALLED ONLY BY 'CALL0' INSTRUCTION !!
  177. Restores all Xtensa processor state except PC, PS, A0, A1 (SP) (and in Call0
  178. ABI, A14, A15 which are preserved by all interrupt handlers) from an interrupt
  179. stack frame defined in xtensa_rtos.h .
  180. Its counterpart is _xt_context_save (whose caller saved A12, A13).
  181. Caller is responsible to restore PC, PS, A0, A1 (SP).
  182. Entry Conditions:
  183. A0 = Return address in caller.
  184. A1 = Stack pointer of interrupted thread or handler ("interruptee").
  185. Exit conditions:
  186. A0 = Return address in caller.
  187. A1 = Stack pointer of interrupted thread or handler ("interruptee").
  188. Other processor state except PC, PS, A0, A1 (SP), is as at the point
  189. of interruption.
  190. *******************************************************************************/
  191. .global _xt_context_restore
  192. .type _xt_context_restore,@function
  193. .align 4
  194. .literal_position
  195. .align 4
  196. _xt_context_restore:
  197. #if XCHAL_EXTRA_SA_SIZE > 0
  198. /*
  199. NOTE: Normally the xthal_restore_extra_nw macro only affects address
  200. registers a2-a5. It is theoretically possible for Xtensa processor
  201. designers to write TIE that causes more address registers to be
  202. affected, but it is generally unlikely. If that ever happens,
  203. more registers need to be saved/restored around this macro invocation.
  204. Here we only assume a13 is preserved.
  205. Future Xtensa tools releases might limit the regs that can be affected.
  206. */
  207. mov a13, a0 /* preserve ret addr */
  208. addi a2, sp, XT_STK_EXTRA /* where to find it */
  209. # if XCHAL_EXTRA_SA_ALIGN > 16
  210. movi a3, -XCHAL_EXTRA_SA_ALIGN
  211. and a2, a2, a3 /* align dynamically >16 bytes */
  212. # endif
  213. call0 xthal_restore_extra_nw /* destroys a0,2,3,4,5 */
  214. mov a0, a13 /* retrieve ret addr */
  215. #endif
  216. #if XCHAL_HAVE_LOOPS
  217. l32i a2, sp, XT_STK_LBEG
  218. l32i a3, sp, XT_STK_LEND
  219. wsr a2, LBEG
  220. l32i a2, sp, XT_STK_LCOUNT
  221. wsr a3, LEND
  222. wsr a2, LCOUNT
  223. #endif
  224. #ifdef XT_USE_OVLY
  225. /*
  226. If we are using overlays, this is a good spot to check if we need
  227. to restore an overlay for the incoming task. Here we have a bunch
  228. of registers to spare. Note that this step is going to use a few
  229. bytes of storage below SP (SP-20 to SP-32) if an overlay is going
  230. to be restored.
  231. */
  232. l32i a2, sp, XT_STK_PC /* retrieve PC */
  233. l32i a3, sp, XT_STK_PS /* retrieve PS */
  234. l32i a4, sp, XT_STK_OVLY /* retrieve overlay state */
  235. l32i a5, sp, XT_STK_A1 /* retrieve stack ptr */
  236. _xt_overlay_check_map a2, a3, a4, a5, a6
  237. s32i a2, sp, XT_STK_PC /* save updated PC */
  238. s32i a3, sp, XT_STK_PS /* save updated PS */
  239. #endif
  240. #ifdef XT_USE_SWPRI
  241. /* Restore virtual interrupt priority and interrupt enable */
  242. movi a3, _xt_intdata
  243. l32i a4, a3, 0 /* a4 = _xt_intenable */
  244. l32i a5, sp, XT_STK_VPRI /* a5 = saved _xt_vpri_mask */
  245. and a4, a4, a5
  246. wsr a4, INTENABLE /* update INTENABLE */
  247. s32i a5, a3, 4 /* restore _xt_vpri_mask */
  248. #endif
  249. l32i a3, sp, XT_STK_SAR
  250. l32i a2, sp, XT_STK_A2
  251. wsr a3, SAR
  252. l32i a3, sp, XT_STK_A3
  253. l32i a4, sp, XT_STK_A4
  254. l32i a5, sp, XT_STK_A5
  255. l32i a6, sp, XT_STK_A6
  256. l32i a7, sp, XT_STK_A7
  257. l32i a8, sp, XT_STK_A8
  258. l32i a9, sp, XT_STK_A9
  259. l32i a10, sp, XT_STK_A10
  260. l32i a11, sp, XT_STK_A11
  261. /*
  262. Call0 ABI callee-saved regs a12-15 do not need to be restored here.
  263. However a12-13 were saved for scratch before XT_RTOS_INT_ENTER(),
  264. so need to be restored anyway, despite being callee-saved in Call0.
  265. */
  266. l32i a12, sp, XT_STK_A12
  267. l32i a13, sp, XT_STK_A13
  268. #ifndef __XTENSA_CALL0_ABI__
  269. l32i a14, sp, XT_STK_A14
  270. l32i a15, sp, XT_STK_A15
  271. #endif
  272. ret
  273. /*******************************************************************************
  274. _xt_coproc_init
  275. Initializes global co-processor management data, setting all co-processors
  276. to "unowned". Leaves CPENABLE as it found it (does NOT clear it).
  277. Called during initialization of the RTOS, before any threads run.
  278. This may be called from normal Xtensa single-threaded application code which
  279. might use co-processors. The Xtensa run-time initialization enables all
  280. co-processors. They must remain enabled here, else a co-processor exception
  281. might occur outside of a thread, which the exception handler doesn't expect.
  282. Entry Conditions:
  283. Xtensa single-threaded run-time environment is in effect.
  284. No thread is yet running.
  285. Exit conditions:
  286. None.
  287. Obeys ABI conventions per prototype:
  288. void _xt_coproc_init(void)
  289. *******************************************************************************/
  290. #if XCHAL_CP_NUM > 0
  291. .global _xt_coproc_init
  292. .type _xt_coproc_init,@function
  293. .align 4
  294. .literal_position
  295. .align 4
  296. _xt_coproc_init:
  297. ENTRY0
  298. /* Initialize thread co-processor ownerships to 0 (unowned). */
  299. movi a2, _xt_coproc_owner_sa /* a2 = base of owner array */
  300. addi a3, a2, (XCHAL_CP_MAX*portNUM_PROCESSORS) << 2 /* a3 = top+1 of owner array */
  301. movi a4, 0 /* a4 = 0 (unowned) */
  302. 1: s32i a4, a2, 0
  303. addi a2, a2, 4
  304. bltu a2, a3, 1b
  305. RET0
  306. #endif
  307. /*******************************************************************************
  308. _xt_coproc_release
  309. Releases any and all co-processors owned by a given thread. The thread is
  310. identified by it's co-processor state save area defined in xtensa_context.h .
  311. Must be called before a thread's co-proc save area is deleted to avoid
  312. memory corruption when the exception handler tries to save the state.
  313. May be called when a thread terminates or completes but does not delete
  314. the co-proc save area, to avoid the exception handler having to save the
  315. thread's co-proc state before another thread can use it (optimization).
  316. Needs to be called on the processor the thread was running on. Unpinned threads
  317. won't have an entry here because they get pinned as soon they use a coprocessor.
  318. Entry Conditions:
  319. A2 = Pointer to base of co-processor state save area.
  320. Exit conditions:
  321. None.
  322. Obeys ABI conventions per prototype:
  323. void _xt_coproc_release(void * coproc_sa_base)
  324. *******************************************************************************/
  325. #if XCHAL_CP_NUM > 0
  326. .global _xt_coproc_release
  327. .type _xt_coproc_release,@function
  328. .align 4
  329. .literal_position
  330. .align 4
  331. _xt_coproc_release:
  332. ENTRY0 /* a2 = base of save area */
  333. getcoreid a5
  334. movi a3, XCHAL_CP_MAX << 2
  335. mull a5, a5, a3
  336. movi a3, _xt_coproc_owner_sa /* a3 = base of owner array */
  337. add a3, a3, a5
  338. addi a4, a3, XCHAL_CP_MAX << 2 /* a4 = top+1 of owner array */
  339. movi a5, 0 /* a5 = 0 (unowned) */
  340. rsil a6, XCHAL_EXCM_LEVEL /* lock interrupts */
  341. 1: l32i a7, a3, 0 /* a7 = owner at a3 */
  342. bne a2, a7, 2f /* if (coproc_sa_base == owner) */
  343. s32i a5, a3, 0 /* owner = unowned */
  344. 2: addi a3, a3, 1<<2 /* a3 = next entry in owner array */
  345. bltu a3, a4, 1b /* repeat until end of array */
  346. 3: wsr a6, PS /* restore interrupts */
  347. RET0
  348. #endif
  349. /*******************************************************************************
  350. _xt_coproc_savecs
  351. If there is a current thread and it has a coprocessor state save area, then
  352. save all callee-saved state into this area. This function is called from the
  353. solicited context switch handler. It calls a system-specific function to get
  354. the coprocessor save area base address.
  355. Entry conditions:
  356. - The thread being switched out is still the current thread.
  357. - CPENABLE state reflects which coprocessors are active.
  358. - Registers have been saved/spilled already.
  359. Exit conditions:
  360. - All necessary CP callee-saved state has been saved.
  361. - Registers a2-a7, a13-a15 have been trashed.
  362. Must be called from assembly code only, using CALL0.
  363. *******************************************************************************/
  364. #if XCHAL_CP_NUM > 0
  365. .extern _xt_coproc_sa_offset /* external reference */
  366. .global _xt_coproc_savecs
  367. .type _xt_coproc_savecs,@function
  368. .align 4
  369. .literal_position
  370. .align 4
  371. _xt_coproc_savecs:
  372. /* At entry, CPENABLE should be showing which CPs are enabled. */
  373. rsr a2, CPENABLE /* a2 = which CPs are enabled */
  374. beqz a2, .Ldone /* quick exit if none */
  375. mov a14, a0 /* save return address */
  376. call0 XT_RTOS_CP_STATE /* get address of CP save area */
  377. mov a0, a14 /* restore return address */
  378. beqz a15, .Ldone /* if none then nothing to do */
  379. s16i a2, a15, XT_CP_CS_ST /* save mask of CPs being stored */
  380. movi a13, _xt_coproc_sa_offset /* array of CP save offsets */
  381. l32i a15, a15, XT_CP_ASA /* a15 = base of aligned save area */
  382. #if XCHAL_CP0_SA_SIZE
  383. bbci.l a2, 0, 2f /* CP 0 not enabled */
  384. l32i a14, a13, 0 /* a14 = _xt_coproc_sa_offset[0] */
  385. add a3, a14, a15 /* a3 = save area for CP 0 */
  386. xchal_cp0_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  387. 2:
  388. #endif
  389. #if XCHAL_CP1_SA_SIZE
  390. bbci.l a2, 1, 2f /* CP 1 not enabled */
  391. l32i a14, a13, 4 /* a14 = _xt_coproc_sa_offset[1] */
  392. add a3, a14, a15 /* a3 = save area for CP 1 */
  393. xchal_cp1_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  394. 2:
  395. #endif
  396. #if XCHAL_CP2_SA_SIZE
  397. bbci.l a2, 2, 2f
  398. l32i a14, a13, 8
  399. add a3, a14, a15
  400. xchal_cp2_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  401. 2:
  402. #endif
  403. #if XCHAL_CP3_SA_SIZE
  404. bbci.l a2, 3, 2f
  405. l32i a14, a13, 12
  406. add a3, a14, a15
  407. xchal_cp3_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  408. 2:
  409. #endif
  410. #if XCHAL_CP4_SA_SIZE
  411. bbci.l a2, 4, 2f
  412. l32i a14, a13, 16
  413. add a3, a14, a15
  414. xchal_cp4_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  415. 2:
  416. #endif
  417. #if XCHAL_CP5_SA_SIZE
  418. bbci.l a2, 5, 2f
  419. l32i a14, a13, 20
  420. add a3, a14, a15
  421. xchal_cp5_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  422. 2:
  423. #endif
  424. #if XCHAL_CP6_SA_SIZE
  425. bbci.l a2, 6, 2f
  426. l32i a14, a13, 24
  427. add a3, a14, a15
  428. xchal_cp6_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  429. 2:
  430. #endif
  431. #if XCHAL_CP7_SA_SIZE
  432. bbci.l a2, 7, 2f
  433. l32i a14, a13, 28
  434. add a3, a14, a15
  435. xchal_cp7_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  436. 2:
  437. #endif
  438. .Ldone:
  439. ret
  440. #endif
  441. /*******************************************************************************
  442. _xt_coproc_restorecs
  443. Restore any callee-saved coprocessor state for the incoming thread.
  444. This function is called from coprocessor exception handling, when giving
  445. ownership to a thread that solicited a context switch earlier. It calls a
  446. system-specific function to get the coprocessor save area base address.
  447. Entry conditions:
  448. - The incoming thread is set as the current thread.
  449. - CPENABLE is set up correctly for all required coprocessors.
  450. - a2 = mask of coprocessors to be restored.
  451. Exit conditions:
  452. - All necessary CP callee-saved state has been restored.
  453. - CPENABLE - unchanged.
  454. - Registers a2-a7, a13-a15 have been trashed.
  455. Must be called from assembly code only, using CALL0.
  456. *******************************************************************************/
  457. #if XCHAL_CP_NUM > 0
  458. .global _xt_coproc_restorecs
  459. .type _xt_coproc_restorecs,@function
  460. .align 4
  461. .literal_position
  462. .align 4
  463. _xt_coproc_restorecs:
  464. mov a14, a0 /* save return address */
  465. call0 XT_RTOS_CP_STATE /* get address of CP save area */
  466. mov a0, a14 /* restore return address */
  467. beqz a15, .Ldone2 /* if none then nothing to do */
  468. l16ui a3, a15, XT_CP_CS_ST /* a3 = which CPs have been saved */
  469. xor a3, a3, a2 /* clear the ones being restored */
  470. s32i a3, a15, XT_CP_CS_ST /* update saved CP mask */
  471. movi a13, _xt_coproc_sa_offset /* array of CP save offsets */
  472. l32i a15, a15, XT_CP_ASA /* a15 = base of aligned save area */
  473. #if XCHAL_CP0_SA_SIZE
  474. bbci.l a2, 0, 2f /* CP 0 not enabled */
  475. l32i a14, a13, 0 /* a14 = _xt_coproc_sa_offset[0] */
  476. add a3, a14, a15 /* a3 = save area for CP 0 */
  477. xchal_cp0_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  478. 2:
  479. #endif
  480. #if XCHAL_CP1_SA_SIZE
  481. bbci.l a2, 1, 2f /* CP 1 not enabled */
  482. l32i a14, a13, 4 /* a14 = _xt_coproc_sa_offset[1] */
  483. add a3, a14, a15 /* a3 = save area for CP 1 */
  484. xchal_cp1_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  485. 2:
  486. #endif
  487. #if XCHAL_CP2_SA_SIZE
  488. bbci.l a2, 2, 2f
  489. l32i a14, a13, 8
  490. add a3, a14, a15
  491. xchal_cp2_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  492. 2:
  493. #endif
  494. #if XCHAL_CP3_SA_SIZE
  495. bbci.l a2, 3, 2f
  496. l32i a14, a13, 12
  497. add a3, a14, a15
  498. xchal_cp3_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  499. 2:
  500. #endif
  501. #if XCHAL_CP4_SA_SIZE
  502. bbci.l a2, 4, 2f
  503. l32i a14, a13, 16
  504. add a3, a14, a15
  505. xchal_cp4_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  506. 2:
  507. #endif
  508. #if XCHAL_CP5_SA_SIZE
  509. bbci.l a2, 5, 2f
  510. l32i a14, a13, 20
  511. add a3, a14, a15
  512. xchal_cp5_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  513. 2:
  514. #endif
  515. #if XCHAL_CP6_SA_SIZE
  516. bbci.l a2, 6, 2f
  517. l32i a14, a13, 24
  518. add a3, a14, a15
  519. xchal_cp6_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  520. 2:
  521. #endif
  522. #if XCHAL_CP7_SA_SIZE
  523. bbci.l a2, 7, 2f
  524. l32i a14, a13, 28
  525. add a3, a14, a15
  526. xchal_cp7_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
  527. 2:
  528. #endif
  529. .Ldone2:
  530. ret
  531. #endif