1 // intlevel-restore.S - Interrupt related assembler code - _xtos_restore_intlevel
3 // Copyright (c) 2004-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/config/specreg.h>
26 #include "xtos-internal.h"
29 /***************************************************************************
30 * void _xtos_restore_intlevel(unsigned restoreval);
32 * _xtos_restore_intlevel() restores the current interrupt level
33 * according to a value returned by _xtos_set_intlevel() or
34 * _xtos_set_min_intlevel() (or one of the corresponding macros).
36 * NOTE: In XEA2, this function may restore the entire PS register, not
37 * just the PS.INTLEVEL field. If some other PS field(s) must be changed
38 * and kept intact across restoring PS.INTLEVEL (this is generally unlikely),
39 * use the XTOS_RESTORE_JUST_INTLEVEL() macro instead (which is slower).
41 * NOTE: In XEA1, this function is implemented further below, identically
42 * to _xtos_set_vpri().
44 * NOTE: The macro form of this function (XTOS_RESTORE_INTLEVEL())
45 * is recommended (for XEA2 configs or where the config is unknown)
46 * because it may be more efficient.
50 .global _xtos_restore_intlevel
51 .type _xtos_restore_intlevel,@function
54 _xtos_restore_intlevel:
56 # if XCHAL_HAVE_INTERRUPTS
57 wsr a2, PS // restore PS
58 rsync // wait for WSR to PS to complete
61 .size _xtos_restore_intlevel, . - _xtos_restore_intlevel
66 /***************************************************************************
67 * _xtos_set_vpri() is used to set the current virtual priority from C code;
68 * it can be called from the application or from a C interrupt handler.
71 .global _xtos_set_vpri
72 .type _xtos_set_vpri,@function
76 _xtos_restore_intlevel:
79 #if XCHAL_HAVE_INTERRUPTS && XTOS_VIRTUAL_INTENABLE
81 movi a4, _xtos_intstruct
82 xtos_lock a7 // MUST USE highest address register of function to avoid window overflows in critical section
83 l32i a2, a4, XTOS_VPRI_ENABLED_OFS // return old xtos_vpri_enabled (current vpri)
84 l32i a5, a4, XTOS_ENABLED_OFS // a3 = xtos_enabled
85 s32i a3, a4, XTOS_VPRI_ENABLED_OFS // set new xtos_vpri_enabled (current vpri)
86 and a5, a5, a3 // a5 = xtos_enabled & xtos_vpri_enabled
89 #endif /*XCHAL_HAVE_INTERRUPTS*/
91 .size _xtos_set_vpri, . - _xtos_set_vpri