xref: /rk3399_ARM-atf/include/common/asm_macros_common.S (revision 738b1fd7c0628e9c6cc89e36629f27bde01559df)
1*738b1fd7SSoby Mathew/*
2*738b1fd7SSoby Mathew * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
3*738b1fd7SSoby Mathew *
4*738b1fd7SSoby Mathew * Redistribution and use in source and binary forms, with or without
5*738b1fd7SSoby Mathew * modification, are permitted provided that the following conditions are met:
6*738b1fd7SSoby Mathew *
7*738b1fd7SSoby Mathew * Redistributions of source code must retain the above copyright notice, this
8*738b1fd7SSoby Mathew * list of conditions and the following disclaimer.
9*738b1fd7SSoby Mathew *
10*738b1fd7SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice,
11*738b1fd7SSoby Mathew * this list of conditions and the following disclaimer in the documentation
12*738b1fd7SSoby Mathew * and/or other materials provided with the distribution.
13*738b1fd7SSoby Mathew *
14*738b1fd7SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used
15*738b1fd7SSoby Mathew * to endorse or promote products derived from this software without specific
16*738b1fd7SSoby Mathew * prior written permission.
17*738b1fd7SSoby Mathew *
18*738b1fd7SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*738b1fd7SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*738b1fd7SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*738b1fd7SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*738b1fd7SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*738b1fd7SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*738b1fd7SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*738b1fd7SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*738b1fd7SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*738b1fd7SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*738b1fd7SSoby Mathew * POSSIBILITY OF SUCH DAMAGE.
29*738b1fd7SSoby Mathew */
30*738b1fd7SSoby Mathew#ifndef __ASM_MACROS_COMMON_S__
31*738b1fd7SSoby Mathew#define __ASM_MACROS_COMMON_S__
32*738b1fd7SSoby Mathew
33*738b1fd7SSoby Mathew#include <arch.h>
34*738b1fd7SSoby Mathew
35*738b1fd7SSoby Mathew	/*
36*738b1fd7SSoby Mathew	 * This macro is used to create a function label and place the
37*738b1fd7SSoby Mathew	 * code into a separate text section based on the function name
38*738b1fd7SSoby Mathew	 * to enable elimination of unused code during linking
39*738b1fd7SSoby Mathew	 */
40*738b1fd7SSoby Mathew	.macro func _name
41*738b1fd7SSoby Mathew	.section .text.\_name, "ax"
42*738b1fd7SSoby Mathew	.type \_name, %function
43*738b1fd7SSoby Mathew	.func \_name
44*738b1fd7SSoby Mathew	\_name:
45*738b1fd7SSoby Mathew	.endm
46*738b1fd7SSoby Mathew
47*738b1fd7SSoby Mathew	/*
48*738b1fd7SSoby Mathew	 * This macro is used to mark the end of a function.
49*738b1fd7SSoby Mathew	 */
50*738b1fd7SSoby Mathew	.macro endfunc _name
51*738b1fd7SSoby Mathew	.endfunc
52*738b1fd7SSoby Mathew	.size \_name, . - \_name
53*738b1fd7SSoby Mathew	.endm
54*738b1fd7SSoby Mathew
55*738b1fd7SSoby Mathew	/*
56*738b1fd7SSoby Mathew	 * Theses macros are used to create function labels for deprecated
57*738b1fd7SSoby Mathew	 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
58*738b1fd7SSoby Mathew	 * will fail to link and cause build failure.
59*738b1fd7SSoby Mathew	 */
60*738b1fd7SSoby Mathew#if ERROR_DEPRECATED
61*738b1fd7SSoby Mathew	.macro func_deprecated _name
62*738b1fd7SSoby Mathew	func deprecated\_name
63*738b1fd7SSoby Mathew	.endm
64*738b1fd7SSoby Mathew
65*738b1fd7SSoby Mathew	.macro endfunc_deprecated _name
66*738b1fd7SSoby Mathew	endfunc deprecated\_name
67*738b1fd7SSoby Mathew	.endm
68*738b1fd7SSoby Mathew#else
69*738b1fd7SSoby Mathew	.macro func_deprecated _name
70*738b1fd7SSoby Mathew	func \_name
71*738b1fd7SSoby Mathew	.endm
72*738b1fd7SSoby Mathew
73*738b1fd7SSoby Mathew	.macro endfunc_deprecated _name
74*738b1fd7SSoby Mathew	endfunc \_name
75*738b1fd7SSoby Mathew	.endm
76*738b1fd7SSoby Mathew#endif
77*738b1fd7SSoby Mathew
78*738b1fd7SSoby Mathew	/*
79*738b1fd7SSoby Mathew	 * Helper assembler macro to count trailing zeros. The output is
80*738b1fd7SSoby Mathew	 * populated in the `TZ_COUNT` symbol.
81*738b1fd7SSoby Mathew	 */
82*738b1fd7SSoby Mathew	.macro count_tz _value, _tz_count
83*738b1fd7SSoby Mathew	.if \_value
84*738b1fd7SSoby Mathew	  count_tz "(\_value >> 1)", "(\_tz_count + 1)"
85*738b1fd7SSoby Mathew	.else
86*738b1fd7SSoby Mathew	  .equ TZ_COUNT, (\_tz_count - 1)
87*738b1fd7SSoby Mathew	.endif
88*738b1fd7SSoby Mathew	.endm
89*738b1fd7SSoby Mathew
90*738b1fd7SSoby Mathew	/*
91*738b1fd7SSoby Mathew	 * This macro declares an array of 1 or more stacks, properly
92*738b1fd7SSoby Mathew	 * aligned and in the requested section
93*738b1fd7SSoby Mathew	 */
94*738b1fd7SSoby Mathew#define DEFAULT_STACK_ALIGN	(1 << 6)   /* In case the caller doesnt provide alignment */
95*738b1fd7SSoby Mathew
96*738b1fd7SSoby Mathew	.macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
97*738b1fd7SSoby Mathew	count_tz \_align, 0
98*738b1fd7SSoby Mathew	.if (\_align - (1 << TZ_COUNT))
99*738b1fd7SSoby Mathew	  .error "Incorrect stack alignment specified (Must be a power of 2)."
100*738b1fd7SSoby Mathew	.endif
101*738b1fd7SSoby Mathew	.if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
102*738b1fd7SSoby Mathew	  .error "Stack size not correctly aligned"
103*738b1fd7SSoby Mathew	.endif
104*738b1fd7SSoby Mathew	.section    \_section, "aw", %nobits
105*738b1fd7SSoby Mathew	.align TZ_COUNT
106*738b1fd7SSoby Mathew	\_name:
107*738b1fd7SSoby Mathew	.space ((\_count) * (\_size)), 0
108*738b1fd7SSoby Mathew	.endm
109*738b1fd7SSoby Mathew
110*738b1fd7SSoby Mathew
111*738b1fd7SSoby Mathew#endif /* __ASM_MACROS_COMMON_S__ */
112