Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / athos / src / xtos / intlevel-set.S
1 // intlevel-set.S - Interrupt related assembler code - _xtos_set_intlevel
2
3 // Copyright (c) 2004-2010 Tensilica Inc.
4 //
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:
12 //
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
15 //
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.
23
24 #include <xtensa/coreasm.h>
25 #include <xtensa/config/specreg.h>
26 #include "xtos-internal.h"
27
28
29 /***************************************************************************
30  *  unsigned  _xtos_set_intlevel(int intlevel);
31  *
32  *  _xtos_set_intlevel() is used to set the current priority from C code;
33  *  it can be called from the application or from a C interrupt handler.
34  *
35  *  NOTE:  This version allows the 'intlevel' parameter to be computed
36  *  at run-time, and thus is longer.  It is much more efficient, and
37  *  highly recommented, to use the XTOS_SET_INTLEVEL(intlevel) macro instead
38  *  (which requires a constant intlevel).
39  */
40
41         .text
42         .align 4
43         .global _xtos_set_intlevel
44         .type   _xtos_set_intlevel,@function
45 _xtos_set_intlevel:
46         abi_entry
47 #if XCHAL_HAVE_INTERRUPTS
48 # if XCHAL_HAVE_XEA2
49         /*  In XEA2, we can simply safely set PS.INTLEVEL directly:  */
50         rsr     a3, PS          // get old (current) PS.INTLEVEL
51         movi    a4, ~0xF
52         extui   a2, a2, 0, 4    // keep only INTLEVEL bits of parameter
53         and     a4, a4, a3      // mask out PS.INTLEVEL
54         or      a4, a4, a2      // insert requested INTLEVEL
55         wsr     a4, PS          // update PS.INTLEVEL
56         extui   a2, a3, 0, 4    // return only old PS.INTLEVEL field
57         rsync                   // wait for WSR to PS to complete
58 # else
59         /*  In XEA1, we have to rely on INTENABLE register virtualization:  */
60         movi    a4, Xthal_intlevel_andbelow_mask
61         extui   a3, a2, 0, 4    // keep only INTLEVEL bits of parameter
62         addx4   a5, a3, a4      // index mask to use
63         l32i    a3, a5, 0       // get mask of interrupts at requested intlevel and below
64         movi    a5, -1          // all 1's
65         movi    a4, _xtos_intstruct
66         xor     a3, a3, a5      // mask of interrupts at intlevels above the requested one (to enable)
67         xtos_lock       a7      // MUST USE highest address register of function to avoid window overflows in critical section
68         l32i    a2, a4, XTOS_VPRI_ENABLED_OFS   // return old xtos_vpri_enabled (current vpri)
69         l32i    a5, a4, XTOS_ENABLED_OFS        // a5 = xtos_enabled
70         s32i    a3, a4, XTOS_VPRI_ENABLED_OFS   // set new xtos_vpri_enabled (current vpri)
71         and     a5, a5, a3                      // a5 = xtos_enabled & xtos_vpri_enabled
72         wsr     a5, INTENABLE
73         xtos_unlock     a7
74 # endif
75 #endif /*XCHAL_HAVE_INTERRUPTS*/
76         abi_return
77
78         .size   _xtos_set_intlevel, . - _xtos_set_intlevel
79