blob: 081addcc51eeea89214b1c0b6ab6e4ea0559f5c6 [file] [log] [blame]
Soby Mathewb9ff2fd2016-07-08 15:26:35 +01001/*
Roberto Vargas59385d02018-04-17 11:31:43 +01002 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
Soby Mathewb9ff2fd2016-07-08 15:26:35 +01003 *
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
Julius Wernerb4c75e92017-08-01 15:16:36 -070014 * time. The optional _align parameter can be used to force a
Masahiro Yamadabe1d3ef2017-08-31 14:29:34 +090015 * 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.
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010019 */
Masahiro Yamadabe1d3ef2017-08-31 14:29:34 +090020 .macro func _name, _align=2
Douglas Raillard1c0e2082016-11-21 14:12:32 +000021 /*
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
25 * ELF file.
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.
30 */
31 .cfi_sections .debug_frame
Roberto Vargase4e342d2017-11-02 16:36:51 +000032 .section .text.asm.\_name, "ax"
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010033 .type \_name, %function
Douglas Raillard1c0e2082016-11-21 14:12:32 +000034 /*
35 * .cfi_startproc and .cfi_endproc are needed to output entries in
36 * .debug_frame
37 */
38 .cfi_startproc
Masahiro Yamadabe1d3ef2017-08-31 14:29:34 +090039 .align \_align
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010040 \_name:
41 .endm
42
43 /*
44 * This macro is used to mark the end of a function.
45 */
46 .macro endfunc _name
Douglas Raillard1c0e2082016-11-21 14:12:32 +000047 .cfi_endproc
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010048 .size \_name, . - \_name
49 .endm
50
51 /*
52 * Theses macros are used to create function labels for deprecated
53 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
54 * will fail to link and cause build failure.
55 */
56#if ERROR_DEPRECATED
57 .macro func_deprecated _name
58 func deprecated\_name
59 .endm
60
61 .macro endfunc_deprecated _name
62 endfunc deprecated\_name
63 .endm
64#else
65 .macro func_deprecated _name
66 func \_name
67 .endm
68
69 .macro endfunc_deprecated _name
70 endfunc \_name
71 .endm
72#endif
73
74 /*
75 * Helper assembler macro to count trailing zeros. The output is
76 * populated in the `TZ_COUNT` symbol.
77 */
78 .macro count_tz _value, _tz_count
79 .if \_value
80 count_tz "(\_value >> 1)", "(\_tz_count + 1)"
81 .else
82 .equ TZ_COUNT, (\_tz_count - 1)
83 .endif
84 .endm
85
86 /*
87 * This macro declares an array of 1 or more stacks, properly
88 * aligned and in the requested section
89 */
90#define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */
91
92 .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
93 count_tz \_align, 0
94 .if (\_align - (1 << TZ_COUNT))
95 .error "Incorrect stack alignment specified (Must be a power of 2)."
96 .endif
97 .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
98 .error "Stack size not correctly aligned"
99 .endif
100 .section \_section, "aw", %nobits
101 .align TZ_COUNT
102 \_name:
103 .space ((\_count) * (\_size)), 0
104 .endm
105
106
107#endif /* __ASM_MACROS_COMMON_S__ */