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 / switch_context.S
1 /* switch_contexts.S - setup for multiple contexts */
2
3 /*
4  * Copyright (c) 2003-2010 Tensilica Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 #include <xtensa/coreasm.h>
27 #include <xtensa/xtruntime-frames.h>
28
29 #if XCHAL_NUM_CONTEXTS > 1
30
31
32 /*
33  *  void        _xtos_setup_context(int context_num, StartInfo *info);
34  */
35         .align 4 
36         .global _xtos_setup_context
37         .type _xtos_setup_context,@function
38 _xtos_setup_context:
39         abi_entry
40 #if XCHAL_HAVE_INTERRUPTS
41         rsil    a5, 15                  /* disable interrupts so we can use EXCSAVE_1 */
42 #else
43         rsr     a5, PS                  /* just read PS */
44 #endif
45         wsr     a3, EXCSAVE_1           /* save pointer to new context info */
46         s32i    a5, a3, INFO_prevps     /* save previous PS */
47         movi    a4, ~0x01F00000         /* mask out PS.CTXT */
48         slli    a2, a2, 20              /* shift up new PS.CTXT value */
49         and     a4, a5, a4
50         or      a4, a4, a2              /* new PS value */
51         wsr     a4, PS
52         rsync
53         /*  We're now in the new context!  */
54         movi    a0, 0
55         movi    a1, 1
56         wsr     a1, WINDOWSTART
57         wsr     a0, WINDOWBASE
58         rsync
59         rsr     a9, EXCSAVE_1           /* get pointer to context info */
60         movi    a0, 0                   /* terminate call frames */
61         l32i    a1, a9, INFO_sp         /* get stack pointer */
62         l32i    a10, a9, INFO_arg1      /* get start function's arguments... */
63         l32i    a8, a9, INFO_funcpc     /* get start function's address */
64         /*  Okay, now switch back to context zero:  */
65         l32i    a9, a9, INFO_prevps     /* retrieve previous PS */
66         wsr     a9, PS
67         rsync
68         /*  Back to original context!  */
69         abi_return
70
71         .size   _xtos_setup_context, . - _xtos_setup_context
72
73
74
75         /*
76          *  This is the first thing to be executed in the new context
77          *  by explicit setting of PC:
78          */
79         .align 4 
80         .global _xtos_start_context
81 _xtos_start_context:
82 #ifdef __XTENSA_CALL0_ABI__
83         Crash the assembler here:  I think this is wrong.
84         callx0  a8
85 #else
86         callx8  a8
87 #endif
88 1:      nop
89         j       1b      /* do nothing until context 0 exits */
90         .size   _xtos_start_context, . - _xtos_start_context
91
92
93 #endif /* XCHAL_NUM_CONTEXTS > 1 */
94