arm: Use .data.rel.ro for const data with relocations
[libav.git] / libavutil / arm / asm.S
CommitLineData
c72ab301
MR
1/*
2 * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
3 *
2912e87a 4 * This file is part of Libav.
c72ab301 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
c72ab301
MR
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 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
c72ab301
MR
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
2912e87a 17 * License along with Libav; if not, write to the Free Software
c72ab301
MR
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
172a39d1
MR
21#include "config.h"
22
e21a8921 23#ifdef __ELF__
341f394f
MR
24# define ELF
25#else
26# define ELF @
e21a8921 27#endif
341f394f 28
8986fddc
MR
29#if CONFIG_THUMB
30# define A @
31# define T
32#else
33# define A
34# define T @
35#endif
36
d5a55981
JG
37#if HAVE_AS_FUNC
38# define FUNC
39#else
40# define FUNC @
41#endif
42
8ee2b467
MR
43#if HAVE_NEON
44 .arch armv7-a
45#elif HAVE_ARMV6T2
46 .arch armv6t2
47#elif HAVE_ARMV6
48 .arch armv6
49#elif HAVE_ARMV5TE
50 .arch armv5te
51#endif
52
53#if HAVE_NEON
54 .fpu neon
b3267559 55#elif HAVE_VFP
8ee2b467
MR
56 .fpu vfp
57#endif
58
371266da 59 .syntax unified
8986fddc 60T .thumb
51a15ed7 61ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
543156d7 62ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
c72ab301 63
5dae4872 64.macro function name, export=0, align=2
62634158
MR
65 .set .Lpic_idx, 0
66 .set .Lpic_gp, 0
480cb7ed 67 .macro endfunc
62634158 68 .if .Lpic_idx
cdb7db5a 69 .align 2
62634158
MR
70 .altmacro
71 put_pic %(.Lpic_idx - 1)
72 .noaltmacro
73 .endif
18c31f6f 74ELF .size \name, . - \name
d5a55981 75FUNC .endfunc
a7e7d40c 76 .purgem endfunc
480cb7ed 77 .endm
278caa6a 78 .text
5dae4872 79 .align \align
480cb7ed 80 .if \export
e654b7c2 81 .global EXTERN_ASM\name
e3fec3f0 82ELF .type EXTERN_ASM\name, %function
d5a55981 83FUNC .func EXTERN_ASM\name
e654b7c2 84EXTERN_ASM\name:
e3fec3f0 85 .else
341f394f 86ELF .type \name, %function
d5a55981 87FUNC .func \name
c72ab301 88\name:
e3fec3f0 89 .endif
480cb7ed 90.endm
172a39d1 91
f963f803 92.macro const name, align=2, relocate=0
b9a639dd
MR
93 .macro endconst
94ELF .size \name, . - \name
95 .purgem endconst
96 .endm
f963f803
MS
97.if HAVE_SECTION_DATA_REL_RO && \relocate
98 .section .data.rel.ro
99.else
b9a639dd 100 .section .rodata
f963f803 101.endif
b9a639dd
MR
102 .align \align
103\name:
104.endm
105
a7831d50 106#if !HAVE_ARMV6T2_EXTERNAL
dac78fd1
MR
107.macro movw rd, val
108 mov \rd, \val & 255
109 orr \rd, \val & ~255
110.endm
111#endif
112
a4edc5a9 113.macro mov32 rd, val
a7831d50 114#if HAVE_ARMV6T2_EXTERNAL
a4edc5a9
MR
115 movw \rd, #(\val) & 0xffff
116 .if (\val) >> 16
117 movt \rd, #(\val) >> 16
118 .endif
119#else
120 ldr \rd, =\val
121#endif
122.endm
123
62634158
MR
124.macro put_pic num
125 put_pic_\num
126.endm
127
128.macro do_def_pic num, val, label
129 .macro put_pic_\num
130 .if \num
131 .altmacro
132 put_pic %(\num - 1)
133 .noaltmacro
134 .endif
135\label: .word \val
136 .purgem put_pic_\num
137 .endm
138.endm
139
140.macro def_pic val, label
141 .altmacro
142 do_def_pic %.Lpic_idx, \val, \label
143 .noaltmacro
144 .set .Lpic_idx, .Lpic_idx + 1
145.endm
146
147.macro ldpic rd, val, indir=0
148 ldr \rd, .Lpicoff\@
149.Lpic\@:
150 .if \indir
7bda4ed7
MR
151A ldr \rd, [pc, \rd]
152T add \rd, pc
153T ldr \rd, [\rd]
62634158 154 .else
8995d349 155 add \rd, pc
62634158
MR
156 .endif
157 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
158.endm
159
480cb7ed 160.macro movrel rd, val
62634158
MR
161#if CONFIG_PIC
162 ldpic \rd, \val
a7831d50 163#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
172a39d1
MR
164 movw \rd, #:lower16:\val
165 movt \rd, #:upper16:\val
166#else
167 ldr \rd, =\val
168#endif
480cb7ed 169.endm
ce742de2 170
62634158
MR
171.macro movrelx rd, val, gp
172#if CONFIG_PIC && defined(__ELF__)
173 .ifnb \gp
174 .if .Lpic_gp
175 .unreq gp
176 .endif
177 gp .req \gp
178 ldpic gp, _GLOBAL_OFFSET_TABLE_
179 .elseif !.Lpic_gp
180 gp .req r12
181 ldpic gp, _GLOBAL_OFFSET_TABLE_
182 .endif
183 .set .Lpic_gp, 1
184 ldr \rd, .Lpicoff\@
185 ldr \rd, [gp, \rd]
186 def_pic \val(GOT), .Lpicoff\@
187#elif CONFIG_PIC && defined(__APPLE__)
188 ldpic \rd, .Lpic\@, indir=1
189 .non_lazy_symbol_pointer
190.Lpic\@:
191 .indirect_symbol \val
192 .word 0
193 .text
194#else
195 movrel \rd, \val
196#endif
197.endm
198
7689eea4
MR
199.macro add_sh rd, rn, rm, sh:vararg
200A add \rd, \rn, \rm, \sh
201T mov \rm, \rm, \sh
202T add \rd, \rn, \rm
203.endm
204
8986fddc
MR
205.macro ldr_pre rt, rn, rm:vararg
206A ldr \rt, [\rn, \rm]!
207T add \rn, \rn, \rm
208T ldr \rt, [\rn]
209.endm
210
71ce7602
MR
211.macro ldr_dpre rt, rn, rm:vararg
212A ldr \rt, [\rn, -\rm]!
213T sub \rn, \rn, \rm
214T ldr \rt, [\rn]
215.endm
216
dac78fd1
MR
217.macro ldr_nreg rt, rn, rm:vararg
218A ldr \rt, [\rn, -\rm]
219T sub \rt, \rn, \rm
220T ldr \rt, [\rt]
221.endm
222
8986fddc
MR
223.macro ldr_post rt, rn, rm:vararg
224A ldr \rt, [\rn], \rm
225T ldr \rt, [\rn]
226T add \rn, \rn, \rm
227.endm
228
cbddee1c
JG
229.macro ldrc_pre cc, rt, rn, rm:vararg
230A ldr\cc \rt, [\rn, \rm]!
231T itt \cc
232T add\cc \rn, \rn, \rm
233T ldr\cc \rt, [\rn]
234.endm
235
8986fddc
MR
236.macro ldrd_reg rt, rt2, rn, rm
237A ldrd \rt, \rt2, [\rn, \rm]
238T add \rt, \rn, \rm
239T ldrd \rt, \rt2, [\rt]
240.endm
241
242.macro ldrd_post rt, rt2, rn, rm
243A ldrd \rt, \rt2, [\rn], \rm
244T ldrd \rt, \rt2, [\rn]
245T add \rn, \rn, \rm
246.endm
247
248.macro ldrh_pre rt, rn, rm
249A ldrh \rt, [\rn, \rm]!
250T add \rn, \rn, \rm
251T ldrh \rt, [\rn]
252.endm
253
254.macro ldrh_dpre rt, rn, rm
255A ldrh \rt, [\rn, -\rm]!
256T sub \rn, \rn, \rm
257T ldrh \rt, [\rn]
258.endm
259
260.macro ldrh_post rt, rn, rm
261A ldrh \rt, [\rn], \rm
262T ldrh \rt, [\rn]
263T add \rn, \rn, \rm
264.endm
265
dac78fd1
MR
266.macro ldrb_post rt, rn, rm
267A ldrb \rt, [\rn], \rm
268T ldrb \rt, [\rn]
269T add \rn, \rn, \rm
270.endm
271
8986fddc
MR
272.macro str_post rt, rn, rm:vararg
273A str \rt, [\rn], \rm
274T str \rt, [\rn]
275T add \rn, \rn, \rm
276.endm
277
278.macro strb_post rt, rn, rm:vararg
279A strb \rt, [\rn], \rm
280T strb \rt, [\rn]
281T add \rn, \rn, \rm
282.endm
283
284.macro strd_post rt, rt2, rn, rm
285A strd \rt, \rt2, [\rn], \rm
286T strd \rt, \rt2, [\rn]
287T add \rn, \rn, \rm
288.endm
289
290.macro strh_pre rt, rn, rm
291A strh \rt, [\rn, \rm]!
292T add \rn, \rn, \rm
293T strh \rt, [\rn]
294.endm
295
296.macro strh_dpre rt, rn, rm
297A strh \rt, [\rn, -\rm]!
298T sub \rn, \rn, \rm
299T strh \rt, [\rn]
300.endm
301
302.macro strh_post rt, rn, rm
303A strh \rt, [\rn], \rm
304T strh \rt, [\rn]
305T add \rn, \rn, \rm
306.endm
307
308.macro strh_dpost rt, rn, rm
309A strh \rt, [\rn], -\rm
310T strh \rt, [\rn]
311T sub \rn, \rn, \rm
312.endm
313
ce742de2 314#if HAVE_VFP_ARGS
be7952b5 315ELF .eabi_attribute 28, 1
ce742de2
MR
316# define VFP
317# define NOVFP @
318#else
319# define VFP @
320# define NOVFP
321#endif
e654b7c2
MR
322
323#define GLUE(a, b) a ## b
324#define JOIN(a, b) GLUE(a, b)
325#define X(s) JOIN(EXTERN_ASM, s)