asm_macros_common.S 3.1 KB

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