2 ; Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 ; This source code is subject to the terms of the BSD 2 Clause License and
5 ; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 ; was not distributed with this source code in the LICENSE file, you can
7 ; obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 ; Media Patent License 1.0 was not distributed with this source code in the
9 ; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
15 %include "aom_config.asm"
17 ; 32/64 bit compatibility macros
19 ; In general, we make the source use 64 bit syntax, then twiddle with it using
20 ; the preprocessor to get the 32 bit syntax on 32 bit platforms.
22 %ifidn __OUTPUT_FORMAT__
,elf32
23 %define ABI_IS_32BIT
1
24 %elifidn __OUTPUT_FORMAT__
,macho32
25 %define ABI_IS_32BIT
1
26 %elifidn __OUTPUT_FORMAT__
,win32
27 %define ABI_IS_32BIT
1
28 %elifidn __OUTPUT_FORMAT__
,aout
29 %define ABI_IS_32BIT
1
31 %define ABI_IS_32BIT
0
85 ; Set LIBAOM_YASM_WIN64 if output is Windows 64bit so the code will work if x64
86 ; or win64 is defined on the Yasm command line.
87 %ifidn __OUTPUT_FORMAT__
,win64
88 %define LIBAOM_YASM_WIN64
1
89 %elifidn __OUTPUT_FORMAT__
,x64
90 %define LIBAOM_YASM_WIN64
1
92 %define LIBAOM_YASM_WIN64
0
96 ; Return the proper symbol name for the target ABI.
98 ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
99 ; with C linkage be prefixed with an underscore.
101 %ifidn __OUTPUT_FORMAT__
,elf32
103 %elifidn __OUTPUT_FORMAT__
,elf64
105 %elifidn __OUTPUT_FORMAT__
,elfx32
107 %elif LIBAOM_YASM_WIN64
110 %define sym
(x
) _
%+ x
114 ; Macro for the attribute to hide a global symbol for the target ABI.
115 ; This is only active if CHROMIUM is defined.
117 ; Chromium doesn't like exported global symbols due to symbol clashing with
118 ; plugins among other things.
120 ; Requires Chromium's patched copy of yasm:
121 ; http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
122 ; http://www.tortall.net/projects/yasm/ticket/236
125 %ifidn __OUTPUT_FORMAT__
,elf32
126 %define PRIVATE
:hidden
127 %elifidn __OUTPUT_FORMAT__
,elf64
128 %define PRIVATE
:hidden
129 %elifidn __OUTPUT_FORMAT__
,elfx32
130 %define PRIVATE
:hidden
131 %elif LIBAOM_YASM_WIN64
134 %define PRIVATE
:private_extern
141 ; Return the address specification of the given argument
144 %define arg
(x
) [ebp+8+4*x
]
146 ; 64 bit ABI passes arguments in registers. This is a workaround to get up
147 ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
148 %if LIBAOM_YASM_WIN64
149 %define arg
(x
) [rbp
+16+8*x
]
151 %define arg
(x
) [rbp
-8-8*x
]
155 ; REG_SZ_BYTES, REG_SZ_BITS
158 %define REG_SZ_BYTES
4
159 %define REG_SZ_BITS
32
161 %define REG_SZ_BYTES
8
162 %define REG_SZ_BITS
64
166 ; ALIGN_STACK <alignment> <register>
167 ; This macro aligns the stack to the given alignment (in bytes). The stack
168 ; is left such that the previous value of the stack pointer is the first
169 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
170 ; This macro uses one temporary register, which is not preserved, and thus
171 ; must be specified as an argument.
175 lea rsp
, [rsp
- (%1 - REG_SZ_BYTES
)]
181 ; The Microsoft assembler tries to impose a certain amount of type safety in
182 ; its register usage. YASM doesn't recognize these directives, so we just
183 ; %define them away to maintain as much compatibility as possible with the
184 ; original inline assembler we're porting from.
194 %ifidn __OUTPUT_FORMAT__
,elf32
195 %define WRT_PLT wrt ..plt
197 extern _GLOBAL_OFFSET_TABLE_
204 add %1, _GLOBAL_OFFSET_TABLE_
+ $$
- %%sub_offset wrt ..gotpc
208 %define
GLOBAL(x
) x
+ %1 wrt ..gotoff
210 %define RESTORE_GOT
pop %1
212 %elifidn __OUTPUT_FORMAT__
,macho32
219 %define
GLOBAL(x
) x
+ %1 - %%get_got
221 %define RESTORE_GOT
pop %1
227 %ifidn __OUTPUT_FORMAT__
,macho32
228 %define HIDDEN_DATA
(x
) x:private_extern
230 %define HIDDEN_DATA
(x
) x
233 %define HIDDEN_DATA
(x
) x
238 %define
GLOBAL(x
) rel x
239 %ifidn __OUTPUT_FORMAT__
,elf64
240 %define WRT_PLT wrt ..plt
241 %define HIDDEN_DATA
(x
) x:data hidden
242 %elifidn __OUTPUT_FORMAT__
,elfx32
243 %define WRT_PLT wrt ..plt
244 %define HIDDEN_DATA
(x
) x:data hidden
245 %elifidn __OUTPUT_FORMAT__
,macho64
247 %define HIDDEN_DATA
(x
) x:private_extern
249 %define HIDDEN_DATA
(x
) x
252 %define HIDDEN_DATA
(x
) x
268 %macro SHADOW_ARGS_TO_STACK
1
270 %define UNSHADOW_ARGS
272 %if LIBAOM_YASM_WIN64
273 %macro SHADOW_ARGS_TO_STACK
1 ; argc
288 %macro SHADOW_ARGS_TO_STACK
1 ; argc
318 %define UNSHADOW_ARGS
mov rsp
, rbp
321 ; Win64 ABI requires that XMM6:XMM15 are callee saved
323 ; store registers 6-n on the stack
324 ; if u is specified, use unaligned movs.
325 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
326 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
327 ; but in some cases this is not done and unaligned movs must be used.
328 %if LIBAOM_YASM_WIN64
329 %macro SAVE_XMM
1-2 a
331 %error Only xmm registers
6-15 must be preserved
334 %define movxmm movdq
%+ %2
335 %assign xmm_stack_space
((last_xmm
- 5) * 16)
336 sub rsp
, xmm_stack_space
339 movxmm
[rsp
+ ((i
- 6) * 16)], xmm
%+ i
346 %error RESTORE_XMM must be paired with SAVE_XMM n
350 movxmm xmm
%+ i
, [rsp
+((i
- 6) * 16)]
353 add rsp
, xmm_stack_space
354 ; there are a couple functions which return from multiple places.
355 ; otherwise, we could uncomment these:
357 ; %undef xmm_stack_space
368 ; Name of the rodata section
370 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
372 %ifidn __OUTPUT_FORMAT__
,macho64
373 %define SECTION_RODATA
section .text
374 %elifidn __OUTPUT_FORMAT__
,macho32
375 %macro SECTION_RODATA
0
378 %elifidn __OUTPUT_FORMAT__
,aout
379 %define SECTION_RODATA
section .data
381 %define SECTION_RODATA
section .rodata
385 ; Tell GNU ld that we don't require an executable stack.
386 %ifidn __OUTPUT_FORMAT__
,elf32
387 section .note.GNU
-stack noalloc noexec nowrite progbits
389 %elifidn __OUTPUT_FORMAT__
,elf64
390 section .note.GNU
-stack noalloc noexec nowrite progbits
392 %elifidn __OUTPUT_FORMAT__
,elfx32
393 section .note.GNU
-stack noalloc noexec nowrite progbits