Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 9fc5963 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | c3cf06f | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 6 | #ifndef ASM_MACROS_COMMON_S |
| 7 | #define ASM_MACROS_COMMON_S |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 8 | |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 9 | /* |
Andre Przywara | bdac600 | 2025-04-15 13:24:40 +0100 | [diff] [blame^] | 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 | /* |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 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 |
Douglas Raillard | b91d935 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 26 | * to enable elimination of unused code during linking. It also adds |
| 27 | * basic debug information to enable call stack printing most of the |
Julius Werner | 64726e6 | 2017-08-01 15:16:36 -0700 | [diff] [blame] | 28 | * time. The optional _align parameter can be used to force a |
Masahiro Yamada | fed18b3 | 2017-08-31 14:29:34 +0900 | [diff] [blame] | 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. |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 33 | */ |
Masahiro Yamada | fed18b3 | 2017-08-31 14:29:34 +0900 | [diff] [blame] | 34 | .macro func _name, _align=2 |
Douglas Raillard | b91d935 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 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 |
Roberto Vargas | d1f7292 | 2017-11-02 16:36:51 +0000 | [diff] [blame] | 46 | .section .text.asm.\_name, "ax" |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 47 | .type \_name, %function |
Douglas Raillard | b91d935 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 48 | /* |
| 49 | * .cfi_startproc and .cfi_endproc are needed to output entries in |
| 50 | * .debug_frame |
| 51 | */ |
| 52 | .cfi_startproc |
Masahiro Yamada | fed18b3 | 2017-08-31 14:29:34 +0900 | [diff] [blame] | 53 | .align \_align |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 54 | \_name: |
Alexei Fedorov | 9fc5963 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 55 | #if ENABLE_BTI |
| 56 | /* When Branch Target Identification is enabled, insert "bti jc" |
| 57 | * instruction to enable indirect calls and branches |
| 58 | */ |
Andre Przywara | bdac600 | 2025-04-15 13:24:40 +0100 | [diff] [blame^] | 59 | BTI jc |
Alexei Fedorov | 9fc5963 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 60 | #endif |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 61 | .endm |
| 62 | |
| 63 | /* |
| 64 | * This macro is used to mark the end of a function. |
| 65 | */ |
| 66 | .macro endfunc _name |
Douglas Raillard | b91d935 | 2016-11-21 14:12:32 +0000 | [diff] [blame] | 67 | .cfi_endproc |
Soby Mathew | 738b1fd | 2016-07-08 15:26:35 +0100 | [diff] [blame] | 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 | |
Antonio Nino Diaz | c3cf06f | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 127 | #endif /* ASM_MACROS_COMMON_S */ |