xref: /rk3399_ARM-atf/include/common/asm_macros_common.S (revision 64726e6d61e94203a1dc6aa3f49affd8f2165aec)
1/*
2 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#ifndef __ASM_MACROS_COMMON_S__
7#define __ASM_MACROS_COMMON_S__
8
9	/*
10	 * This macro is used to create a function label and place the
11	 * code into a separate text section based on the function name
12	 * to enable elimination of unused code during linking. It also adds
13	 * basic debug information to enable call stack printing most of the
14	 * time. The optional _align parameter can be used to force a
15	 * non-standard alignment (indicated in powers of 2). Do *not* try to
16	 * use a raw .align directive. Since func switches to a new section,
17	 * this would not have the desired effect.
18	 */
19	.macro func _name, _align=-1
20	/*
21	 * Add Call Frame Information entry in the .debug_frame section for
22	 * debugger consumption. This enables callstack printing in debuggers.
23	 * This does not use any space in the final loaded binary, only in the
24	 * ELF file.
25	 * Note that a function manipulating the CFA pointer location (i.e. the
26	 * x29 frame pointer on AArch64) should declare it using the
27	 * appropriate .cfi* directives, or be prepared to have a degraded
28	 * debugging experience.
29	 */
30	.cfi_sections .debug_frame
31	.section .text.\_name, "ax"
32	.type \_name, %function
33	.func \_name
34	/*
35	 * .cfi_startproc and .cfi_endproc are needed to output entries in
36	 * .debug_frame
37	 */
38	.cfi_startproc
39	.if (\_align) != -1
40		.align \_align
41	.endif
42	\_name:
43	.endm
44
45	/*
46	 * This macro is used to mark the end of a function.
47	 */
48	.macro endfunc _name
49	.endfunc
50	.cfi_endproc
51	.size \_name, . - \_name
52	.endm
53
54	/*
55	 * Theses macros are used to create function labels for deprecated
56	 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
57	 * will fail to link and cause build failure.
58	 */
59#if ERROR_DEPRECATED
60	.macro func_deprecated _name
61	func deprecated\_name
62	.endm
63
64	.macro endfunc_deprecated _name
65	endfunc deprecated\_name
66	.endm
67#else
68	.macro func_deprecated _name
69	func \_name
70	.endm
71
72	.macro endfunc_deprecated _name
73	endfunc \_name
74	.endm
75#endif
76
77	/*
78	 * Helper assembler macro to count trailing zeros. The output is
79	 * populated in the `TZ_COUNT` symbol.
80	 */
81	.macro count_tz _value, _tz_count
82	.if \_value
83	  count_tz "(\_value >> 1)", "(\_tz_count + 1)"
84	.else
85	  .equ TZ_COUNT, (\_tz_count - 1)
86	.endif
87	.endm
88
89	/*
90	 * This macro declares an array of 1 or more stacks, properly
91	 * aligned and in the requested section
92	 */
93#define DEFAULT_STACK_ALIGN	(1 << 6)   /* In case the caller doesnt provide alignment */
94
95	.macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
96	count_tz \_align, 0
97	.if (\_align - (1 << TZ_COUNT))
98	  .error "Incorrect stack alignment specified (Must be a power of 2)."
99	.endif
100	.if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
101	  .error "Stack size not correctly aligned"
102	.endif
103	.section    \_section, "aw", %nobits
104	.align TZ_COUNT
105	\_name:
106	.space ((\_count) * (\_size)), 0
107	.endm
108
109
110#endif /* __ASM_MACROS_COMMON_S__ */
111