blob: 6cf1a19f7a59628c6189c12b543db5f94d06e6f2 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
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
Dan Handley2bd4ef22014-04-09 13:14:54 +010031#include <arch.h>
32
33
Achin Gupta4f6ad662013-10-25 09:08:21 +010034 .macro func_prologue
35 stp x29, x30, [sp, #-0x10]!
36 mov x29,sp
37 .endm
38
39 .macro func_epilogue
40 ldp x29, x30, [sp], #0x10
41 .endm
42
43
44 .macro dcache_line_size reg, tmp
Achin Gupta07f4e072014-02-02 12:02:23 +000045 mrs \tmp, ctr_el0
Achin Gupta4f6ad662013-10-25 09:08:21 +010046 ubfx \tmp, \tmp, #16, #4
Achin Gupta07f4e072014-02-02 12:02:23 +000047 mov \reg, #4
48 lsl \reg, \reg, \tmp
Achin Gupta4f6ad662013-10-25 09:08:21 +010049 .endm
50
51
52 .macro icache_line_size reg, tmp
Achin Gupta07f4e072014-02-02 12:02:23 +000053 mrs \tmp, ctr_el0
54 and \tmp, \tmp, #0xf
55 mov \reg, #4
56 lsl \reg, \reg, \tmp
Achin Gupta4f6ad662013-10-25 09:08:21 +010057 .endm
58
59
Achin Gupta4f6ad662013-10-25 09:08:21 +010060 .macro smc_check label
61 bl read_esr
62 ubfx x0, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
63 cmp x0, #EC_AARCH64_SMC
64 b.ne $label
65 .endm
66
67
68 .macro setup_dcsw_op_args start_level, end_level, clidr, shift, fw, ls
69 mrs \clidr, clidr_el1
70 mov \start_level, xzr
71 ubfx \end_level, \clidr, \shift, \fw
72 lsl \end_level, \end_level, \ls
73 .endm
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000074
75 /*
76 * This macro verifies that the a given vector doesn't exceed the
77 * architectural limit of 32 instructions. This is meant to be placed
78 * immedately after the last instruction in the vector. It takes the
79 * vector entry as the parameter
80 */
81 .macro check_vector_size since
82 .if (. - \since) > (32 * 4)
83 .error "Vector exceeds 32 instructions"
84 .endif
85 .endm
Andrew Thoelke38bde412014-03-18 13:46:55 +000086
87 /*
88 * This macro is used to create a function label and place the
89 * code into a separate text section based on the function name
90 * to enable elimination of unused code during linking
91 */
92 .macro func _name
93 .section .text.\_name, "ax"
94 .type \_name, %function
95 \_name:
96 .endm
Andrew Thoelke65668f92014-03-20 10:48:23 +000097
98 /*
99 * This macro declares an array of 1 or more stacks, properly
100 * aligned and in the requested section
101 */
102#define STACK_ALIGN 6
103
104 .macro declare_stack _name, _section, _size, _count
105 .if ((\_size & ((1 << STACK_ALIGN) - 1)) <> 0)
106 .error "Stack size not correctly aligned"
107 .endif
108 .section \_section, "aw", %nobits
109 .align STACK_ALIGN
110 \_name:
111 .space ((\_count) * (\_size)), 0
112 .endm
113
114 /*
115 * This macro calculates the base address of an MP stack using the
116 * platform_get_core_pos() index, the name of the stack storage and
117 * the size of each stack
118 * In: X0 = MPIDR of CPU whose stack is wanted
119 * Out: X0 = physical address of stack base
120 * Clobber: X30, X1, X2
121 */
122 .macro get_mp_stack _name, _size
123 bl platform_get_core_pos
124 ldr x2, =(\_name + \_size)
125 mov x1, #\_size
126 madd x0, x0, x1, x2
127 .endm
128
129 /*
130 * This macro calculates the base address of a UP stack using the
131 * name of the stack storage and the size of the stack
132 * Out: X0 = physical address of stack base
133 */
134 .macro get_up_stack _name, _size
135 ldr x0, =(\_name + \_size)
136 .endm