1/* 2 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6#ifndef __ASM_MACROS_COMMON_S__ 7#define __ASM_MACROS_COMMON_S__ 8 9 /* 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. 19 */ 20 .macro func _name, _align=2 21 /* 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 32 .section .text.\_name, "ax" 33 .type \_name, %function 34 .func \_name 35 /* 36 * .cfi_startproc and .cfi_endproc are needed to output entries in 37 * .debug_frame 38 */ 39 .cfi_startproc 40 .align \_align 41 \_name: 42 .endm 43 44 /* 45 * This macro is used to mark the end of a function. 46 */ 47 .macro endfunc _name 48 .endfunc 49 .cfi_endproc 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__ */ 110