2015-12-30 21:46:06 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Assembly testing and benchmarking tool
|
|
|
|
* Copyright (c) 2015 Martin Storsjo
|
|
|
|
* Copyright (c) 2015 Janne Grunau
|
|
|
|
*
|
2016-01-19 07:49:27 +00:00
|
|
|
* This file is part of FFmpeg.
|
2015-12-30 21:46:06 +00:00
|
|
|
*
|
2016-01-19 07:49:27 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or modify
|
2015-12-30 21:46:06 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2016-01-19 07:49:27 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2015-12-30 21:46:06 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "libavutil/arm/asm.S"
|
|
|
|
|
2017-01-24 18:17:38 +00:00
|
|
|
/* override fpu so that NEON instructions are rejected */
|
|
|
|
#if HAVE_VFP
|
2016-07-18 20:23:50 +00:00
|
|
|
FPU .fpu vfp
|
2017-01-24 18:17:38 +00:00
|
|
|
ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
|
|
|
|
#endif
|
|
|
|
|
2016-07-10 11:23:13 +00:00
|
|
|
const register_init, align=3
|
2020-05-12 10:44:05 +00:00
|
|
|
.quad 0x21f86d66c8ca00ce
|
|
|
|
.quad 0x75b6ba21077c48ad
|
|
|
|
.quad 0xed56bb2dcb3c7736
|
|
|
|
.quad 0x8bda43d3fd1a7e06
|
|
|
|
.quad 0xb64a9c9e5d318408
|
|
|
|
.quad 0xdf9a54b303f1d3a3
|
|
|
|
.quad 0x4a75479abd64e097
|
|
|
|
.quad 0x249214109d5d1c88
|
2015-12-30 21:46:06 +00:00
|
|
|
endconst
|
|
|
|
|
2016-07-14 21:16:14 +00:00
|
|
|
const error_message_fpscr
|
2020-05-12 10:44:05 +00:00
|
|
|
.asciz "failed to preserve register FPSCR, changed bits: %x"
|
2017-01-24 18:17:38 +00:00
|
|
|
error_message_gpr:
|
2020-05-12 10:44:05 +00:00
|
|
|
.asciz "failed to preserve register r%d"
|
2017-01-24 18:17:38 +00:00
|
|
|
error_message_vfp:
|
2020-05-12 10:44:05 +00:00
|
|
|
.asciz "failed to preserve register d%d"
|
2020-05-13 18:09:08 +00:00
|
|
|
error_message_stack:
|
|
|
|
.asciz "failed to preserve stack"
|
2015-12-30 21:46:06 +00:00
|
|
|
endconst
|
|
|
|
|
|
|
|
@ max number of args used by any asm function.
|
|
|
|
#define MAX_ARGS 15
|
|
|
|
|
2016-09-30 08:49:47 +00:00
|
|
|
#define ARG_STACK 4*(MAX_ARGS - 4)
|
2015-12-30 21:46:06 +00:00
|
|
|
|
2020-05-13 18:09:08 +00:00
|
|
|
@ Align the used stack space to 8 to preserve the stack alignment.
|
|
|
|
@ +8 for stack canary reference.
|
|
|
|
#define ARG_STACK_A (((ARG_STACK + pushed + 7) & ~7) - pushed + 8)
|
2016-07-12 20:46:43 +00:00
|
|
|
|
2015-12-30 21:46:06 +00:00
|
|
|
.macro clobbercheck variant
|
|
|
|
.equ pushed, 4*9
|
|
|
|
function checkasm_checked_call_\variant, export=1
|
2020-05-12 10:44:05 +00:00
|
|
|
push {r4-r11, lr}
|
2015-12-30 21:46:06 +00:00
|
|
|
.ifc \variant, vfp
|
2020-05-12 10:44:05 +00:00
|
|
|
vpush {d8-d15}
|
|
|
|
fmrx r4, FPSCR
|
|
|
|
push {r4}
|
2015-12-30 21:46:06 +00:00
|
|
|
.equ pushed, pushed + 16*4 + 4
|
|
|
|
.endif
|
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
movrel r12, register_init
|
2015-12-30 21:46:06 +00:00
|
|
|
.ifc \variant, vfp
|
2020-05-12 10:44:05 +00:00
|
|
|
vldm r12, {d8-d15}
|
2015-12-30 21:46:06 +00:00
|
|
|
.endif
|
2020-05-12 10:44:05 +00:00
|
|
|
ldm r12, {r4-r11}
|
2015-12-30 21:46:06 +00:00
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
sub sp, sp, #ARG_STACK_A
|
2015-12-30 21:46:06 +00:00
|
|
|
.equ pos, 0
|
2016-09-30 08:49:47 +00:00
|
|
|
.rept MAX_ARGS-4
|
2020-05-12 10:44:05 +00:00
|
|
|
ldr r12, [sp, #ARG_STACK_A + pushed + 8 + pos]
|
|
|
|
str r12, [sp, #pos]
|
2015-12-30 21:46:06 +00:00
|
|
|
.equ pos, pos + 4
|
|
|
|
.endr
|
|
|
|
|
2020-05-13 18:09:08 +00:00
|
|
|
@ For stack overflows, the callee is free to overwrite the parameters
|
|
|
|
@ that were passed on the stack (if any), so we can only check after
|
|
|
|
@ that point. First figure out how many parameters the function
|
|
|
|
@ really took on the stack:
|
|
|
|
ldr r12, [sp, #ARG_STACK_A + pushed + 8 + 4*(MAX_ARGS-4)]
|
|
|
|
@ Load the first non-parameter value from the stack, that should be
|
|
|
|
@ left untouched by the function. Store a copy of it inverted, so that
|
|
|
|
@ e.g. overwriting everything with zero would be noticed.
|
|
|
|
ldr r12, [sp, r12, lsl #2]
|
|
|
|
mvn r12, r12
|
|
|
|
str r12, [sp, #ARG_STACK_A - 4]
|
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
mov r12, r0
|
|
|
|
mov r0, r2
|
|
|
|
mov r1, r3
|
|
|
|
ldrd r2, r3, [sp, #ARG_STACK_A + pushed]
|
2020-05-13 18:09:08 +00:00
|
|
|
@ Call the target function
|
2020-05-12 10:44:05 +00:00
|
|
|
blx r12
|
2015-12-30 21:46:06 +00:00
|
|
|
|
2020-05-13 18:09:08 +00:00
|
|
|
@ Load the number of stack parameters, stack canary and its reference
|
|
|
|
ldr r12, [sp, #ARG_STACK_A + pushed + 8 + 4*(MAX_ARGS-4)]
|
|
|
|
ldr r2, [sp, r12, lsl #2]
|
|
|
|
ldr r3, [sp, #ARG_STACK_A - 4]
|
|
|
|
|
|
|
|
add sp, sp, #ARG_STACK_A
|
2020-05-12 10:44:05 +00:00
|
|
|
push {r0, r1}
|
2020-05-13 18:09:08 +00:00
|
|
|
|
|
|
|
mvn r3, r3
|
|
|
|
cmp r2, r3
|
|
|
|
bne 5f
|
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
movrel r12, register_init
|
2015-12-30 21:46:06 +00:00
|
|
|
.ifc \variant, vfp
|
2016-07-14 21:16:14 +00:00
|
|
|
.macro check_reg_vfp, dreg, offset
|
2020-05-12 10:44:05 +00:00
|
|
|
ldrd r2, r3, [r12, #8 * (\offset)]
|
|
|
|
vmov r0, lr, \dreg
|
|
|
|
eor r2, r2, r0
|
|
|
|
eor r3, r3, lr
|
|
|
|
orrs r2, r2, r3
|
|
|
|
bne 4f
|
2015-12-30 21:46:06 +00:00
|
|
|
.endm
|
|
|
|
|
2016-07-14 21:16:14 +00:00
|
|
|
.irp n, 8, 9, 10, 11, 12, 13, 14, 15
|
2020-05-12 10:44:05 +00:00
|
|
|
@ keep track of the checked double/SIMD register
|
|
|
|
mov r1, #\n
|
|
|
|
check_reg_vfp d\n, \n-8
|
2015-12-30 21:46:06 +00:00
|
|
|
.endr
|
|
|
|
.purgem check_reg_vfp
|
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
fmrx r1, FPSCR
|
|
|
|
ldr r3, [sp, #8]
|
|
|
|
eor r1, r1, r3
|
|
|
|
@ Ignore changes in bits 0-4 and 7
|
|
|
|
bic r1, r1, #0x9f
|
|
|
|
@ Ignore changes in the topmost 5 bits
|
|
|
|
bics r1, r1, #0xf8000000
|
|
|
|
bne 3f
|
2015-12-30 21:46:06 +00:00
|
|
|
.endif
|
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
@ keep track of the checked GPR
|
|
|
|
mov r1, #4
|
2015-12-30 21:46:06 +00:00
|
|
|
.macro check_reg reg1, reg2=
|
2020-05-12 10:44:05 +00:00
|
|
|
ldrd r2, r3, [r12], #8
|
|
|
|
eors r2, r2, \reg1
|
|
|
|
bne 2f
|
|
|
|
add r1, r1, #1
|
2015-12-30 21:46:06 +00:00
|
|
|
.ifnb \reg2
|
2020-05-12 10:44:05 +00:00
|
|
|
eors r3, r3, \reg2
|
|
|
|
bne 2f
|
2015-12-30 21:46:06 +00:00
|
|
|
.endif
|
2020-05-12 10:44:05 +00:00
|
|
|
add r1, r1, #1
|
2015-12-30 21:46:06 +00:00
|
|
|
.endm
|
2020-05-12 10:44:05 +00:00
|
|
|
check_reg r4, r5
|
|
|
|
check_reg r6, r7
|
2015-12-30 21:46:06 +00:00
|
|
|
@ r9 is a volatile register in the ios ABI
|
|
|
|
#ifdef __APPLE__
|
2020-05-12 10:44:05 +00:00
|
|
|
check_reg r8
|
2015-12-30 21:46:06 +00:00
|
|
|
#else
|
2020-05-12 10:44:05 +00:00
|
|
|
check_reg r8, r9
|
2015-12-30 21:46:06 +00:00
|
|
|
#endif
|
2020-05-12 10:44:05 +00:00
|
|
|
check_reg r10, r11
|
2015-12-30 21:46:06 +00:00
|
|
|
.purgem check_reg
|
|
|
|
|
2020-05-12 10:44:05 +00:00
|
|
|
b 0f
|
2020-05-13 18:09:08 +00:00
|
|
|
5:
|
|
|
|
movrel r0, error_message_stack
|
|
|
|
b 1f
|
2016-07-14 21:16:14 +00:00
|
|
|
4:
|
2020-05-12 10:44:05 +00:00
|
|
|
movrel r0, error_message_vfp
|
|
|
|
b 1f
|
2016-07-14 21:16:14 +00:00
|
|
|
3:
|
2020-05-12 10:44:05 +00:00
|
|
|
movrel r0, error_message_fpscr
|
|
|
|
b 1f
|
2016-07-14 21:16:14 +00:00
|
|
|
2:
|
2020-05-12 10:44:05 +00:00
|
|
|
movrel r0, error_message_gpr
|
2016-07-14 21:16:14 +00:00
|
|
|
1:
|
2020-05-12 12:50:10 +00:00
|
|
|
bl X(checkasm_fail_func)
|
2015-12-30 21:46:06 +00:00
|
|
|
0:
|
2020-05-12 10:44:05 +00:00
|
|
|
pop {r0, r1}
|
2015-12-30 21:46:06 +00:00
|
|
|
.ifc \variant, vfp
|
2020-05-12 10:44:05 +00:00
|
|
|
pop {r2}
|
|
|
|
fmxr FPSCR, r2
|
|
|
|
vpop {d8-d15}
|
2015-12-30 21:46:06 +00:00
|
|
|
.endif
|
2020-05-12 10:44:05 +00:00
|
|
|
pop {r4-r11, pc}
|
2015-12-30 21:46:06 +00:00
|
|
|
endfunc
|
|
|
|
.endm
|
|
|
|
|
|
|
|
#if HAVE_VFP || HAVE_NEON
|
|
|
|
clobbercheck vfp
|
|
|
|
#endif
|
|
|
|
clobbercheck novfp
|