blob: 023124b30af9725456d322819527abe66a6ce706 [file] [log] [blame]
Soby Mathewb9ff2fd2016-07-08 15:26:35 +01001/*
2 * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30#ifndef __ASM_MACROS_COMMON_S__
31#define __ASM_MACROS_COMMON_S__
32
Soby Mathewb9ff2fd2016-07-08 15:26:35 +010033 /*
34 * This macro is used to create a function label and place the
35 * code into a separate text section based on the function name
36 * to enable elimination of unused code during linking
37 */
38 .macro func _name
39 .section .text.\_name, "ax"
40 .type \_name, %function
41 .func \_name
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 .size \_name, . - \_name
51 .endm
52
53 /*
54 * Theses macros are used to create function labels for deprecated
55 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
56 * will fail to link and cause build failure.
57 */
58#if ERROR_DEPRECATED
59 .macro func_deprecated _name
60 func deprecated\_name
61 .endm
62
63 .macro endfunc_deprecated _name
64 endfunc deprecated\_name
65 .endm
66#else
67 .macro func_deprecated _name
68 func \_name
69 .endm
70
71 .macro endfunc_deprecated _name
72 endfunc \_name
73 .endm
74#endif
75
76 /*
77 * Helper assembler macro to count trailing zeros. The output is
78 * populated in the `TZ_COUNT` symbol.
79 */
80 .macro count_tz _value, _tz_count
81 .if \_value
82 count_tz "(\_value >> 1)", "(\_tz_count + 1)"
83 .else
84 .equ TZ_COUNT, (\_tz_count - 1)
85 .endif
86 .endm
87
88 /*
89 * This macro declares an array of 1 or more stacks, properly
90 * aligned and in the requested section
91 */
92#define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */
93
94 .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
95 count_tz \_align, 0
96 .if (\_align - (1 << TZ_COUNT))
97 .error "Incorrect stack alignment specified (Must be a power of 2)."
98 .endif
99 .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
100 .error "Stack size not correctly aligned"
101 .endif
102 .section \_section, "aw", %nobits
103 .align TZ_COUNT
104 \_name:
105 .space ((\_count) * (\_size)), 0
106 .endm
107
108
109#endif /* __ASM_MACROS_COMMON_S__ */