Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / build / magpie_1_1 / sboot / athos / src / xtos / intlevel-restore.S
1 // intlevel-restore.S - Interrupt related assembler code - _xtos_restore_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  *  void  _xtos_restore_intlevel(unsigned restoreval);
31  *
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).
35  *
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).
40  *
41  *  NOTE:  In XEA1, this function is implemented further below, identically
42  *  to _xtos_set_vpri().
43  *
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.
47  */
48
49         .text
50         .global _xtos_restore_intlevel
51         .type   _xtos_restore_intlevel,@function
52 #if XCHAL_HAVE_XEA2
53         .align 4
54 _xtos_restore_intlevel:
55         abi_entry
56 # if XCHAL_HAVE_INTERRUPTS
57         wsr     a2, PS          // restore PS
58         rsync                   // wait for WSR to PS to complete
59 # endif
60         abi_return
61         .size   _xtos_restore_intlevel, . - _xtos_restore_intlevel
62 #endif
63
64
65
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.
69  */
70
71         .global _xtos_set_vpri
72         .type   _xtos_set_vpri,@function
73         .align 4
74 _xtos_set_vpri:
75 #if XCHAL_HAVE_XEA1
76 _xtos_restore_intlevel:
77 #endif
78         abi_entry
79 #if XCHAL_HAVE_INTERRUPTS && XTOS_VIRTUAL_INTENABLE
80         mov     a3, a2
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
87         wsr     a5, INTENABLE
88         xtos_unlock     a7
89 #endif /*XCHAL_HAVE_INTERRUPTS*/
90         abi_return
91         .size   _xtos_set_vpri, . - _xtos_set_vpri
92