xref: /rk3399_ARM-atf/include/common/asm_macros_common.S (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
1/*
2 * Copyright (c) 2013-2016, 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.
15	 */
16	.macro func _name
17	/*
18	 * Add Call Frame Information entry in the .debug_frame section for
19	 * debugger consumption. This enables callstack printing in debuggers.
20	 * This does not use any space in the final loaded binary, only in the
21	 * ELF file.
22	 * Note that a function manipulating the CFA pointer location (i.e. the
23	 * x29 frame pointer on AArch64) should declare it using the
24	 * appropriate .cfi* directives, or be prepared to have a degraded
25	 * debugging experience.
26	 */
27	.cfi_sections .debug_frame
28	.section .text.\_name, "ax"
29	.type \_name, %function
30	.func \_name
31	/*
32	 * .cfi_startproc and .cfi_endproc are needed to output entries in
33	 * .debug_frame
34	 */
35	.cfi_startproc
36	\_name:
37	.endm
38
39	/*
40	 * This macro is used to mark the end of a function.
41	 */
42	.macro endfunc _name
43	.endfunc
44	.cfi_endproc
45	.size \_name, . - \_name
46	.endm
47
48	/*
49	 * Theses macros are used to create function labels for deprecated
50	 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
51	 * will fail to link and cause build failure.
52	 */
53#if ERROR_DEPRECATED
54	.macro func_deprecated _name
55	func deprecated\_name
56	.endm
57
58	.macro endfunc_deprecated _name
59	endfunc deprecated\_name
60	.endm
61#else
62	.macro func_deprecated _name
63	func \_name
64	.endm
65
66	.macro endfunc_deprecated _name
67	endfunc \_name
68	.endm
69#endif
70
71	/*
72	 * Helper assembler macro to count trailing zeros. The output is
73	 * populated in the `TZ_COUNT` symbol.
74	 */
75	.macro count_tz _value, _tz_count
76	.if \_value
77	  count_tz "(\_value >> 1)", "(\_tz_count + 1)"
78	.else
79	  .equ TZ_COUNT, (\_tz_count - 1)
80	.endif
81	.endm
82
83	/*
84	 * This macro declares an array of 1 or more stacks, properly
85	 * aligned and in the requested section
86	 */
87#define DEFAULT_STACK_ALIGN	(1 << 6)   /* In case the caller doesnt provide alignment */
88
89	.macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
90	count_tz \_align, 0
91	.if (\_align - (1 << TZ_COUNT))
92	  .error "Incorrect stack alignment specified (Must be a power of 2)."
93	.endif
94	.if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
95	  .error "Stack size not correctly aligned"
96	.endif
97	.section    \_section, "aw", %nobits
98	.align TZ_COUNT
99	\_name:
100	.space ((\_count) * (\_size)), 0
101	.endm
102
103
104#endif /* __ASM_MACROS_COMMON_S__ */
105