2 * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
6 #ifndef ASM_MACROS_COMMON_S
7 #define ASM_MACROS_COMMON_S
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). The default is
16 * _align=2 because both Aarch32 and Aarch64 instructions must be
17 * word aligned. Do *not* try to use a raw .align directive. Since func
18 * switches to a new section, this would not have the desired effect.
20 .macro func _name, _align=2
22 * Add Call Frame Information entry in the .debug_frame section for
23 * debugger consumption. This enables callstack printing in debuggers.
24 * This does not use any space in the final loaded binary, only in the
26 * Note that a function manipulating the CFA pointer location (i.e. the
27 * x29 frame pointer on AArch64) should declare it using the
28 * appropriate .cfi* directives, or be prepared to have a degraded
29 * debugging experience.
31 .cfi_sections .debug_frame
32 .section .text.asm.\_name, "ax"
33 .type \_name, %function
35 * .cfi_startproc and .cfi_endproc are needed to output entries in
42 /* When Branch Target Identification is enabled, insert "bti jc"
43 * instruction to enable indirect calls and branches
50 * This macro is used to mark the end of a function.
54 .size \_name, . - \_name
58 * Theses macros are used to create function labels for deprecated
59 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
60 * will fail to link and cause build failure.
63 .macro func_deprecated _name
67 .macro endfunc_deprecated _name
68 endfunc deprecated\_name
71 .macro func_deprecated _name
75 .macro endfunc_deprecated _name
81 * Helper assembler macro to count trailing zeros. The output is
82 * populated in the `TZ_COUNT` symbol.
84 .macro count_tz _value, _tz_count
86 count_tz "(\_value >> 1)", "(\_tz_count + 1)"
88 .equ TZ_COUNT, (\_tz_count - 1)
93 * This macro declares an array of 1 or more stacks, properly
94 * aligned and in the requested section
96 #define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */
98 .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
100 .if (\_align - (1 << TZ_COUNT))
101 .error "Incorrect stack alignment specified (Must be a power of 2)."
103 .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
104 .error "Stack size not correctly aligned"
106 .section \_section, "aw", %nobits
109 .space ((\_count) * (\_size)), 0
113 #endif /* ASM_MACROS_COMMON_S */