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 / reset-unneeded.S
1 // reset-unneeded.S  --  Optional Extraneous Reset Code
2 // $Id: //depot/rel/Cottonwood/Xtensa/OS/xtos/reset-unneeded.S#2 $
3
4 // Copyright (c) 2002-2006 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 //  This file is meant to be included by another, e.g. crt1-***.S .
26 //  The code it contains is generally not needed, so is kept in a
27 //  separate file for clarity of other code.
28
29 #if XTOS_RESET_UNNEEDED
30         /*
31          *  Reset registers that don't really need to be reset,
32          *  but may provide more predictability when buggy code
33          *  relies on uninitialized state.  It might also clear
34          *  "X"s a bit earlier in hardware simulations.
35          *
36          *  NOTE:  This code is by no means exhaustive.
37          *  More processor registers/states could be reset if desired.
38          *  This is just an example.
39          *
40          *  ASSUMPTION:  a0 is still zero at this point.
41          */
42
43         // Interrupt initialization.
44         // Because INTENABLE is cleared by the reset vector, clearing the
45         // interrupt-pending register should not be needed.  This assumes
46         // that any application setting up an interrupt will register and
47         // clear it before enabling it, which is the recommended sequence.
48         // 
49 #if XCHAL_HAVE_INTERRUPTS && (XCHAL_INTCLEARABLE_MASK != 0) && !XCHAL_HAVE_FULL_RESET
50         movi    a2, XCHAL_INTCLEARABLE_MASK
51         wsr     a2, INTCLEAR            // clear software and edge-trig ints
52 #endif
53
54         // Timer initialization (not strictly required, but sometimes helpful)
55         .macro  reset_timer     num
56          wsr    a0, CCOMPARE_0 + \num
57         .endm
58         iterate 0, XCHAL_NUM_TIMERS-1, reset_timer
59
60 # if XCHAL_HAVE_WINDOWED
61         // Windowed address register init -- initialize entire physical AR file
62         movi    a0, XCHAL_NUM_AREGS/8   // number of 8-register chunks
63 arloop:
64         addi    a8, a0, -1              // countdown into next chunk's a0
65         movi    a0, 0
66         movi    a1, 0
67         movi    a2, 0
68         movi    a3, 0
69         movi    a4, 0
70         movi    a5, 0
71         movi    a6, 0
72         movi    a7, 0
73         rotw    2                       // rotate to next chunk
74         bnez    a0, arloop
75         //  NOTE:  WINDOWBASE is back to zero at this point.
76 # else /* XCHAL_HAVE_WINDOWED */
77         // Non-windowed address register init
78         movi    a1, 0
79         movi    a2, 0
80         movi    a3, 0
81         movi    a4, 0
82         movi    a5, 0
83         movi    a6, 0
84         movi    a7, 0
85         movi    a8, 0
86         movi    a9, 0
87         movi    a10, 0
88         movi    a11, 0
89         movi    a12, 0
90         movi    a13, 0
91         movi    a14, 0
92         movi    a15, 0
93 # endif /* XCHAL_HAVE_WINDOWED */
94         //  Now all address registers are zero.
95
96         // Initialize LBEG, LEND, and LCOUNT.
97 # if XCHAL_HAVE_LOOPS
98         wsr     a0, LCOUNT              // note: LCOUNT gets cleared by processor reset
99         wsr     a0, LBEG
100         wsr     a0, LEND
101 # endif
102
103 # if XCHAL_HAVE_DEBUG
104         .macro  reset_dbreaka   num
105          wsr    a0, DBREAKA + \num
106         .endm
107         .macro  reset_ibreaka   num
108          wsr    a0, IBREAKA + \num
109         .endm
110         iterate 0, XCHAL_NUM_DBREAK-1, reset_dbreaka
111         iterate 0, XCHAL_NUM_IBREAK-1, reset_ibreaka
112 # endif
113
114         // SAR initialization
115         ssai    0
116
117         // Exception initialization
118 # if XCHAL_HAVE_EXCEPTIONS
119         wsr     a0, EPC+1
120         wsr     a0, EXCSAVE+1
121         wsr     a0, EXCCAUSE
122 # endif
123
124 # if XCHAL_HAVE_HIGHLEVEL_INTERRUPTS
125         .macro  reset_int       num
126          wsr    a0, EPC + \num
127          wsr    a0, EPS + \num
128          wsr    a0, EXCSAVE + \num
129         .endm
130         iterate 2, XCHAL_NUM_INTLEVELS, reset_int
131 # endif
132
133         // Booleans initialization
134 # if XCHAL_HAVE_BOOLEANS
135         wsr     a0, BR
136 # endif
137
138         // MAC16 initialization
139 # if XCHAL_HAVE_MAC16
140         wsr     a0, ACCLO
141         wsr     a0, ACCHI
142         wsr     a0, M0
143         wsr     a0, M1
144         wsr     a0, M2
145         wsr     a0, M3
146 # endif
147
148         // OCD initialization
149 # if XCHAL_HAVE_OCD
150         wsr     a0, DDR
151 # endif
152
153         isync                   // wait for all the above to take effect
154
155 #endif /* XTOS_RESET_UNNEEDED */
156