blob: b529246d8e53be25b9869aa8ab96d200d45066e2 [file] [log] [blame]
Soby Mathewb9ff2fd2016-07-08 15:26:35 +01001/*
2 * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathewb9ff2fd2016-07-08 15:26:35 +01005 */
6#ifndef __ASM_MACROS_COMMON_S__
7#define __ASM_MACROS_COMMON_S__
8
Soby Mathewb9ff2fd2016-07-08 15:26:35 +01009 /*
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
Douglas Raillard1c0e2082016-11-21 14:12:32 +000012 * 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.
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010015 */
16 .macro func _name
Douglas Raillard1c0e2082016-11-21 14:12:32 +000017 /*
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
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010028 .section .text.\_name, "ax"
29 .type \_name, %function
30 .func \_name
Douglas Raillard1c0e2082016-11-21 14:12:32 +000031 /*
32 * .cfi_startproc and .cfi_endproc are needed to output entries in
33 * .debug_frame
34 */
35 .cfi_startproc
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010036 \_name:
37 .endm
38
39 /*
40 * This macro is used to mark the end of a function.
41 */
42 .macro endfunc _name
43 .endfunc
Douglas Raillard1c0e2082016-11-21 14:12:32 +000044 .cfi_endproc
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010045 .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__ */