You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.9KB

  1. /*
  2. * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config.h"
  21. #ifdef __ELF__
  22. # define ELF
  23. #else
  24. # define ELF #
  25. #endif
  26. #if HAVE_AS_FUNC
  27. # define FUNC
  28. #else
  29. # define FUNC #
  30. #endif
  31. #ifndef __has_feature
  32. # define __has_feature(x) 0
  33. #endif
  34. .macro function name, export=0, align=2
  35. .macro endfunc
  36. ELF .size \name, . - \name
  37. FUNC .endfunc
  38. .purgem endfunc
  39. .endm
  40. .text
  41. .align \align
  42. .if \export
  43. .global EXTERN_ASM\name
  44. ELF .type EXTERN_ASM\name, %function
  45. FUNC .func EXTERN_ASM\name
  46. EXTERN_ASM\name:
  47. .else
  48. ELF .type \name, %function
  49. FUNC .func \name
  50. \name:
  51. .endif
  52. .endm
  53. .macro const name, align=2, relocate=0
  54. .macro endconst
  55. ELF .size \name, . - \name
  56. .purgem endconst
  57. .endm
  58. #if HAVE_SECTION_DATA_REL_RO
  59. .if \relocate
  60. .section .data.rel.ro
  61. .else
  62. .section .rodata
  63. .endif
  64. #elif defined(_WIN32)
  65. .section .rdata
  66. #elif !defined(__MACH__)
  67. .section .rodata
  68. #else
  69. .const_data
  70. #endif
  71. .align \align
  72. \name:
  73. .endm
  74. .macro movrel rd, val, offset=0
  75. #if CONFIG_PIC && defined(__APPLE__)
  76. .if \offset < 0
  77. adrp \rd, \val@PAGE
  78. add \rd, \rd, \val@PAGEOFF
  79. sub \rd, \rd, -(\offset)
  80. .else
  81. adrp \rd, \val+(\offset)@PAGE
  82. add \rd, \rd, \val+(\offset)@PAGEOFF
  83. .endif
  84. #elif CONFIG_PIC && defined(_WIN32)
  85. .if \offset < 0
  86. adrp \rd, \val
  87. add \rd, \rd, :lo12:\val
  88. sub \rd, \rd, -(\offset)
  89. .else
  90. adrp \rd, \val+(\offset)
  91. add \rd, \rd, :lo12:\val+(\offset)
  92. .endif
  93. #elif CONFIG_PIC
  94. # if __has_feature(hwaddress_sanitizer)
  95. adrp \rd, :pg_hi21_nc:\val+(\offset)
  96. # else
  97. adrp \rd, \val+(\offset)
  98. # endif
  99. add \rd, \rd, :lo12:\val+(\offset)
  100. #else
  101. ldr \rd, =\val+\offset
  102. #endif
  103. .endm
  104. #define GLUE(a, b) a ## b
  105. #define JOIN(a, b) GLUE(a, b)
  106. #define X(s) JOIN(EXTERN_ASM, s)