xref: /rk3399_ARM-atf/include/common/asm_macros_common.S (revision 51faada71a219a8b94cd8d8e423f0f22e9da4d8f)
1/*
2 * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
3 *
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#ifndef __ASM_MACROS_COMMON_S__
31#define __ASM_MACROS_COMMON_S__
32
33	/*
34	 * This macro is used to create a function label and place the
35	 * code into a separate text section based on the function name
36	 * to enable elimination of unused code during linking. It also adds
37	 * basic debug information to enable call stack printing most of the
38	 * time.
39	 */
40	.macro func _name
41	/*
42	 * Add Call Frame Information entry in the .debug_frame section for
43	 * debugger consumption. This enables callstack printing in debuggers.
44	 * This does not use any space in the final loaded binary, only in the
45	 * ELF file.
46	 * Note that a function manipulating the CFA pointer location (i.e. the
47	 * x29 frame pointer on AArch64) should declare it using the
48	 * appropriate .cfi* directives, or be prepared to have a degraded
49	 * debugging experience.
50	 */
51	.cfi_sections .debug_frame
52	.section .text.\_name, "ax"
53	.type \_name, %function
54	.func \_name
55	/*
56	 * .cfi_startproc and .cfi_endproc are needed to output entries in
57	 * .debug_frame
58	 */
59	.cfi_startproc
60	\_name:
61	.endm
62
63	/*
64	 * This macro is used to mark the end of a function.
65	 */
66	.macro endfunc _name
67	.endfunc
68	.cfi_endproc
69	.size \_name, . - \_name
70	.endm
71
72	/*
73	 * Theses macros are used to create function labels for deprecated
74	 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
75	 * will fail to link and cause build failure.
76	 */
77#if ERROR_DEPRECATED
78	.macro func_deprecated _name
79	func deprecated\_name
80	.endm
81
82	.macro endfunc_deprecated _name
83	endfunc deprecated\_name
84	.endm
85#else
86	.macro func_deprecated _name
87	func \_name
88	.endm
89
90	.macro endfunc_deprecated _name
91	endfunc \_name
92	.endm
93#endif
94
95	/*
96	 * Helper assembler macro to count trailing zeros. The output is
97	 * populated in the `TZ_COUNT` symbol.
98	 */
99	.macro count_tz _value, _tz_count
100	.if \_value
101	  count_tz "(\_value >> 1)", "(\_tz_count + 1)"
102	.else
103	  .equ TZ_COUNT, (\_tz_count - 1)
104	.endif
105	.endm
106
107	/*
108	 * This macro declares an array of 1 or more stacks, properly
109	 * aligned and in the requested section
110	 */
111#define DEFAULT_STACK_ALIGN	(1 << 6)   /* In case the caller doesnt provide alignment */
112
113	.macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
114	count_tz \_align, 0
115	.if (\_align - (1 << TZ_COUNT))
116	  .error "Incorrect stack alignment specified (Must be a power of 2)."
117	.endif
118	.if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
119	  .error "Stack size not correctly aligned"
120	.endif
121	.section    \_section, "aw", %nobits
122	.align TZ_COUNT
123	\_name:
124	.space ((\_count) * (\_size)), 0
125	.endm
126
127
128#endif /* __ASM_MACROS_COMMON_S__ */
129