asm.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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(__MACH__)
  62. .section .rodata
  63. #else
  64. .const_data
  65. #endif
  66. .align \align
  67. \name:
  68. .endm
  69. .macro movrel rd, val, offset=0
  70. #if CONFIG_PIC && defined(__APPLE__)
  71. .if \offset < 0
  72. adrp \rd, \val@PAGE
  73. add \rd, \rd, \val@PAGEOFF
  74. sub \rd, \rd, -(\offset)
  75. .else
  76. adrp \rd, \val+(\offset)@PAGE
  77. add \rd, \rd, \val+(\offset)@PAGEOFF
  78. .endif
  79. #elif CONFIG_PIC && defined(_WIN32)
  80. .if \offset < 0
  81. adrp \rd, \val
  82. add \rd, \rd, :lo12:\val
  83. sub \rd, \rd, -(\offset)
  84. .else
  85. adrp \rd, \val+(\offset)
  86. add \rd, \rd, :lo12:\val+(\offset)
  87. .endif
  88. #elif CONFIG_PIC
  89. adrp \rd, \val+(\offset)
  90. add \rd, \rd, :lo12:\val+(\offset)
  91. #else
  92. ldr \rd, =\val+\offset
  93. #endif
  94. .endm
  95. #define GLUE(a, b) a ## b
  96. #define JOIN(a, b) GLUE(a, b)
  97. #define X(s) JOIN(EXTERN_ASM, s)