1/* 2 * Copyright (c) 2013-2019, 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 * Provide a wrapper for the "bti" instructions using the more 11 * compatible "hint" encoding, otherwise older toolchains would reject 12 * this when not compiled for a BTI capable machine (-march=armv8.5-a). 13 */ 14 .macro BTI _targets 15 .ifc \_targets, j 16 hint #36 17 .endif 18 .ifc \_targets, jc 19 hint #38 20 .endif 21 .endm 22 23 /* 24 * This macro is used to create a function label and place the 25 * code into a separate text section based on the function name 26 * to enable elimination of unused code during linking. It also adds 27 * basic debug information to enable call stack printing most of the 28 * time. The optional _align parameter can be used to force a 29 * non-standard alignment (indicated in powers of 2). The default is 30 * _align=2 because both Aarch32 and Aarch64 instructions must be 31 * word aligned. Do *not* try to use a raw .align directive. Since func 32 * switches to a new section, this would not have the desired effect. 33 */ 34 .macro func _name, _align=2 35 /* 36 * Add Call Frame Information entry in the .debug_frame section for 37 * debugger consumption. This enables callstack printing in debuggers. 38 * This does not use any space in the final loaded binary, only in the 39 * ELF file. 40 * Note that a function manipulating the CFA pointer location (i.e. the 41 * x29 frame pointer on AArch64) should declare it using the 42 * appropriate .cfi* directives, or be prepared to have a degraded 43 * debugging experience. 44 */ 45 .cfi_sections .debug_frame 46 .section .text.asm.\_name, "ax" 47 .type \_name, %function 48 /* 49 * .cfi_startproc and .cfi_endproc are needed to output entries in 50 * .debug_frame 51 */ 52 .cfi_startproc 53 .align \_align 54 \_name: 55#if ENABLE_BTI 56 /* When Branch Target Identification is enabled, insert "bti jc" 57 * instruction to enable indirect calls and branches 58 */ 59 BTI jc 60#endif 61 .endm 62 63 /* 64 * This macro is used to mark the end of a function. 65 */ 66 .macro endfunc _name 67 .cfi_endproc 68 .size \_name, . - \_name 69 .endm 70 71 /* 72 * Theses macros are used to create function labels for deprecated 73 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs 74 * will fail to link and cause build failure. 75 */ 76#if ERROR_DEPRECATED 77 .macro func_deprecated _name 78 func deprecated\_name 79 .endm 80 81 .macro endfunc_deprecated _name 82 endfunc deprecated\_name 83 .endm 84#else 85 .macro func_deprecated _name 86 func \_name 87 .endm 88 89 .macro endfunc_deprecated _name 90 endfunc \_name 91 .endm 92#endif 93 94 /* 95 * Helper assembler macro to count trailing zeros. The output is 96 * populated in the `TZ_COUNT` symbol. 97 */ 98 .macro count_tz _value, _tz_count 99 .if \_value 100 count_tz "(\_value >> 1)", "(\_tz_count + 1)" 101 .else 102 .equ TZ_COUNT, (\_tz_count - 1) 103 .endif 104 .endm 105 106 /* 107 * This macro declares an array of 1 or more stacks, properly 108 * aligned and in the requested section 109 */ 110#define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */ 111 112 .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN 113 count_tz \_align, 0 114 .if (\_align - (1 << TZ_COUNT)) 115 .error "Incorrect stack alignment specified (Must be a power of 2)." 116 .endif 117 .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0) 118 .error "Stack size not correctly aligned" 119 .endif 120 .section \_section, "aw", %nobits 121 .align TZ_COUNT 122 \_name: 123 .space ((\_count) * (\_size)), 0 124 .endm 125 126 127#endif /* ASM_MACROS_COMMON_S */ 128