blob: f9e7823c623ac13ed3717e3d070ad22045ca5f30 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleyea596682015-04-01 17:34:24 +01002 * Copyright (c) 2013-2015, 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 */
Dan Handleyea596682015-04-01 17:34:24 +010030#ifndef __ASM_MACROS_S__
31#define __ASM_MACROS_S__
Achin Gupta4f6ad662013-10-25 09:08:21 +010032
Dan Handley2bd4ef22014-04-09 13:14:54 +010033#include <arch.h>
34
35
Achin Gupta4f6ad662013-10-25 09:08:21 +010036 .macro func_prologue
37 stp x29, x30, [sp, #-0x10]!
38 mov x29,sp
39 .endm
40
41 .macro func_epilogue
42 ldp x29, x30, [sp], #0x10
43 .endm
44
45
46 .macro dcache_line_size reg, tmp
Achin Gupta07f4e072014-02-02 12:02:23 +000047 mrs \tmp, ctr_el0
Achin Gupta4f6ad662013-10-25 09:08:21 +010048 ubfx \tmp, \tmp, #16, #4
Achin Gupta07f4e072014-02-02 12:02:23 +000049 mov \reg, #4
50 lsl \reg, \reg, \tmp
Achin Gupta4f6ad662013-10-25 09:08:21 +010051 .endm
52
53
54 .macro icache_line_size reg, tmp
Achin Gupta07f4e072014-02-02 12:02:23 +000055 mrs \tmp, ctr_el0
56 and \tmp, \tmp, #0xf
57 mov \reg, #4
58 lsl \reg, \reg, \tmp
Achin Gupta4f6ad662013-10-25 09:08:21 +010059 .endm
60
61
Achin Gupta4f6ad662013-10-25 09:08:21 +010062 .macro smc_check label
Andrew Thoelkef977ed82014-04-28 12:32:02 +010063 mrs x0, esr_el3
Achin Gupta4f6ad662013-10-25 09:08:21 +010064 ubfx x0, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
65 cmp x0, #EC_AARCH64_SMC
66 b.ne $label
67 .endm
68
69
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000070 /*
71 * This macro verifies that the a given vector doesn't exceed the
72 * architectural limit of 32 instructions. This is meant to be placed
73 * immedately after the last instruction in the vector. It takes the
74 * vector entry as the parameter
75 */
76 .macro check_vector_size since
77 .if (. - \since) > (32 * 4)
78 .error "Vector exceeds 32 instructions"
79 .endif
80 .endm
Andrew Thoelke38bde412014-03-18 13:46:55 +000081
82 /*
83 * This macro is used to create a function label and place the
84 * code into a separate text section based on the function name
85 * to enable elimination of unused code during linking
86 */
87 .macro func _name
88 .section .text.\_name, "ax"
89 .type \_name, %function
Kévin Petita877c252015-03-24 14:03:57 +000090 .func \_name
Andrew Thoelke38bde412014-03-18 13:46:55 +000091 \_name:
92 .endm
Andrew Thoelke65668f92014-03-20 10:48:23 +000093
Kévin Petita877c252015-03-24 14:03:57 +000094 /*
95 * This macro is used to mark the end of a function.
96 */
97 .macro endfunc _name
98 .endfunc
99 .size \_name, . - \_name
100 .endm
101
Vikram Kanigiri96377452014-04-24 11:02:16 +0100102 /* ---------------------------------------------
103 * Find the type of reset and jump to handler
104 * if present. If the handler is null then it is
105 * a cold boot. The primary cpu will set up the
106 * platform while the secondaries wait for
107 * their turn to be woken up
108 * ---------------------------------------------
109 */
110 .macro wait_for_entrypoint
111wait_for_entrypoint:
112 mrs x0, mpidr_el1
113 bl platform_get_entrypoint
114 cbnz x0, do_warm_boot
115 mrs x0, mpidr_el1
116 bl platform_is_primary_cpu
117 cbnz x0, do_cold_boot
118
119 /* ---------------------------------------------
120 * Perform any platform specific secondary cpu
121 * actions
122 * ---------------------------------------------
123 */
124 bl plat_secondary_cold_boot_setup
125 b wait_for_entrypoint
126
127 do_warm_boot:
128 /* ---------------------------------------------
129 * Jump to BL31 for all warm boot init.
130 * ---------------------------------------------
131 */
132 blr x0
133
134 do_cold_boot:
135 .endm
136
Andrew Thoelke65668f92014-03-20 10:48:23 +0000137 /*
138 * This macro declares an array of 1 or more stacks, properly
139 * aligned and in the requested section
140 */
141#define STACK_ALIGN 6
142
143 .macro declare_stack _name, _section, _size, _count
144 .if ((\_size & ((1 << STACK_ALIGN) - 1)) <> 0)
145 .error "Stack size not correctly aligned"
146 .endif
147 .section \_section, "aw", %nobits
148 .align STACK_ALIGN
149 \_name:
150 .space ((\_count) * (\_size)), 0
151 .endm
152
153 /*
154 * This macro calculates the base address of an MP stack using the
155 * platform_get_core_pos() index, the name of the stack storage and
156 * the size of each stack
157 * In: X0 = MPIDR of CPU whose stack is wanted
158 * Out: X0 = physical address of stack base
159 * Clobber: X30, X1, X2
160 */
161 .macro get_mp_stack _name, _size
162 bl platform_get_core_pos
163 ldr x2, =(\_name + \_size)
164 mov x1, #\_size
165 madd x0, x0, x1, x2
166 .endm
167
168 /*
169 * This macro calculates the base address of a UP stack using the
170 * name of the stack storage and the size of the stack
171 * Out: X0 = physical address of stack base
172 */
173 .macro get_up_stack _name, _size
174 ldr x0, =(\_name + \_size)
175 .endm
Soby Mathew066f7132014-07-14 16:57:23 +0100176
177 /*
178 * Helper macro to generate the best mov/movk combinations according
179 * the value to be moved. The 16 bits from '_shift' are tested and
180 * if not zero, they are moved into '_reg' without affecting
181 * other bits.
182 */
183 .macro _mov_imm16 _reg, _val, _shift
184 .if (\_val >> \_shift) & 0xffff
185 .if (\_val & (1 << \_shift - 1))
186 movk \_reg, (\_val >> \_shift) & 0xffff, LSL \_shift
187 .else
188 mov \_reg, \_val & (0xffff << \_shift)
189 .endif
190 .endif
191 .endm
192
193 /*
194 * Helper macro to load arbitrary values into 32 or 64-bit registers
195 * which generates the best mov/movk combinations. Many base addresses
196 * are 64KB aligned the macro will eliminate updating bits 15:0 in
197 * that case
198 */
199 .macro mov_imm _reg, _val
200 .if (\_val) == 0
201 mov \_reg, #0
202 .else
203 _mov_imm16 \_reg, (\_val), 0
204 _mov_imm16 \_reg, (\_val), 16
205 _mov_imm16 \_reg, (\_val), 32
206 _mov_imm16 \_reg, (\_val), 48
207 .endif
208 .endm
Dan Handleyea596682015-04-01 17:34:24 +0100209
210#endif /* __ASM_MACROS_S__ */