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 "config/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
95 ; Declare groups of platforms
96 %ifidn __OUTPUT_FORMAT__
,elf32
98 %elifidn __OUTPUT_FORMAT__
,elfx32
100 %elifidn __OUTPUT_FORMAT__
,elf64
106 %ifidn __OUTPUT_FORMAT__
,macho32
107 %define LIBAOM_MACHO
1
108 %elifidn __OUTPUT_FORMAT__
,macho64
109 %define LIBAOM_MACHO
1
111 %define LIBAOM_MACHO
0
115 ; Return the proper symbol name for the target ABI.
117 ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
118 ; with C linkage be prefixed with an underscore.
120 %if LIBAOM_ELF || LIBAOM_YASM_WIN64
124 %define sym
(x
) _
%+ x
128 ; Return a global declaration with the proper decoration for the target ABI.
130 ; When CHROMIUM is defined, include attributes to hide the symbol from the
133 ; Chromium doesn't like exported global symbols due to symbol clashing with
134 ; plugins among other things.
136 ; Requires Chromium's patched copy of yasm:
137 ; http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
138 ; http://www.tortall.net/projects/yasm/ticket/236
143 %if __NASM_VERSION_ID__
< 0x020e0000 ; 2.14
144 ; nasm < 2.14 does not support :private_extern directive
145 %fatal Must use nasm
2.14 or newer
150 %define globalsym
(x
) global sym
(x
) %+ :function hidden
152 %define globalsym
(x
) global sym
(x
) %+ :private_extern
155 %define globalsym
(x
) global sym
(x
)
158 %define globalsym
(x
) global sym
(x
)
162 ; Return the address specification of the given argument
165 %define arg
(x
) [ebp+8+4*x
]
167 ; 64 bit ABI passes arguments in registers. This is a workaround to get up
168 ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
169 %if LIBAOM_YASM_WIN64
170 %define arg
(x
) [rbp
+16+8*x
]
172 %define arg
(x
) [rbp
-8-8*x
]
176 ; REG_SZ_BYTES, REG_SZ_BITS
179 %define REG_SZ_BYTES
4
180 %define REG_SZ_BITS
32
182 %define REG_SZ_BYTES
8
183 %define REG_SZ_BITS
64
187 ; ALIGN_STACK <alignment> <register>
188 ; This macro aligns the stack to the given alignment (in bytes). The stack
189 ; is left such that the previous value of the stack pointer is the first
190 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
191 ; This macro uses one temporary register, which is not preserved, and thus
192 ; must be specified as an argument.
196 lea rsp
, [rsp
- (%1 - REG_SZ_BYTES
)]
202 ; The Microsoft assembler tries to impose a certain amount of type safety in
203 ; its register usage. YASM doesn't recognize these directives, so we just
204 ; %define them away to maintain as much compatibility as possible with the
205 ; original inline assembler we're porting from.
215 %ifidn __OUTPUT_FORMAT__
,elf32
216 %define WRT_PLT wrt ..plt
218 extern _GLOBAL_OFFSET_TABLE_
225 add %1, _GLOBAL_OFFSET_TABLE_
+ $$
- %%sub_offset wrt ..gotpc
229 %define
GLOBAL(x
) x
+ %1 wrt ..gotoff
231 %define RESTORE_GOT
pop %1
233 %elifidn __OUTPUT_FORMAT__
,macho32
240 %define
GLOBAL(x
) x
+ %1 - %%get_got
242 %define RESTORE_GOT
pop %1
248 %ifidn __OUTPUT_FORMAT__
,macho32
249 %define HIDDEN_DATA
(x
) x:private_extern
251 %define HIDDEN_DATA
(x
) x
254 %define HIDDEN_DATA
(x
) x
259 %define
GLOBAL(x
) rel x
260 %ifidn __OUTPUT_FORMAT__
,elf64
261 %define WRT_PLT wrt ..plt
262 %define HIDDEN_DATA
(x
) x:data hidden
263 %elifidn __OUTPUT_FORMAT__
,elfx32
264 %define WRT_PLT wrt ..plt
265 %define HIDDEN_DATA
(x
) x:data hidden
266 %elifidn __OUTPUT_FORMAT__
,macho64
268 %define HIDDEN_DATA
(x
) x:private_extern
270 %define HIDDEN_DATA
(x
) x
273 %define HIDDEN_DATA
(x
) x
289 %macro SHADOW_ARGS_TO_STACK
1
291 %define UNSHADOW_ARGS
293 %if LIBAOM_YASM_WIN64
294 %macro SHADOW_ARGS_TO_STACK
1 ; argc
309 %macro SHADOW_ARGS_TO_STACK
1 ; argc
339 %define UNSHADOW_ARGS
mov rsp
, rbp
342 ; Win64 ABI requires that XMM6:XMM15 are callee saved
344 ; store registers 6-n on the stack
345 ; if u is specified, use unaligned movs.
346 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
347 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
348 ; but in some cases this is not done and unaligned movs must be used.
349 %if LIBAOM_YASM_WIN64
350 %macro SAVE_XMM
1-2 a
352 %error Only xmm registers
6-15 must be preserved
355 %define movxmm movdq
%+ %2
356 %assign xmm_stack_space
((last_xmm
- 5) * 16)
357 sub rsp
, xmm_stack_space
360 movxmm
[rsp
+ ((i
- 6) * 16)], xmm
%+ i
367 %error RESTORE_XMM must be paired with SAVE_XMM n
371 movxmm xmm
%+ i
, [rsp
+((i
- 6) * 16)]
374 add rsp
, xmm_stack_space
375 ; there are a couple functions which return from multiple places.
376 ; otherwise, we could uncomment these:
378 ; %undef xmm_stack_space
389 ; Name of the rodata section
391 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
393 %ifidn __OUTPUT_FORMAT__
,macho64
394 %define SECTION_RODATA
section .text
395 %elifidn __OUTPUT_FORMAT__
,macho32
396 %macro SECTION_RODATA
0
399 %elifidn __OUTPUT_FORMAT__
,aout
400 %define SECTION_RODATA
section .data
402 %define SECTION_RODATA
section .rodata
406 ; Tell GNU ld that we don't require an executable stack.
407 %ifidn __OUTPUT_FORMAT__
,elf32
408 section .note.GNU
-stack noalloc noexec nowrite progbits
410 %elifidn __OUTPUT_FORMAT__
,elf64
411 section .note.GNU
-stack noalloc noexec nowrite progbits
413 %elifidn __OUTPUT_FORMAT__
,elfx32
414 section .note.GNU
-stack noalloc noexec nowrite progbits