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 ; Set LIBVPX_YASM_WIN64 if output is Windows 64bit so the code will work if x64
83 ; or win64 is defined on the Yasm command line.
84 %ifidn __OUTPUT_FORMAT__,win64
85 %define LIBVPX_YASM_WIN64 1
86 %elifidn __OUTPUT_FORMAT__,x64
87 %define LIBVPX_YASM_WIN64 1
89 %define LIBVPX_YASM_WIN64 0
93 ; Return the proper symbol name for the target ABI.
95 ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
96 ; with C linkage be prefixed with an underscore.
98 %ifidn __OUTPUT_FORMAT__,elf32
100 %elifidn __OUTPUT_FORMAT__,elf64
102 %elifidn __OUTPUT_FORMAT__,elfx32
104 %elif LIBVPX_YASM_WIN64
107 %define sym(x) _ %+ x
111 ; Macro for the attribute to hide a global symbol for the target ABI.
112 ; This is only active if CHROMIUM is defined.
114 ; Chromium doesn't like exported global symbols due to symbol clashing with
115 ; plugins among other things.
117 ; Requires Chromium's patched copy of yasm:
118 ; http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
119 ; http://www.tortall.net/projects/yasm/ticket/236
122 %ifidn __OUTPUT_FORMAT__,elf32
123 %define PRIVATE :hidden
124 %elifidn __OUTPUT_FORMAT__,elf64
125 %define PRIVATE :hidden
126 %elifidn __OUTPUT_FORMAT__,elfx32
127 %define PRIVATE :hidden
128 %elif LIBVPX_YASM_WIN64
131 %define PRIVATE :private_extern
138 ; Return the address specification of the given argument
141 %define arg(x) [ebp+8+4*x]
143 ; 64 bit ABI passes arguments in registers. This is a workaround to get up
144 ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
145 %if LIBVPX_YASM_WIN64
146 %define arg(x) [rbp+16+8*x]
148 %define arg(x) [rbp-8-8*x]
152 ; REG_SZ_BYTES, REG_SZ_BITS
155 %define REG_SZ_BYTES 4
156 %define REG_SZ_BITS 32
158 %define REG_SZ_BYTES 8
159 %define REG_SZ_BITS 64
163 ; ALIGN_STACK <alignment> <register>
164 ; This macro aligns the stack to the given alignment (in bytes). The stack
165 ; is left such that the previous value of the stack pointer is the first
166 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
167 ; This macro uses one temporary register, which is not preserved, and thus
168 ; must be specified as an argument.
172 lea rsp, [rsp - (%1 - REG_SZ_BYTES)]
178 ; The Microsoft assembler tries to impose a certain amount of type safety in
179 ; its register usage. YASM doesn't recognize these directives, so we just
180 ; %define them away to maintain as much compatibility as possible with the
181 ; original inline assembler we're porting from.
191 %ifidn __OUTPUT_FORMAT__,elf32
192 %define GET_GOT_SAVE_ARG 1
193 %define WRT_PLT wrt ..plt
195 extern _GLOBAL_OFFSET_TABLE_
202 add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc
206 %define GLOBAL(x) x + %1 wrt ..gotoff
208 %define RESTORE_GOT pop %1
210 %elifidn __OUTPUT_FORMAT__,macho32
211 %define GET_GOT_SAVE_ARG 1
218 %define GLOBAL(x) x + %1 - %%get_got
220 %define RESTORE_GOT pop %1
226 %ifidn __OUTPUT_FORMAT__,macho32
227 %define HIDDEN_DATA(x) x:private_extern
229 %define HIDDEN_DATA(x) x
232 %define HIDDEN_DATA(x) x
237 %define GLOBAL(x) rel x
238 %ifidn __OUTPUT_FORMAT__,elf64
239 %define WRT_PLT wrt ..plt
240 %define HIDDEN_DATA(x) x:data hidden
241 %elifidn __OUTPUT_FORMAT__,elfx32
242 %define WRT_PLT wrt ..plt
243 %define HIDDEN_DATA(x) x:data hidden
244 %elifidn __OUTPUT_FORMAT__,macho64
246 %define HIDDEN_DATA(x) x:private_extern
248 %define HIDDEN_DATA(x) x
251 %define HIDDEN_DATA(x) x
267 %macro SHADOW_ARGS_TO_STACK 1
269 %define UNSHADOW_ARGS
271 %if LIBVPX_YASM_WIN64
272 %macro SHADOW_ARGS_TO_STACK 1 ; argc
287 %macro SHADOW_ARGS_TO_STACK 1 ; argc
317 %define UNSHADOW_ARGS mov rsp, rbp
320 ; Win64 ABI requires that XMM6:XMM15 are callee saved
322 ; store registers 6-n on the stack
323 ; if u is specified, use unaligned movs.
324 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
325 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
326 ; but in some cases this is not done and unaligned movs must be used.
327 %if LIBVPX_YASM_WIN64
328 %macro SAVE_XMM 1-2 a
330 %error Only xmm registers 6-15 must be preserved
333 %define movxmm movdq %+ %2
334 %assign xmm_stack_space ((last_xmm - 5) * 16)
335 sub rsp, xmm_stack_space
338 movxmm [rsp + ((i - 6) * 16)], xmm %+ i
345 %error RESTORE_XMM must be paired with SAVE_XMM n
349 movxmm xmm %+ i, [rsp +((i - 6) * 16)]
352 add rsp, xmm_stack_space
353 ; there are a couple functions which return from multiple places.
354 ; otherwise, we could uncomment these:
356 ; %undef xmm_stack_space
367 ; Name of the rodata section
369 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
371 %ifidn __OUTPUT_FORMAT__,macho64
372 %define SECTION_RODATA section .text
373 %elifidn __OUTPUT_FORMAT__,macho32
374 %macro SECTION_RODATA 0
377 %elifidn __OUTPUT_FORMAT__,aout
378 %define SECTION_RODATA section .data
380 %define SECTION_RODATA section .rodata
384 ; Tell GNU ld that we don't require an executable stack.
385 %ifidn __OUTPUT_FORMAT__,elf32
386 section .note.GNU-stack noalloc noexec nowrite progbits
388 %elifidn __OUTPUT_FORMAT__,elf64
389 section .note.GNU-stack noalloc noexec nowrite progbits
391 %elifidn __OUTPUT_FORMAT__,elfx32
392 section .note.GNU-stack noalloc noexec nowrite progbits