blob: 10ed301de7be89c885b595a622e6e33481fb723a [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Jeenu Viswambharan14c60162018-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-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
Dan Handleye2bf57f2015-04-01 17:34:24 +01006#ifndef __ASM_MACROS_S__
7#define __ASM_MACROS_S__
Achin Gupta4f6ad662013-10-25 09:08:21 +01008
Dan Handley97043ac2014-04-09 13:14:54 +01009#include <arch.h>
Soby Mathew738b1fd2016-07-08 15:26:35 +010010#include <asm_macros_common.S>
Jeenu Viswambharanb38bc682017-01-19 14:23:36 +000011#include <spinlock.h>
Dan Handley97043ac2014-04-09 13:14:54 +010012
Jeenu Viswambharan0cc7aa82018-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 Handley97043ac2014-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 Thoelke7935d0a2014-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 Bailleuxe0ae9fa2016-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 Bailleux79627dc2016-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 Bailleuxe0ae9fa2016-05-24 16:56:03 +010067 */
Antonio Nino Diaz2fccb222017-10-24 10:07:35 +010068 .macro vector_base label, section_name=.vectors
69 .section \section_name, "ax"
Sandrine Bailleux79627dc2016-05-24 16:22:59 +010070 .align 11, 0
Sandrine Bailleuxe0ae9fa2016-05-24 16:56:03 +010071 \label:
72 .endm
Achin Gupta4f6ad662013-10-25 09:08:21 +010073
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000074 /*
Sandrine Bailleuxe0ae9fa2016-05-24 16:56:03 +010075 * 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 Bailleux79627dc2016-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 Bailleuxe0ae9fa2016-05-24 16:56:03 +010080 */
Antonio Nino Diaz2fccb222017-10-24 10:07:35 +010081 .macro vector_entry label, section_name=.vectors
Douglas Raillard31823b62017-08-07 16:20:46 +010082 .cfi_sections .debug_frame
Antonio Nino Diaz2fccb222017-10-24 10:07:35 +010083 .section \section_name, "ax"
Sandrine Bailleux79627dc2016-05-24 16:22:59 +010084 .align 7, 0
Douglas Raillard31823b62017-08-07 16:20:46 +010085 .type \label, %function
Douglas Raillard31823b62017-08-07 16:20:46 +010086 .cfi_startproc
Sandrine Bailleuxe0ae9fa2016-05-24 16:56:03 +010087 \label:
88 .endm
89
90 /*
91 * This macro verifies that the given vector doesn't exceed the
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000092 * architectural limit of 32 instructions. This is meant to be placed
Sandrine Bailleuxe0ae9fa2016-05-24 16:56:03 +010093 * immediately after the last instruction in the vector. It takes the
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000094 * vector entry as the parameter
95 */
96 .macro check_vector_size since
Douglas Raillard31823b62017-08-07 16:20:46 +010097 .cfi_endproc
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000098 .if (. - \since) > (32 * 4)
99 .error "Vector exceeds 32 instructions"
100 .endif
101 .endm
Andrew Thoelke0a30cf52014-03-18 13:46:55 +0000102
Soby Mathew67487842015-07-13 14:10:57 +0100103#if ENABLE_PLAT_COMPAT
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000104 /*
105 * This macro calculates the base address of an MP stack using the
106 * platform_get_core_pos() index, the name of the stack storage and
107 * the size of each stack
108 * In: X0 = MPIDR of CPU whose stack is wanted
109 * Out: X0 = physical address of stack base
110 * Clobber: X30, X1, X2
111 */
112 .macro get_mp_stack _name, _size
113 bl platform_get_core_pos
114 ldr x2, =(\_name + \_size)
115 mov x1, #\_size
116 madd x0, x0, x1, x2
117 .endm
Soby Mathew67487842015-07-13 14:10:57 +0100118#endif
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000119
120 /*
Soby Mathew12d0d002015-04-09 13:40:55 +0100121 * This macro calculates the base address of the current CPU's MP stack
122 * using the plat_my_core_pos() index, the name of the stack storage
123 * and the size of each stack
124 * Out: X0 = physical address of stack base
125 * Clobber: X30, X1, X2
126 */
127 .macro get_my_mp_stack _name, _size
128 bl plat_my_core_pos
129 ldr x2, =(\_name + \_size)
130 mov x1, #\_size
131 madd x0, x0, x1, x2
132 .endm
133
134 /*
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000135 * This macro calculates the base address of a UP stack using the
136 * name of the stack storage and the size of the stack
137 * Out: X0 = physical address of stack base
138 */
139 .macro get_up_stack _name, _size
140 ldr x0, =(\_name + \_size)
141 .endm
Soby Mathewc67b09b2014-07-14 16:57:23 +0100142
143 /*
144 * Helper macro to generate the best mov/movk combinations according
145 * the value to be moved. The 16 bits from '_shift' are tested and
146 * if not zero, they are moved into '_reg' without affecting
147 * other bits.
148 */
149 .macro _mov_imm16 _reg, _val, _shift
150 .if (\_val >> \_shift) & 0xffff
151 .if (\_val & (1 << \_shift - 1))
152 movk \_reg, (\_val >> \_shift) & 0xffff, LSL \_shift
153 .else
154 mov \_reg, \_val & (0xffff << \_shift)
155 .endif
156 .endif
157 .endm
158
159 /*
160 * Helper macro to load arbitrary values into 32 or 64-bit registers
161 * which generates the best mov/movk combinations. Many base addresses
162 * are 64KB aligned the macro will eliminate updating bits 15:0 in
163 * that case
164 */
165 .macro mov_imm _reg, _val
166 .if (\_val) == 0
167 mov \_reg, #0
168 .else
169 _mov_imm16 \_reg, (\_val), 0
170 _mov_imm16 \_reg, (\_val), 16
171 _mov_imm16 \_reg, (\_val), 32
172 _mov_imm16 \_reg, (\_val), 48
173 .endif
174 .endm
Dan Handleye2bf57f2015-04-01 17:34:24 +0100175
Jeenu Viswambharana806dad2016-11-30 15:21:11 +0000176 /*
177 * Macro to mark instances where we're jumping to a function and don't
178 * expect a return. To provide the function being jumped to with
179 * additional information, we use 'bl' instruction to jump rather than
180 * 'b'.
181 *
182 * Debuggers infer the location of a call from where LR points to, which
183 * is usually the instruction after 'bl'. If this macro expansion
184 * happens to be the last location in a function, that'll cause the LR
185 * to point a location beyond the function, thereby misleading debugger
186 * back trace. We therefore insert a 'nop' after the function call for
187 * debug builds, unless 'skip_nop' parameter is non-zero.
188 */
189 .macro no_ret _func:req, skip_nop=0
190 bl \_func
191#if DEBUG
192 .ifeq \skip_nop
193 nop
194 .endif
195#endif
196 .endm
197
Jeenu Viswambharanb38bc682017-01-19 14:23:36 +0000198 /*
199 * Reserve space for a spin lock in assembly file.
200 */
201 .macro define_asm_spinlock _name:req
202 .align SPINLOCK_ASM_ALIGN
203 \_name:
204 .space SPINLOCK_ASM_SIZE
205 .endm
206
Jeenu Viswambharan14c60162018-04-04 16:07:11 +0100207#if RAS_EXTENSION
208 .macro esb
209 .inst 0xd503221f
210 .endm
211#endif
212
Dan Handleye2bf57f2015-04-01 17:34:24 +0100213#endif /* __ASM_MACROS_S__ */