blob: 5b050455ceb993d555b30980655c4be58325b161 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Jeenu Viswambharan9a7ce2f2018-04-04 16:07:11 +01002 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
Dan Handleyea596682015-04-01 17:34:24 +01006#ifndef __ASM_MACROS_S__
7#define __ASM_MACROS_S__
Achin Gupta4f6ad662013-10-25 09:08:21 +01008
Dan Handley2bd4ef22014-04-09 13:14:54 +01009#include <arch.h>
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010010#include <asm_macros_common.S>
Jeenu Viswambharan54ec86a2017-01-19 14:23:36 +000011#include <spinlock.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010012
Jeenu Viswambharan58e81482018-04-27 15:06:57 +010013/*
14 * TLBI instruction with type specifier that implements the workaround for
15 * errata 813419 of Cortex-A57.
16 */
17#if ERRATA_A57_813419
18#define TLB_INVALIDATE(_type) \
19 tlbi _type; \
20 dsb ish; \
21 tlbi _type
22#else
23#define TLB_INVALIDATE(_type) \
24 tlbi _type
25#endif
26
Dan Handley2bd4ef22014-04-09 13:14:54 +010027
Achin Gupta4f6ad662013-10-25 09:08:21 +010028 .macro func_prologue
29 stp x29, x30, [sp, #-0x10]!
30 mov x29,sp
31 .endm
32
33 .macro func_epilogue
34 ldp x29, x30, [sp], #0x10
35 .endm
36
37
38 .macro dcache_line_size reg, tmp
Achin Gupta07f4e072014-02-02 12:02:23 +000039 mrs \tmp, ctr_el0
Achin Gupta4f6ad662013-10-25 09:08:21 +010040 ubfx \tmp, \tmp, #16, #4
Achin Gupta07f4e072014-02-02 12:02:23 +000041 mov \reg, #4
42 lsl \reg, \reg, \tmp
Achin Gupta4f6ad662013-10-25 09:08:21 +010043 .endm
44
45
46 .macro icache_line_size reg, tmp
Achin Gupta07f4e072014-02-02 12:02:23 +000047 mrs \tmp, ctr_el0
48 and \tmp, \tmp, #0xf
49 mov \reg, #4
50 lsl \reg, \reg, \tmp
Achin Gupta4f6ad662013-10-25 09:08:21 +010051 .endm
52
53
Achin Gupta4f6ad662013-10-25 09:08:21 +010054 .macro smc_check label
Andrew Thoelkef977ed82014-04-28 12:32:02 +010055 mrs x0, esr_el3
Achin Gupta4f6ad662013-10-25 09:08:21 +010056 ubfx x0, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
57 cmp x0, #EC_AARCH64_SMC
58 b.ne $label
59 .endm
60
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010061 /*
62 * Declare the exception vector table, enforcing it is aligned on a
63 * 2KB boundary, as required by the ARMv8 architecture.
Sandrine Bailleux618ba992016-05-24 16:22:59 +010064 * Use zero bytes as the fill value to be stored in the padding bytes
65 * so that it inserts illegal AArch64 instructions. This increases
66 * security, robustness and potentially facilitates debugging.
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010067 */
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010068 .macro vector_base label, section_name=.vectors
69 .section \section_name, "ax"
Sandrine Bailleux618ba992016-05-24 16:22:59 +010070 .align 11, 0
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010071 \label:
72 .endm
73
74 /*
75 * Create an entry in the exception vector table, enforcing it is
76 * aligned on a 128-byte boundary, as required by the ARMv8 architecture.
Sandrine Bailleux618ba992016-05-24 16:22:59 +010077 * Use zero bytes as the fill value to be stored in the padding bytes
78 * so that it inserts illegal AArch64 instructions. This increases
79 * security, robustness and potentially facilitates debugging.
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010080 */
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010081 .macro vector_entry label, section_name=.vectors
Douglas Raillardefa50b52017-08-07 16:20:46 +010082 .cfi_sections .debug_frame
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010083 .section \section_name, "ax"
Sandrine Bailleux618ba992016-05-24 16:22:59 +010084 .align 7, 0
Douglas Raillardefa50b52017-08-07 16:20:46 +010085 .type \label, %function
86 .func \label
87 .cfi_startproc
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010088 \label:
89 .endm
Achin Gupta4f6ad662013-10-25 09:08:21 +010090
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000091 /*
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010092 * This macro verifies that the given vector doesn't exceed the
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000093 * architectural limit of 32 instructions. This is meant to be placed
Sandrine Bailleux9e6ad6c2016-05-24 16:56:03 +010094 * immediately after the last instruction in the vector. It takes the
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000095 * vector entry as the parameter
96 */
97 .macro check_vector_size since
Douglas Raillardefa50b52017-08-07 16:20:46 +010098 .endfunc
99 .cfi_endproc
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000100 .if (. - \since) > (32 * 4)
101 .error "Vector exceeds 32 instructions"
102 .endif
103 .endm
Andrew Thoelke38bde412014-03-18 13:46:55 +0000104
Soby Mathew981487a2015-07-13 14:10:57 +0100105#if ENABLE_PLAT_COMPAT
Andrew Thoelke65668f92014-03-20 10:48:23 +0000106 /*
107 * This macro calculates the base address of an MP stack using the
108 * platform_get_core_pos() index, the name of the stack storage and
109 * the size of each stack
110 * In: X0 = MPIDR of CPU whose stack is wanted
111 * Out: X0 = physical address of stack base
112 * Clobber: X30, X1, X2
113 */
114 .macro get_mp_stack _name, _size
115 bl platform_get_core_pos
116 ldr x2, =(\_name + \_size)
117 mov x1, #\_size
118 madd x0, x0, x1, x2
119 .endm
Soby Mathew981487a2015-07-13 14:10:57 +0100120#endif
Andrew Thoelke65668f92014-03-20 10:48:23 +0000121
122 /*
Soby Mathewb0082d22015-04-09 13:40:55 +0100123 * This macro calculates the base address of the current CPU's MP stack
124 * using the plat_my_core_pos() index, the name of the stack storage
125 * and the size of each stack
126 * Out: X0 = physical address of stack base
127 * Clobber: X30, X1, X2
128 */
129 .macro get_my_mp_stack _name, _size
130 bl plat_my_core_pos
131 ldr x2, =(\_name + \_size)
132 mov x1, #\_size
133 madd x0, x0, x1, x2
134 .endm
135
136 /*
Andrew Thoelke65668f92014-03-20 10:48:23 +0000137 * This macro calculates the base address of a UP stack using the
138 * name of the stack storage and the size of the stack
139 * Out: X0 = physical address of stack base
140 */
141 .macro get_up_stack _name, _size
142 ldr x0, =(\_name + \_size)
143 .endm
Soby Mathew066f7132014-07-14 16:57:23 +0100144
145 /*
146 * Helper macro to generate the best mov/movk combinations according
147 * the value to be moved. The 16 bits from '_shift' are tested and
148 * if not zero, they are moved into '_reg' without affecting
149 * other bits.
150 */
151 .macro _mov_imm16 _reg, _val, _shift
152 .if (\_val >> \_shift) & 0xffff
153 .if (\_val & (1 << \_shift - 1))
154 movk \_reg, (\_val >> \_shift) & 0xffff, LSL \_shift
155 .else
156 mov \_reg, \_val & (0xffff << \_shift)
157 .endif
158 .endif
159 .endm
160
161 /*
162 * Helper macro to load arbitrary values into 32 or 64-bit registers
163 * which generates the best mov/movk combinations. Many base addresses
164 * are 64KB aligned the macro will eliminate updating bits 15:0 in
165 * that case
166 */
167 .macro mov_imm _reg, _val
168 .if (\_val) == 0
169 mov \_reg, #0
170 .else
171 _mov_imm16 \_reg, (\_val), 0
172 _mov_imm16 \_reg, (\_val), 16
173 _mov_imm16 \_reg, (\_val), 32
174 _mov_imm16 \_reg, (\_val), 48
175 .endif
176 .endm
Dan Handleyea596682015-04-01 17:34:24 +0100177
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000178 /*
179 * Macro to mark instances where we're jumping to a function and don't
180 * expect a return. To provide the function being jumped to with
181 * additional information, we use 'bl' instruction to jump rather than
182 * 'b'.
183 *
184 * Debuggers infer the location of a call from where LR points to, which
185 * is usually the instruction after 'bl'. If this macro expansion
186 * happens to be the last location in a function, that'll cause the LR
187 * to point a location beyond the function, thereby misleading debugger
188 * back trace. We therefore insert a 'nop' after the function call for
189 * debug builds, unless 'skip_nop' parameter is non-zero.
190 */
191 .macro no_ret _func:req, skip_nop=0
192 bl \_func
193#if DEBUG
194 .ifeq \skip_nop
195 nop
196 .endif
197#endif
198 .endm
199
Jeenu Viswambharan54ec86a2017-01-19 14:23:36 +0000200 /*
201 * Reserve space for a spin lock in assembly file.
202 */
203 .macro define_asm_spinlock _name:req
204 .align SPINLOCK_ASM_ALIGN
205 \_name:
206 .space SPINLOCK_ASM_SIZE
207 .endm
208
Jeenu Viswambharan9a7ce2f2018-04-04 16:07:11 +0100209#if RAS_EXTENSION
210 .macro esb
211 .inst 0xd503221f
212 .endm
213#endif
214
Dan Handleyea596682015-04-01 17:34:24 +0100215#endif /* __ASM_MACROS_S__ */