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 21#include "config.h" 22 23#ifdef __ELF__ 24# define ELF 25#else 26# define ELF @ 27#endif 28 29#if CONFIG_THUMB 30# define A @ 31# define T 32#else 33# define A 34# define T @ 35#endif 36 37#if HAVE_AS_FUNC 38# define FUNC 39#else 40# define FUNC @ 41#endif 42 43#if HAVE_AS_FPU_DIRECTIVE 44# define FPU 45#else 46# define FPU @ 47#endif 48 49#if CONFIG_THUMB && defined(__APPLE__) 50# define TFUNC 51#else 52# define TFUNC @ 53#endif 54 55#if HAVE_AS_ARCH_DIRECTIVE 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 65#endif 66#if HAVE_AS_OBJECT_ARCH 67ELF .object_arch armv4 68#endif 69 70#if HAVE_NEON 71FPU .fpu neon 72ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch 73ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch 74#elif HAVE_VFP 75FPU .fpu vfp 76ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch 77#endif 78 79 .syntax unified 80T .thumb 81ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved 82ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable 83 84.macro function name, export=0, align=2 85 .set .Lpic_idx, 0 86 .set .Lpic_gp, 0 87 .macro endfunc 88 .if .Lpic_idx 89 .align 2 90 .altmacro 91 put_pic %(.Lpic_idx - 1) 92 .noaltmacro 93 .endif 94 .if .Lpic_gp 95 .unreq gp 96 .endif 97ELF .size \name, . - \name 98FUNC .endfunc 99 .purgem endfunc 100 .endm 101 .text 102 .align \align 103 .if \export 104 .global EXTERN_ASM\name 105ELF .type EXTERN_ASM\name, %function 106FUNC .func EXTERN_ASM\name 107TFUNC .thumb_func EXTERN_ASM\name 108EXTERN_ASM\name: 109 .else 110ELF .type \name, %function 111FUNC .func \name 112TFUNC .thumb_func \name 113\name: 114 .endif 115.endm 116 117.macro const name, align=2, relocate=0 118 .macro endconst 119ELF .size \name, . - \name 120 .purgem endconst 121 .endm 122#if HAVE_SECTION_DATA_REL_RO 123.if \relocate 124 .section .data.rel.ro 125.else 126 .section .rodata 127.endif 128#elif defined(_WIN32) 129 .section .rdata 130#elif !defined(__MACH__) 131 .section .rodata 132#else 133 .const_data 134#endif 135 .align \align 136\name: 137.endm 138 139#if !HAVE_ARMV6T2_EXTERNAL 140.macro movw rd, val 141 mov \rd, \val & 255 142 orr \rd, \val & ~255 143.endm 144#endif 145 146.macro mov32 rd, val 147#if HAVE_ARMV6T2_EXTERNAL 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 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 184A ldr \rd, [pc, \rd] 185T add \rd, pc 186T ldr \rd, [\rd] 187 .else 188 add \rd, pc 189 .endif 190 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@ 191.endm 192 193.macro movrel rd, val 194#if CONFIG_PIC 195 ldpic \rd, \val 196#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__) 197 movw \rd, #:lower16:\val 198 movt \rd, #:upper16:\val 199#else 200 ldr \rd, =\val 201#endif 202.endm 203 204.macro movrelx rd, val, gp 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 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 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 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 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 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 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 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 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 308.macro ldrb_post rt, rn, rm 309A ldrb \rt, [\rn], \rm 310T ldrb \rt, [\rn] 311T add \rn, \rn, \rm 312.endm 313 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 356#if HAVE_VFP_ARGS 357ELF .eabi_attribute 28, 1 358# define VFP 359# define NOVFP @ 360#else 361# define VFP @ 362# define NOVFP 363#endif 364 365#define GLUE(a, b) a ## b 366#define JOIN(a, b) GLUE(a, b) 367#define X(s) JOIN(EXTERN_ASM, s) 368