asm.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. .macro function name, export=0, align=2
  32. .macro endfunc
  33. ELF .size \name, . - \name
  34. FUNC .endfunc
  35. .purgem endfunc
  36. .endm
  37. .text
  38. .align \align
  39. .if \export
  40. .global EXTERN_ASM\name
  41. ELF .type EXTERN_ASM\name, %function
  42. FUNC .func EXTERN_ASM\name
  43. EXTERN_ASM\name:
  44. .else
  45. ELF .type \name, %function
  46. FUNC .func \name
  47. \name:
  48. .endif
  49. .endm
  50. .macro const name, align=2, relocate=0
  51. .macro endconst
  52. ELF .size \name, . - \name
  53. .purgem endconst
  54. .endm
  55. #if HAVE_SECTION_DATA_REL_RO
  56. .if \relocate
  57. .section .data.rel.ro
  58. .else
  59. .section .rodata
  60. .endif
  61. #elif defined(_WIN32)
  62. .section .rdata
  63. #elif !defined(__MACH__)
  64. .section .rodata
  65. #else
  66. .const_data
  67. #endif
  68. .align \align
  69. \name:
  70. .endm
  71. .macro movrel rd, val, offset=0
  72. #if CONFIG_PIC && defined(__APPLE__)
  73. .if \offset < 0
  74. adrp \rd, \val@PAGE
  75. add \rd, \rd, \val@PAGEOFF
  76. sub \rd, \rd, -(\offset)
  77. .else
  78. adrp \rd, \val+(\offset)@PAGE
  79. add \rd, \rd, \val+(\offset)@PAGEOFF
  80. .endif
  81. #elif CONFIG_PIC && defined(_WIN32)
  82. .if \offset < 0
  83. adrp \rd, \val
  84. add \rd, \rd, :lo12:\val
  85. sub \rd, \rd, -(\offset)
  86. .else
  87. adrp \rd, \val+(\offset)
  88. add \rd, \rd, :lo12:\val+(\offset)
  89. .endif
  90. #elif CONFIG_PIC
  91. adrp \rd, \val+(\offset)
  92. add \rd, \rd, :lo12:\val+(\offset)
  93. #else
  94. ldr \rd, =\val+\offset
  95. #endif
  96. .endm
  97. #define GLUE(a, b) a ## b
  98. #define JOIN(a, b) GLUE(a, b)
  99. #define X(s) JOIN(EXTERN_ASM, s)