1 // exc-return.S - Shared exception/interrupt return code
3 // Copyright (c) 2002-2004, 2006-2007, 2010 Tensilica Inc.
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <xtensa/coreasm.h>
25 #include <xtensa/corebits.h>
26 #include <xtensa/config/specreg.h>
27 #include "xtos-internal.h"
29 #if XCHAL_HAVE_EXCEPTIONS
33 .global _xtos_return_from_exc
34 _xtos_return_from_exc:
36 #ifdef __XTENSA_CALL0_ABI__
38 l32i a0, a1, UEXC_a0 // restore general registers, pc, ps
45 l32i a10, a1, UEXC_a10
46 l32i a11, a1, UEXC_a11
47 l32i a12, a1, UEXC_a12
48 l32i a13, a1, UEXC_a13
49 l32i a14, a1, UEXC_a14
50 l32i a15, a1, UEXC_a15
60 rsync // wait for WSR to PS to complete
62 addi a1, a1, ESF_TOTALSIZE // restore sp
66 #else /* ! __XTENSA_CALL0_ABI__ */
69 // Here we rotated back by N registers, to the interrupted code's register window.
70 // NOTA: a2 and a3 might contain something useful, but we haven't determined
71 // what that might be yet (for now, a2 contains nested-C-func call-chain ptr).
73 // NOTE: a5 still contains the exception window's exception stack frame pointer.
76 s32i a2, a5, ESF_TOTALSIZE-20 // restore nested-C-func call-chain ptr
80 wsr a2, PS // for XEA2, this sets EXCM; for XEA1, this sets INTLEVEL to 1; ...
82 # if XCHAL_HAVE_XEA1 && XCHAL_HAVE_INTERRUPTS
83 l32i a4, a5, UEXC_sar // load INTENABLE value that restores original vpri
85 rsync // wait for WSR to PS to complete
86 wsr a4, INTENABLE // update INTENABLE to restore original vpri (PS.INTLEVEL=1 here)
91 rsync // wait for WSR to PS to complete
94 /* FIXME: Enabling this here may break task-engine builds
95 * because task engines have exceptions (sort of), but they do
96 * not have the EPC_1 special register. XCHAL_HAVE_INTERRUPTS
97 * is incorrect for normal configs without interrupts but with
98 * exceptions (we still need to restore EPC_1). The correct
99 * solution is to define XCHAL_HAVE_EXCEPTIONS more strictly
100 * to mean something like "Have exceptions with
101 * user/kernel/double vectors" so that task engines are
102 * excluded. This would be a change to
103 * <xtensa/config/core.h>. */
107 // - we cannot get window overflows anymore -- we're NOT in a valid windowed context
108 // - low-priority interrupts are still disabled
110 // NOTE: we don't restore EXCCAUSE or EXCVADDR, not needed.
118 #endif /* __XTENSA_CALL0_ABI__ */
120 .size _xtos_return_from_exc, . - _xtos_return_from_exc
122 #endif /* XCHAL_HAVE_EXCEPTIONS */