Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 90f2e88 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 6 | #ifndef ASM_MACROS_COMMON_S |
| 7 | #define ASM_MACROS_COMMON_S |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 8 | |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 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 |
Douglas Raillard | 1c0e208 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 12 | * to enable elimination of unused code during linking. It also adds |
| 13 | * basic debug information to enable call stack printing most of the |
Julius Werner | b4c75e9 | 2017-08-01 15:16:36 -0700 | [diff] [blame] | 14 | * time. The optional _align parameter can be used to force a |
Masahiro Yamada | be1d3ef | 2017-08-31 14:29:34 +0900 | [diff] [blame] | 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. |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 19 | */ |
Masahiro Yamada | be1d3ef | 2017-08-31 14:29:34 +0900 | [diff] [blame] | 20 | .macro func _name, _align=2 |
Douglas Raillard | 1c0e208 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 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 |
Roberto Vargas | e4e342d | 2017-11-02 16:36:51 +0000 | [diff] [blame] | 32 | .section .text.asm.\_name, "ax" |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 33 | .type \_name, %function |
Douglas Raillard | 1c0e208 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 34 | /* |
| 35 | * .cfi_startproc and .cfi_endproc are needed to output entries in |
| 36 | * .debug_frame |
| 37 | */ |
| 38 | .cfi_startproc |
Masahiro Yamada | be1d3ef | 2017-08-31 14:29:34 +0900 | [diff] [blame] | 39 | .align \_align |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 40 | \_name: |
Alexei Fedorov | 90f2e88 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 41 | #if ENABLE_BTI |
| 42 | /* When Branch Target Identification is enabled, insert "bti jc" |
| 43 | * instruction to enable indirect calls and branches |
| 44 | */ |
| 45 | bti jc |
| 46 | #endif |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 47 | .endm |
| 48 | |
| 49 | /* |
| 50 | * This macro is used to mark the end of a function. |
| 51 | */ |
| 52 | .macro endfunc _name |
Douglas Raillard | 1c0e208 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 53 | .cfi_endproc |
Soby Mathew | b9ff2fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 54 | .size \_name, . - \_name |
| 55 | .endm |
| 56 | |
| 57 | /* |
| 58 | * Theses macros are used to create function labels for deprecated |
| 59 | * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs |
| 60 | * will fail to link and cause build failure. |
| 61 | */ |
| 62 | #if ERROR_DEPRECATED |
| 63 | .macro func_deprecated _name |
| 64 | func deprecated\_name |
| 65 | .endm |
| 66 | |
| 67 | .macro endfunc_deprecated _name |
| 68 | endfunc deprecated\_name |
| 69 | .endm |
| 70 | #else |
| 71 | .macro func_deprecated _name |
| 72 | func \_name |
| 73 | .endm |
| 74 | |
| 75 | .macro endfunc_deprecated _name |
| 76 | endfunc \_name |
| 77 | .endm |
| 78 | #endif |
| 79 | |
| 80 | /* |
| 81 | * Helper assembler macro to count trailing zeros. The output is |
| 82 | * populated in the `TZ_COUNT` symbol. |
| 83 | */ |
| 84 | .macro count_tz _value, _tz_count |
| 85 | .if \_value |
| 86 | count_tz "(\_value >> 1)", "(\_tz_count + 1)" |
| 87 | .else |
| 88 | .equ TZ_COUNT, (\_tz_count - 1) |
| 89 | .endif |
| 90 | .endm |
| 91 | |
| 92 | /* |
| 93 | * This macro declares an array of 1 or more stacks, properly |
| 94 | * aligned and in the requested section |
| 95 | */ |
| 96 | #define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */ |
| 97 | |
| 98 | .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN |
| 99 | count_tz \_align, 0 |
| 100 | .if (\_align - (1 << TZ_COUNT)) |
| 101 | .error "Incorrect stack alignment specified (Must be a power of 2)." |
| 102 | .endif |
| 103 | .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0) |
| 104 | .error "Stack size not correctly aligned" |
| 105 | .endif |
| 106 | .section \_section, "aw", %nobits |
| 107 | .align TZ_COUNT |
| 108 | \_name: |
| 109 | .space ((\_count) * (\_size)), 0 |
| 110 | .endm |
| 111 | |
| 112 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 113 | #endif /* ASM_MACROS_COMMON_S */ |