1/* 2 * Arm SCP/MCP Software 3 * Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7#ifndef ASM_MACROS_COMMON_S 8#define ASM_MACROS_COMMON_S 9 10 /* 11 * This macro is used to create a function label and place the 12 * code into a separate text section based on the function name 13 * to enable elimination of unused code during linking. It also adds 14 * basic debug information to enable call stack printing most of the 15 * time. The optional _align parameter can be used to force a 16 * non-standard alignment (indicated in powers of 2). The default is 17 * _align=2 because both Aarch32 and Aarch64 instructions must be 18 * word aligned. Do *not* try to use a raw .align directive. Since func 19 * switches to a new section, this would not have the desired effect. 20 */ 21 .macro func _name, _align=2 22 /* 23 * Add Call Frame Information entry in the .debug_frame section for 24 * debugger consumption. This enables callstack printing in debuggers. 25 * This does not use any space in the final loaded binary, only in the 26 * ELF file. 27 * Note that a function manipulating the CFA pointer location (i.e. the 28 * x29 frame pointer on AArch64) should declare it using the 29 * appropriate .cfi* directives, or be prepared to have a degraded 30 * debugging experience. 31 */ 32 .cfi_sections .debug_frame 33 .section .text.asm.\_name, "ax" 34 .type \_name, %function 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 .cfi_endproc 49 .size \_name, . - \_name 50 .endm 51 52 /* 53 * Theses macros are used to create function labels for deprecated 54 * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs 55 * will fail to link and cause build failure. 56 */ 57#if ERROR_DEPRECATED 58 .macro func_deprecated _name 59 func deprecated\_name 60 .endm 61 62 .macro endfunc_deprecated _name 63 endfunc deprecated\_name 64 .endm 65#else 66 .macro func_deprecated _name 67 func \_name 68 .endm 69 70 .macro endfunc_deprecated _name 71 endfunc \_name 72 .endm 73#endif 74 75 /* 76 * Helper assembler macro to count trailing zeros. The output is 77 * populated in the `TZ_COUNT` symbol. 78 */ 79 .macro count_tz _value, _tz_count 80 .if \_value 81 count_tz "(\_value >> 1)", "(\_tz_count + 1)" 82 .else 83 .equ TZ_COUNT, (\_tz_count - 1) 84 .endif 85 .endm 86 87 /* 88 * This macro declares an array of 1 or more stacks, properly 89 * aligned and in the requested section 90 */ 91#define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */ 92 93 .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN 94 count_tz \_align, 0 95 .if (\_align - (1 << TZ_COUNT)) 96 .error "Incorrect stack alignment specified (Must be a power of 2)." 97 .endif 98 .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0) 99 .error "Stack size not correctly aligned" 100 .endif 101 .section \_section, "aw", %nobits 102 .align TZ_COUNT 103 \_name: 104 .space ((\_count) * (\_size)), 0 105 .endm 106 107 108#endif /* ASM_MACROS_COMMON_S */ 109