blob: 05e90f9529c0e4143cbb5ed7c00e870e54844347 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
2 * Copyright (c) 2013, ARM Limited. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch_helpers.h>
32
33 .globl enable_irq
34 .globl disable_irq
35
36 .globl enable_fiq
37 .globl disable_fiq
38
39 .globl enable_serror
40 .globl disable_serror
41
Sandrine Bailleux37382742013-11-18 17:26:59 +000042 .globl enable_debug_exceptions
43 .globl disable_debug_exceptions
44
Achin Gupta4f6ad662013-10-25 09:08:21 +010045 .globl read_daif
46 .globl write_daif
47
48 .globl read_spsr
49 .globl read_spsr_el1
50 .globl read_spsr_el2
51 .globl read_spsr_el3
52
53 .globl write_spsr
54 .globl write_spsr_el1
55 .globl write_spsr_el2
56 .globl write_spsr_el3
57
58 .globl read_elr
59 .globl read_elr_el1
60 .globl read_elr_el2
61 .globl read_elr_el3
62
63 .globl write_elr
64 .globl write_elr_el1
65 .globl write_elr_el2
66 .globl write_elr_el3
67
68 .globl get_afflvl_shift
69 .globl mpidr_mask_lower_afflvls
70 .globl dsb
71 .globl isb
72 .globl sev
73 .globl wfe
74 .globl wfi
75 .globl eret
76 .globl smc
77
78
79 .section .text, "ax"
80
81get_afflvl_shift:; .type get_afflvl_shift, %function
82 cmp x0, #3
83 cinc x0, x0, eq
84 mov x1, #MPIDR_AFFLVL_SHIFT
85 lsl x0, x0, x1
86 ret
87
88mpidr_mask_lower_afflvls:; .type mpidr_mask_lower_afflvls, %function
89 cmp x1, #3
90 cinc x1, x1, eq
91 mov x2, #MPIDR_AFFLVL_SHIFT
92 lsl x2, x1, x2
93 lsr x0, x0, x2
94 lsl x0, x0, x2
95 ret
96
97 /* -----------------------------------------------------
98 * Asynchronous exception manipulation accessors
99 * -----------------------------------------------------
100 */
101enable_irq:; .type enable_irq, %function
102 msr daifclr, #DAIF_IRQ_BIT
103 ret
104
105
106enable_fiq:; .type enable_fiq, %function
107 msr daifclr, #DAIF_FIQ_BIT
108 ret
109
110
111enable_serror:; .type enable_serror, %function
112 msr daifclr, #DAIF_ABT_BIT
113 ret
114
115
Sandrine Bailleux37382742013-11-18 17:26:59 +0000116enable_debug_exceptions:
117 msr daifclr, #DAIF_DBG_BIT
118 ret
119
120
Achin Gupta4f6ad662013-10-25 09:08:21 +0100121disable_irq:; .type disable_irq, %function
122 msr daifset, #DAIF_IRQ_BIT
123 ret
124
125
126disable_fiq:; .type disable_fiq, %function
127 msr daifset, #DAIF_FIQ_BIT
128 ret
129
130
131disable_serror:; .type disable_serror, %function
132 msr daifset, #DAIF_ABT_BIT
133 ret
134
135
Sandrine Bailleux37382742013-11-18 17:26:59 +0000136disable_debug_exceptions:
137 msr daifset, #DAIF_DBG_BIT
138 ret
139
140
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141read_daif:; .type read_daif, %function
142 mrs x0, daif
143 ret
144
145
146write_daif:; .type write_daif, %function
147 msr daif, x0
148 ret
149
150
151read_spsr:; .type read_spsr, %function
152 mrs x0, CurrentEl
153 cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
154 b.eq read_spsr_el1
155 cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
156 b.eq read_spsr_el2
157 cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
158 b.eq read_spsr_el3
159
160
161read_spsr_el1:; .type read_spsr_el1, %function
162 mrs x0, spsr_el1
163 ret
164
165
166read_spsr_el2:; .type read_spsr_el2, %function
167 mrs x0, spsr_el2
168 ret
169
170
171read_spsr_el3:; .type read_spsr_el3, %function
172 mrs x0, spsr_el3
173 ret
174
175
176write_spsr:; .type write_spsr, %function
177 mrs x1, CurrentEl
178 cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
179 b.eq write_spsr_el1
180 cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
181 b.eq write_spsr_el2
182 cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
183 b.eq write_spsr_el3
184
185
186write_spsr_el1:; .type write_spsr_el1, %function
187 msr spsr_el1, x0
188 isb
189 ret
190
191
192write_spsr_el2:; .type write_spsr_el2, %function
193 msr spsr_el2, x0
194 isb
195 ret
196
197
198write_spsr_el3:; .type write_spsr_el3, %function
199 msr spsr_el3, x0
200 isb
201 ret
202
203
204read_elr:; .type read_elr, %function
205 mrs x0, CurrentEl
206 cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
207 b.eq read_elr_el1
208 cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
209 b.eq read_elr_el2
210 cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
211 b.eq read_elr_el3
212
213
214read_elr_el1:; .type read_elr_el1, %function
215 mrs x0, elr_el1
216 ret
217
218
219read_elr_el2:; .type read_elr_el2, %function
220 mrs x0, elr_el2
221 ret
222
223
224read_elr_el3:; .type read_elr_el3, %function
225 mrs x0, elr_el3
226 ret
227
228
229write_elr:; .type write_elr, %function
230 mrs x1, CurrentEl
231 cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
232 b.eq write_elr_el1
233 cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
234 b.eq write_elr_el2
235 cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
236 b.eq write_elr_el3
237
238
239write_elr_el1:; .type write_elr_el1, %function
240 msr elr_el1, x0
241 isb
242 ret
243
244
245write_elr_el2:; .type write_elr_el2, %function
246 msr elr_el2, x0
247 isb
248 ret
249
250
251write_elr_el3:; .type write_elr_el3, %function
252 msr elr_el3, x0
253 isb
254 ret
255
256
257dsb:; .type dsb, %function
258 dsb sy
259 ret
260
261
262isb:; .type isb, %function
263 isb
264 ret
265
266
267sev:; .type sev, %function
268 sev
269 ret
270
271
272wfe:; .type wfe, %function
273 wfe
274 ret
275
276
277wfi:; .type wfi, %function
278 wfi
279 ret
280
281
282eret:; .type eret, %function
283 eret
284
285
286smc:; .type smc, %function
287 smc #0