misc_helpers.S 5.91 KB
Newer Older
1
/*
2
 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of ARM nor the names of its contributors may be used
 * to endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

31
#include <arch.h>
32
#include <asm_macros.S>
33

34
35
36
37
38
39
40
41
42
	.globl	enable_irq
	.globl	disable_irq

	.globl	enable_fiq
	.globl	disable_fiq

	.globl	enable_serror
	.globl	disable_serror

43
44
45
	.globl	enable_debug_exceptions
	.globl	disable_debug_exceptions

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	.globl	read_daif
	.globl	write_daif

	.globl	read_spsr
	.globl	read_spsr_el1
	.globl	read_spsr_el2
	.globl	read_spsr_el3

	.globl	write_spsr
	.globl	write_spsr_el1
	.globl	write_spsr_el2
	.globl	write_spsr_el3

	.globl	read_elr
	.globl	read_elr_el1
	.globl	read_elr_el2
	.globl	read_elr_el3

	.globl	write_elr
	.globl	write_elr_el1
	.globl	write_elr_el2
	.globl	write_elr_el3

	.globl	get_afflvl_shift
	.globl	mpidr_mask_lower_afflvls
	.globl	dsb
	.globl	isb
	.globl	sev
	.globl	wfe
	.globl	wfi
	.globl	eret
	.globl	smc

79
80
	.globl	zeromem16
	.globl	memcpy16
81
82


83
func get_afflvl_shift
84
85
86
87
88
89
	cmp	x0, #3
	cinc	x0, x0, eq
	mov	x1, #MPIDR_AFFLVL_SHIFT
	lsl	x0, x0, x1
	ret

90
func mpidr_mask_lower_afflvls
91
92
93
94
95
96
97
98
99
100
101
102
	cmp	x1, #3
	cinc	x1, x1, eq
	mov	x2, #MPIDR_AFFLVL_SHIFT
	lsl	x2, x1, x2
	lsr	x0, x0, x2
	lsl	x0, x0, x2
	ret

	/* -----------------------------------------------------
	 * Asynchronous exception manipulation accessors
	 * -----------------------------------------------------
	 */
103
func enable_irq
104
105
106
107
	msr	daifclr, #DAIF_IRQ_BIT
	ret


108
func enable_fiq
109
110
111
112
	msr	daifclr, #DAIF_FIQ_BIT
	ret


113
func enable_serror
114
115
116
117
	msr	daifclr, #DAIF_ABT_BIT
	ret


118
func enable_debug_exceptions
119
120
121
122
	msr	daifclr, #DAIF_DBG_BIT
	ret


123
func disable_irq
124
125
126
127
	msr	daifset, #DAIF_IRQ_BIT
	ret


128
func disable_fiq
129
130
131
132
	msr	daifset, #DAIF_FIQ_BIT
	ret


133
func disable_serror
134
135
136
137
	msr	daifset, #DAIF_ABT_BIT
	ret


138
func disable_debug_exceptions
139
140
141
142
	msr	daifset, #DAIF_DBG_BIT
	ret


143
func read_daif
144
145
146
147
	mrs	x0, daif
	ret


148
func write_daif
149
150
151
152
	msr	daif, x0
	ret


153
func read_spsr
154
155
156
157
158
159
160
161
162
	mrs	x0, CurrentEl
	cmp	x0, #(MODE_EL1 << MODE_EL_SHIFT)
	b.eq	read_spsr_el1
	cmp	x0, #(MODE_EL2 << MODE_EL_SHIFT)
	b.eq	read_spsr_el2
	cmp	x0, #(MODE_EL3 << MODE_EL_SHIFT)
	b.eq	read_spsr_el3


163
func read_spsr_el1
164
165
166
167
	mrs	x0, spsr_el1
	ret


168
func read_spsr_el2
169
170
171
172
	mrs	x0, spsr_el2
	ret


173
func read_spsr_el3
174
175
176
177
	mrs	x0, spsr_el3
	ret


178
func write_spsr
179
180
181
182
183
184
185
186
187
	mrs	x1, CurrentEl
	cmp	x1, #(MODE_EL1 << MODE_EL_SHIFT)
	b.eq	write_spsr_el1
	cmp	x1, #(MODE_EL2 << MODE_EL_SHIFT)
	b.eq	write_spsr_el2
	cmp	x1, #(MODE_EL3 << MODE_EL_SHIFT)
	b.eq	write_spsr_el3


188
func write_spsr_el1
189
190
191
192
193
	msr	spsr_el1, x0
	isb
	ret


194
func write_spsr_el2
195
196
197
198
199
	msr	spsr_el2, x0
	isb
	ret


200
func write_spsr_el3
201
202
203
204
205
	msr	spsr_el3, x0
	isb
	ret


206
func read_elr
207
208
209
210
211
212
213
214
215
	mrs	x0, CurrentEl
	cmp	x0, #(MODE_EL1 << MODE_EL_SHIFT)
	b.eq	read_elr_el1
	cmp	x0, #(MODE_EL2 << MODE_EL_SHIFT)
	b.eq	read_elr_el2
	cmp	x0, #(MODE_EL3 << MODE_EL_SHIFT)
	b.eq	read_elr_el3


216
func read_elr_el1
217
218
219
220
	mrs	x0, elr_el1
	ret


221
func read_elr_el2
222
223
224
225
	mrs	x0, elr_el2
	ret


226
func read_elr_el3
227
228
229
230
	mrs	x0, elr_el3
	ret


231
func write_elr
232
233
234
235
236
237
238
239
240
	mrs	x1, CurrentEl
	cmp	x1, #(MODE_EL1 << MODE_EL_SHIFT)
	b.eq	write_elr_el1
	cmp	x1, #(MODE_EL2 << MODE_EL_SHIFT)
	b.eq	write_elr_el2
	cmp	x1, #(MODE_EL3 << MODE_EL_SHIFT)
	b.eq	write_elr_el3


241
func write_elr_el1
242
243
244
245
246
	msr	elr_el1, x0
	isb
	ret


247
func write_elr_el2
248
249
250
251
252
	msr	elr_el2, x0
	isb
	ret


253
func write_elr_el3
254
255
256
257
258
	msr	elr_el3, x0
	isb
	ret


259
func dsb
260
261
262
263
	dsb	sy
	ret


264
func isb
265
266
267
268
	isb
	ret


269
func sev
270
271
272
273
	sev
	ret


274
func wfe
275
276
277
278
	wfe
	ret


279
func wfi
280
281
282
283
	wfi
	ret


284
func eret
285
286
287
	eret


288
func smc
289
	smc	#0
290
291
292
293
294
295
296
297

/* -----------------------------------------------------------------------
 * void zeromem16(void *mem, unsigned int length);
 *
 * Initialise a memory region to 0.
 * The memory address must be 16-byte aligned.
 * -----------------------------------------------------------------------
 */
298
func zeromem16
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
	add	x2, x0, x1
/* zero 16 bytes at a time */
z_loop16:
	sub	x3, x2, x0
	cmp	x3, #16
	b.lt	z_loop1
	stp	xzr, xzr, [x0], #16
	b	z_loop16
/* zero byte per byte */
z_loop1:
	cmp	x0, x2
	b.eq	z_end
	strb	wzr, [x0], #1
	b	z_loop1
z_end:	ret


/* --------------------------------------------------------------------------
 * void memcpy16(void *dest, const void *src, unsigned int length)
 *
 * Copy length bytes from memory area src to memory area dest.
 * The memory areas should not overlap.
 * Destination and source addresses must be 16-byte aligned.
 * --------------------------------------------------------------------------
 */
324
func memcpy16
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/* copy 16 bytes at a time */
m_loop16:
	cmp	x2, #16
	b.lt	m_loop1
	ldp	x3, x4, [x1], #16
	stp	x3, x4, [x0], #16
	sub	x2, x2, #16
	b	m_loop16
/* copy byte per byte */
m_loop1:
	cbz	x2, m_end
	ldrb	w3, [x1], #1
	strb	w3, [x0], #1
	subs	x2, x2, #1
	b.ne	m_loop1
m_end:	ret