arm: Create proper .rdata sections for COFF
[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
6f9e34ba
MS
43#if HAVE_AS_FPU_DIRECTIVE
44# define FPU
45#else
46# define FPU @
47#endif
48
5584abf6
MS
49#if CONFIG_THUMB && defined(__APPLE__)
50# define TFUNC
51#else
52# define TFUNC @
53#endif
54
59cee42d 55#if HAVE_AS_ARCH_DIRECTIVE
8ee2b467
MR
56#if HAVE_NEON
57 .arch armv7-a
58#elif HAVE_ARMV6T2
59 .arch armv6t2
60#elif HAVE_ARMV6
61 .arch armv6
62#elif HAVE_ARMV5TE
63 .arch armv5te
64#endif
59cee42d 65#endif
dcae2e32
MS
66#if HAVE_AS_OBJECT_ARCH
67ELF .object_arch armv4
68#endif
8ee2b467
MR
69
70#if HAVE_NEON
6f9e34ba 71FPU .fpu neon
dcae2e32
MS
72ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
73ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch
b3267559 74#elif HAVE_VFP
6f9e34ba 75FPU .fpu vfp
dcae2e32 76ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
8ee2b467
MR
77#endif
78
371266da 79 .syntax unified
8986fddc 80T .thumb
51a15ed7 81ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
543156d7 82ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
c72ab301 83
5dae4872 84.macro function name, export=0, align=2
62634158
MR
85 .set .Lpic_idx, 0
86 .set .Lpic_gp, 0
480cb7ed 87 .macro endfunc
62634158 88 .if .Lpic_idx
cdb7db5a 89 .align 2
62634158
MR
90 .altmacro
91 put_pic %(.Lpic_idx - 1)
92 .noaltmacro
93 .endif
824e8c28
MS
94 .if .Lpic_gp
95 .unreq gp
96 .endif
18c31f6f 97ELF .size \name, . - \name
d5a55981 98FUNC .endfunc
a7e7d40c 99 .purgem endfunc
480cb7ed 100 .endm
278caa6a 101 .text
5dae4872 102 .align \align
480cb7ed 103 .if \export
e654b7c2 104 .global EXTERN_ASM\name
e3fec3f0 105ELF .type EXTERN_ASM\name, %function
d5a55981 106FUNC .func EXTERN_ASM\name
5584abf6 107TFUNC .thumb_func EXTERN_ASM\name
e654b7c2 108EXTERN_ASM\name:
e3fec3f0 109 .else
341f394f 110ELF .type \name, %function
d5a55981 111FUNC .func \name
5584abf6 112TFUNC .thumb_func \name
c72ab301 113\name:
e3fec3f0 114 .endif
480cb7ed 115.endm
172a39d1 116
f963f803 117.macro const name, align=2, relocate=0
b9a639dd
MR
118 .macro endconst
119ELF .size \name, . - \name
120 .purgem endconst
121 .endm
3a7b4ae6
MS
122#if HAVE_SECTION_DATA_REL_RO
123.if \relocate
f963f803
MS
124 .section .data.rel.ro
125.else
b9a639dd 126 .section .rodata
f963f803 127.endif
41cf3e3b
MS
128#elif defined(_WIN32)
129 .section .rdata
3a7b4ae6
MS
130#elif !defined(__MACH__)
131 .section .rodata
132#else
133 .const_data
134#endif
b9a639dd
MR
135 .align \align
136\name:
137.endm
138
a7831d50 139#if !HAVE_ARMV6T2_EXTERNAL
dac78fd1
MR
140.macro movw rd, val
141 mov \rd, \val & 255
142 orr \rd, \val & ~255
143.endm
144#endif
145
a4edc5a9 146.macro mov32 rd, val
a7831d50 147#if HAVE_ARMV6T2_EXTERNAL
a4edc5a9
MR
148 movw \rd, #(\val) & 0xffff
149 .if (\val) >> 16
150 movt \rd, #(\val) >> 16
151 .endif
152#else
153 ldr \rd, =\val
154#endif
155.endm
156
62634158
MR
157.macro put_pic num
158 put_pic_\num
159.endm
160
161.macro do_def_pic num, val, label
162 .macro put_pic_\num
163 .if \num
164 .altmacro
165 put_pic %(\num - 1)
166 .noaltmacro
167 .endif
168\label: .word \val
169 .purgem put_pic_\num
170 .endm
171.endm
172
173.macro def_pic val, label
174 .altmacro
175 do_def_pic %.Lpic_idx, \val, \label
176 .noaltmacro
177 .set .Lpic_idx, .Lpic_idx + 1
178.endm
179
180.macro ldpic rd, val, indir=0
181 ldr \rd, .Lpicoff\@
182.Lpic\@:
183 .if \indir
7bda4ed7
MR
184A ldr \rd, [pc, \rd]
185T add \rd, pc
186T ldr \rd, [\rd]
62634158 187 .else
8995d349 188 add \rd, pc
62634158
MR
189 .endif
190 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
191.endm
192
480cb7ed 193.macro movrel rd, val
62634158
MR
194#if CONFIG_PIC
195 ldpic \rd, \val
a7831d50 196#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
172a39d1
MR
197 movw \rd, #:lower16:\val
198 movt \rd, #:upper16:\val
199#else
200 ldr \rd, =\val
201#endif
480cb7ed 202.endm
ce742de2 203
62634158 204.macro movrelx rd, val, gp
6a1ea4ec
JG
205 .ifc \rd,\gp
206 .error "movrelx needs two distinct registers"
207 .endif
208 .ifc \rd\()_\gp,r12_
209 .warning "movrelx rd=\rd without explicit set gp"
210 .endif
211 .ifc \rd\()_\gp,ip_
212 .warning "movrelx rd=\rd without explicit set gp"
213 .endif
62634158
MR
214#if CONFIG_PIC && defined(__ELF__)
215 .ifnb \gp
216 .if .Lpic_gp
217 .unreq gp
218 .endif
219 gp .req \gp
220 ldpic gp, _GLOBAL_OFFSET_TABLE_
221 .elseif !.Lpic_gp
222 gp .req r12
223 ldpic gp, _GLOBAL_OFFSET_TABLE_
224 .endif
225 .set .Lpic_gp, 1
226 ldr \rd, .Lpicoff\@
227 ldr \rd, [gp, \rd]
228 def_pic \val(GOT), .Lpicoff\@
229#elif CONFIG_PIC && defined(__APPLE__)
230 ldpic \rd, .Lpic\@, indir=1
231 .non_lazy_symbol_pointer
232.Lpic\@:
233 .indirect_symbol \val
234 .word 0
235 .text
236#else
237 movrel \rd, \val
238#endif
239.endm
240
7689eea4
MR
241.macro add_sh rd, rn, rm, sh:vararg
242A add \rd, \rn, \rm, \sh
243T mov \rm, \rm, \sh
244T add \rd, \rn, \rm
245.endm
246
8986fddc
MR
247.macro ldr_pre rt, rn, rm:vararg
248A ldr \rt, [\rn, \rm]!
249T add \rn, \rn, \rm
250T ldr \rt, [\rn]
251.endm
252
71ce7602
MR
253.macro ldr_dpre rt, rn, rm:vararg
254A ldr \rt, [\rn, -\rm]!
255T sub \rn, \rn, \rm
256T ldr \rt, [\rn]
257.endm
258
dac78fd1
MR
259.macro ldr_nreg rt, rn, rm:vararg
260A ldr \rt, [\rn, -\rm]
261T sub \rt, \rn, \rm
262T ldr \rt, [\rt]
263.endm
264
8986fddc
MR
265.macro ldr_post rt, rn, rm:vararg
266A ldr \rt, [\rn], \rm
267T ldr \rt, [\rn]
268T add \rn, \rn, \rm
269.endm
270
cbddee1c
JG
271.macro ldrc_pre cc, rt, rn, rm:vararg
272A ldr\cc \rt, [\rn, \rm]!
273T itt \cc
274T add\cc \rn, \rn, \rm
275T ldr\cc \rt, [\rn]
276.endm
277
8986fddc
MR
278.macro ldrd_reg rt, rt2, rn, rm
279A ldrd \rt, \rt2, [\rn, \rm]
280T add \rt, \rn, \rm
281T ldrd \rt, \rt2, [\rt]
282.endm
283
284.macro ldrd_post rt, rt2, rn, rm
285A ldrd \rt, \rt2, [\rn], \rm
286T ldrd \rt, \rt2, [\rn]
287T add \rn, \rn, \rm
288.endm
289
290.macro ldrh_pre rt, rn, rm
291A ldrh \rt, [\rn, \rm]!
292T add \rn, \rn, \rm
293T ldrh \rt, [\rn]
294.endm
295
296.macro ldrh_dpre rt, rn, rm
297A ldrh \rt, [\rn, -\rm]!
298T sub \rn, \rn, \rm
299T ldrh \rt, [\rn]
300.endm
301
302.macro ldrh_post rt, rn, rm
303A ldrh \rt, [\rn], \rm
304T ldrh \rt, [\rn]
305T add \rn, \rn, \rm
306.endm
307
dac78fd1
MR
308.macro ldrb_post rt, rn, rm
309A ldrb \rt, [\rn], \rm
310T ldrb \rt, [\rn]
311T add \rn, \rn, \rm
312.endm
313
8986fddc
MR
314.macro str_post rt, rn, rm:vararg
315A str \rt, [\rn], \rm
316T str \rt, [\rn]
317T add \rn, \rn, \rm
318.endm
319
320.macro strb_post rt, rn, rm:vararg
321A strb \rt, [\rn], \rm
322T strb \rt, [\rn]
323T add \rn, \rn, \rm
324.endm
325
326.macro strd_post rt, rt2, rn, rm
327A strd \rt, \rt2, [\rn], \rm
328T strd \rt, \rt2, [\rn]
329T add \rn, \rn, \rm
330.endm
331
332.macro strh_pre rt, rn, rm
333A strh \rt, [\rn, \rm]!
334T add \rn, \rn, \rm
335T strh \rt, [\rn]
336.endm
337
338.macro strh_dpre rt, rn, rm
339A strh \rt, [\rn, -\rm]!
340T sub \rn, \rn, \rm
341T strh \rt, [\rn]
342.endm
343
344.macro strh_post rt, rn, rm
345A strh \rt, [\rn], \rm
346T strh \rt, [\rn]
347T add \rn, \rn, \rm
348.endm
349
350.macro strh_dpost rt, rn, rm
351A strh \rt, [\rn], -\rm
352T strh \rt, [\rn]
353T sub \rn, \rn, \rm
354.endm
355
ce742de2 356#if HAVE_VFP_ARGS
be7952b5 357ELF .eabi_attribute 28, 1
ce742de2
MR
358# define VFP
359# define NOVFP @
360#else
361# define VFP @
362# define NOVFP
363#endif
e654b7c2
MR
364
365#define GLUE(a, b) a ## b
366#define JOIN(a, b) GLUE(a, b)
367#define X(s) JOIN(EXTERN_ASM, s)