asmdefs.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Macros for asm code.
  4. *
  5. * Copyright (c) 2019, Arm Limited.
  6. */
  7. #ifndef _ASMDEFS_H
  8. #define _ASMDEFS_H
  9. #if defined(__aarch64__)
  10. /* Branch Target Identitication support. */
  11. #define BTI_C hint 34
  12. #define BTI_J hint 36
  13. /* Return address signing support (pac-ret). */
  14. #define PACIASP hint 25; .cfi_window_save
  15. #define AUTIASP hint 29; .cfi_window_save
  16. /* GNU_PROPERTY_AARCH64_* macros from elf.h. */
  17. #define FEATURE_1_AND 0xc0000000
  18. #define FEATURE_1_BTI 1
  19. #define FEATURE_1_PAC 2
  20. /* Add a NT_GNU_PROPERTY_TYPE_0 note. */
  21. #define GNU_PROPERTY(type, value) \
  22. .section .note.gnu.property, "a"; \
  23. .p2align 3; \
  24. .word 4; \
  25. .word 16; \
  26. .word 5; \
  27. .asciz "GNU"; \
  28. .word type; \
  29. .word 4; \
  30. .word value; \
  31. .word 0; \
  32. .text
  33. /* If set then the GNU Property Note section will be added to
  34. mark objects to support BTI and PAC-RET. */
  35. #ifndef WANT_GNU_PROPERTY
  36. #define WANT_GNU_PROPERTY 1
  37. #endif
  38. #if WANT_GNU_PROPERTY
  39. /* Add property note with supported features to all asm files. */
  40. GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC)
  41. #endif
  42. #define ENTRY_ALIGN(name, alignment) \
  43. .global name; \
  44. .type name,%function; \
  45. .align alignment; \
  46. name: \
  47. .cfi_startproc; \
  48. BTI_C;
  49. #else
  50. #define END_FILE
  51. #define ENTRY_ALIGN(name, alignment) \
  52. .global name; \
  53. .type name,%function; \
  54. .align alignment; \
  55. name: \
  56. .cfi_startproc;
  57. #endif
  58. #define ENTRY(name) ENTRY_ALIGN(name, 6)
  59. #define ENTRY_ALIAS(name) \
  60. .global name; \
  61. .type name,%function; \
  62. name:
  63. #define END(name) \
  64. .cfi_endproc; \
  65. .size name, .-name;
  66. #define L(l) .L ## l
  67. #ifdef __ILP32__
  68. /* Sanitize padding bits of pointer arguments as per aapcs64 */
  69. #define PTR_ARG(n) mov w##n, w##n
  70. #else
  71. #define PTR_ARG(n)
  72. #endif
  73. #ifdef __ILP32__
  74. /* Sanitize padding bits of size arguments as per aapcs64 */
  75. #define SIZE_ARG(n) mov w##n, w##n
  76. #else
  77. #define SIZE_ARG(n)
  78. #endif
  79. #endif