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__
,elfx32
93 %elifidn __OUTPUT_FORMAT__
,x64
100 ; Macro for the attribute to hide a global symbol for the target ABI.
101 ; This is only active if CHROMIUM is defined.
103 ; Chromium doesn't like exported global symbols due to symbol clashing with
104 ; plugins among other things.
106 ; Requires Chromium's patched copy of yasm:
107 ; http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
108 ; http://www.tortall.net/projects/yasm/ticket/236
111 %ifidn __OUTPUT_FORMAT__
,elf32
112 %define PRIVATE
:hidden
113 %elifidn __OUTPUT_FORMAT__
,elf64
114 %define PRIVATE
:hidden
115 %elifidn __OUTPUT_FORMAT__
,elfx32
116 %define PRIVATE
:hidden
117 %elifidn __OUTPUT_FORMAT__
,x64
120 %define PRIVATE
:private_extern
127 ; Return the address specification of the given argument
130 %define arg
(x
) [ebp+8+4*x
]
132 ; 64 bit ABI passes arguments in registers. This is a workaround to get up
133 ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
134 %ifidn __OUTPUT_FORMAT__
,x64
135 %define arg
(x
) [rbp
+16+8*x
]
137 %define arg
(x
) [rbp
-8-8*x
]
141 ; REG_SZ_BYTES, REG_SZ_BITS
144 %define REG_SZ_BYTES
4
145 %define REG_SZ_BITS
32
147 %define REG_SZ_BYTES
8
148 %define REG_SZ_BITS
64
152 ; ALIGN_STACK <alignment> <register>
153 ; This macro aligns the stack to the given alignment (in bytes). The stack
154 ; is left such that the previous value of the stack pointer is the first
155 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
156 ; This macro uses one temporary register, which is not preserved, and thus
157 ; must be specified as an argument.
161 lea rsp
, [rsp
- (%1 - REG_SZ_BYTES
)]
167 ; The Microsoft assembler tries to impose a certain amount of type safety in
168 ; its register usage. YASM doesn't recognize these directives, so we just
169 ; %define them away to maintain as much compatibility as possible with the
170 ; original inline assembler we're porting from.
180 %ifidn __OUTPUT_FORMAT__
,elf32
181 %define GET_GOT_SAVE_ARG
1
182 %define WRT_PLT wrt ..plt
184 extern _GLOBAL_OFFSET_TABLE_
191 add %1, _GLOBAL_OFFSET_TABLE_
+ $$
- %%sub_offset wrt ..gotpc
195 %define
GLOBAL(x
) x
+ %1 wrt ..gotoff
197 %define RESTORE_GOT
pop %1
199 %elifidn __OUTPUT_FORMAT__
,macho32
200 %define GET_GOT_SAVE_ARG
1
207 %define
GLOBAL(x
) x
+ %1 - %%get_got
209 %define RESTORE_GOT
pop %1
215 %ifidn __OUTPUT_FORMAT__
,macho32
216 %define HIDDEN_DATA
(x
) x:private_extern
218 %define HIDDEN_DATA
(x
) x
221 %define HIDDEN_DATA
(x
) x
226 %define
GLOBAL(x
) rel x
227 %ifidn __OUTPUT_FORMAT__
,elf64
228 %define WRT_PLT wrt ..plt
229 %define HIDDEN_DATA
(x
) x:data hidden
230 %elifidn __OUTPUT_FORMAT__
,elfx32
231 %define WRT_PLT wrt ..plt
232 %define HIDDEN_DATA
(x
) x:data hidden
234 %define HIDDEN_DATA
(x
) x
250 %macro SHADOW_ARGS_TO_STACK
1
252 %define UNSHADOW_ARGS
254 %ifidn __OUTPUT_FORMAT__
,x64
255 %macro SHADOW_ARGS_TO_STACK
1 ; argc
270 %macro SHADOW_ARGS_TO_STACK
1 ; argc
300 %define UNSHADOW_ARGS
mov rsp
, rbp
303 ; Win64 ABI requires that XMM6:XMM15 are callee saved
305 ; store registers 6-n on the stack
306 ; if u is specified, use unaligned movs.
307 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
308 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
309 ; but in some cases this is not done and unaligned movs must be used.
310 %ifidn __OUTPUT_FORMAT__
,x64
311 %macro SAVE_XMM
1-2 a
313 %error Only xmm registers
6-15 must be preserved
316 %define movxmm movdq
%+ %2
317 %assign xmm_stack_space
((last_xmm
- 5) * 16)
318 sub rsp
, xmm_stack_space
321 movxmm
[rsp
+ ((i
- 6) * 16)], xmm
%+ i
328 %error RESTORE_XMM must be paired with SAVE_XMM n
332 movxmm xmm
%+ i
, [rsp
+((i
- 6) * 16)]
335 add rsp
, xmm_stack_space
336 ; there are a couple functions which return from multiple places.
337 ; otherwise, we could uncomment these:
339 ; %undef xmm_stack_space
350 ; Name of the rodata section
352 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
354 %ifidn __OUTPUT_FORMAT__
,macho64
355 %define SECTION_RODATA
section .text
356 %elifidn __OUTPUT_FORMAT__
,macho32
357 %macro SECTION_RODATA
0
360 %elifidn __OUTPUT_FORMAT__
,aout
361 %define SECTION_RODATA
section .data
363 %define SECTION_RODATA
section .rodata
367 ; Tell GNU ld that we don't require an executable stack.
368 %ifidn __OUTPUT_FORMAT__
,elf32
369 section .note.GNU
-stack noalloc noexec nowrite progbits
371 %elifidn __OUTPUT_FORMAT__
,elf64
372 section .note.GNU
-stack noalloc noexec nowrite progbits
374 %elifidn __OUTPUT_FORMAT__
,elfx32
375 section .note.GNU
-stack noalloc noexec nowrite progbits