blob: ee59a939d4f2a68681751409f7dc8cb6d6c44c01 [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
33#include <arch.h>
34
35 /*
36 * This macro is used to create a function label and place the
37 * code into a separate text section based on the function name
38 * to enable elimination of unused code during linking
39 */
40 .macro func _name
41 .section .text.\_name, "ax"
42 .type \_name, %function
43 .func \_name
44 \_name:
45 .endm
46
47 /*
48 * This macro is used to mark the end of a function.
49 */
50 .macro endfunc _name
51 .endfunc
52 .size \_name, . - \_name
53 .endm
54
55 /*
56 * Theses macros are used to create function labels for deprecated
57 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs
58 * will fail to link and cause build failure.
59 */
60#if ERROR_DEPRECATED
61 .macro func_deprecated _name
62 func deprecated\_name
63 .endm
64
65 .macro endfunc_deprecated _name
66 endfunc deprecated\_name
67 .endm
68#else
69 .macro func_deprecated _name
70 func \_name
71 .endm
72
73 .macro endfunc_deprecated _name
74 endfunc \_name
75 .endm
76#endif
77
78 /*
79 * Helper assembler macro to count trailing zeros. The output is
80 * populated in the `TZ_COUNT` symbol.
81 */
82 .macro count_tz _value, _tz_count
83 .if \_value
84 count_tz "(\_value >> 1)", "(\_tz_count + 1)"
85 .else
86 .equ TZ_COUNT, (\_tz_count - 1)
87 .endif
88 .endm
89
90 /*
91 * This macro declares an array of 1 or more stacks, properly
92 * aligned and in the requested section
93 */
94#define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */
95
96 .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
97 count_tz \_align, 0
98 .if (\_align - (1 << TZ_COUNT))
99 .error "Incorrect stack alignment specified (Must be a power of 2)."
100 .endif
101 .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
102 .error "Stack size not correctly aligned"
103 .endif
104 .section \_section, "aw", %nobits
105 .align TZ_COUNT
106 \_name:
107 .space ((\_count) * (\_size)), 0
108 .endm
109
110
111#endif /* __ASM_MACROS_COMMON_S__ */