2 ; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 ; Use of this source code is governed by a BSD-style license
5 ; that can be found in the LICENSE file in the root of the source
6 ; tree. An additional intellectual property rights grant can be found
7 ; in the file PATENTS. All contributing project authors may
8 ; be found in the AUTHORS file in the root of the source tree.
12 %include "vpx_config.asm"
14 ; 32/64 bit compatibility macros
16 ; In general, we make the source use 64 bit syntax, then twiddle with it using
17 ; the preprocessor to get the 32 bit syntax on 32 bit platforms.
19 %ifidn __OUTPUT_FORMAT__,elf32
20 %define ABI_IS_32BIT 1
21 %elifidn __OUTPUT_FORMAT__,macho32
22 %define ABI_IS_32BIT 1
23 %elifidn __OUTPUT_FORMAT__,win32
24 %define ABI_IS_32BIT 1
25 %elifidn __OUTPUT_FORMAT__,aout
26 %define ABI_IS_32BIT 1
28 %define ABI_IS_32BIT 0
82 ; Return the proper symbol name for the target ABI.
84 ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
85 ; with C linkage be prefixed with an underscore.
87 %ifidn __OUTPUT_FORMAT__,elf32
89 %elifidn __OUTPUT_FORMAT__,elf64
91 %elifidn __OUTPUT_FORMAT__,x64
98 ; Return the address specification of the given argument
101 %define arg(x) [ebp+8+4*x]
103 ; 64 bit ABI passes arguments in registers. This is a workaround to get up
104 ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
105 %ifidn __OUTPUT_FORMAT__,x64
106 %define arg(x) [rbp+16+8*x]
108 %define arg(x) [rbp-8-8*x]
112 ; REG_SZ_BYTES, REG_SZ_BITS
115 %define REG_SZ_BYTES 4
116 %define REG_SZ_BITS 32
118 %define REG_SZ_BYTES 8
119 %define REG_SZ_BITS 64
123 ; ALIGN_STACK <alignment> <register>
124 ; This macro aligns the stack to the given alignment (in bytes). The stack
125 ; is left such that the previous value of the stack pointer is the first
126 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
127 ; This macro uses one temporary register, which is not preserved, and thus
128 ; must be specified as an argument.
132 lea rsp, [rsp - (%1 - REG_SZ_BYTES)]
138 ; The Microsoft assembler tries to impose a certain amount of type safety in
139 ; its register usage. YASM doesn't recognize these directives, so we just
140 ; %define them away to maintain as much compatibility as possible with the
141 ; original inline assembler we're porting from.
151 %ifidn __OUTPUT_FORMAT__,elf32
152 %define GET_GOT_SAVE_ARG 1
153 %define WRT_PLT wrt ..plt
155 extern _GLOBAL_OFFSET_TABLE_
162 add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc
166 %define GLOBAL(x) x + %1 wrt ..gotoff
168 %define RESTORE_GOT pop %1
170 %elifidn __OUTPUT_FORMAT__,macho32
171 %define GET_GOT_SAVE_ARG 1
178 %define GLOBAL(x) x + %1 - %%get_got
180 %define RESTORE_GOT pop %1
184 %define HIDDEN_DATA(x) x
188 %define GLOBAL(x) rel x
189 %ifidn __OUTPUT_FORMAT__,elf64
190 %define WRT_PLT wrt ..plt
191 %define HIDDEN_DATA(x) x:data hidden
193 %define HIDDEN_DATA(x) x
209 %macro SHADOW_ARGS_TO_STACK 1
211 %define UNSHADOW_ARGS
213 %ifidn __OUTPUT_FORMAT__,x64
214 %macro SHADOW_ARGS_TO_STACK 1 ; argc
229 %macro SHADOW_ARGS_TO_STACK 1 ; argc
259 %define UNSHADOW_ARGS mov rsp, rbp
262 ; Win64 ABI requires that XMM6:XMM15 are callee saved
264 ; store registers 6-n on the stack
265 ; if u is specified, use unaligned movs.
266 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
267 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
268 ; but in some cases this is not done and unaligned movs must be used.
269 %ifidn __OUTPUT_FORMAT__,x64
270 %macro SAVE_XMM 1-2 a
272 %error Only xmm registers 6-15 must be preserved
275 %define movxmm movdq %+ %2
276 %assign xmm_stack_space ((last_xmm - 5) * 16)
277 sub rsp, xmm_stack_space
280 movxmm [rsp + ((i - 6) * 16)], xmm %+ i
287 %error RESTORE_XMM must be paired with SAVE_XMM n
291 movxmm xmm %+ i, [rsp +((i - 6) * 16)]
294 add rsp, xmm_stack_space
295 ; there are a couple functions which return from multiple places.
296 ; otherwise, we could uncomment these:
298 ; %undef xmm_stack_space
309 ; Name of the rodata section
311 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
313 %ifidn __OUTPUT_FORMAT__,macho64
314 %define SECTION_RODATA section .text
315 %elifidn __OUTPUT_FORMAT__,macho32
316 %macro SECTION_RODATA 0
319 %elifidn __OUTPUT_FORMAT__,aout
320 %define SECTION_RODATA section .data
322 %define SECTION_RODATA section .rodata
326 ; Tell GNU ld that we don't require an executable stack.
327 %ifidn __OUTPUT_FORMAT__,elf32
328 section .note.GNU-stack noalloc noexec nowrite progbits
330 %elifidn __OUTPUT_FORMAT__,elf64
331 section .note.GNU-stack noalloc noexec nowrite progbits