Add packaging files for Tizen
[profile/ivi/libvpx.git] / vpx_ports / x86_abi_support.asm
1 ;
2 ;  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 ;
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.
9 ;
10
11
12 %include "vpx_config.asm"
13
14 ; 32/64 bit compatibility macros
15 ;
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.
18 ;
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
27 %else
28 %define ABI_IS_32BIT 0
29 %endif
30
31 %if ABI_IS_32BIT
32 %define rax eax
33 %define rbx ebx
34 %define rcx ecx
35 %define rdx edx
36 %define rsi esi
37 %define rdi edi
38 %define rsp esp
39 %define rbp ebp
40 %define movsxd mov
41 %macro movq 2
42   %ifidn %1,eax
43     movd %1,%2
44   %elifidn %2,eax
45     movd %1,%2
46   %elifidn %1,ebx
47     movd %1,%2
48   %elifidn %2,ebx
49     movd %1,%2
50   %elifidn %1,ecx
51     movd %1,%2
52   %elifidn %2,ecx
53     movd %1,%2
54   %elifidn %1,edx
55     movd %1,%2
56   %elifidn %2,edx
57     movd %1,%2
58   %elifidn %1,esi
59     movd %1,%2
60   %elifidn %2,esi
61     movd %1,%2
62   %elifidn %1,edi
63     movd %1,%2
64   %elifidn %2,edi
65     movd %1,%2
66   %elifidn %1,esp
67     movd %1,%2
68   %elifidn %2,esp
69     movd %1,%2
70   %elifidn %1,ebp
71     movd %1,%2
72   %elifidn %2,ebp
73     movd %1,%2
74   %else
75     movq %1,%2
76   %endif
77 %endmacro
78 %endif
79
80
81 ; sym()
82 ; Return the proper symbol name for the target ABI.
83 ;
84 ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
85 ; with C linkage be prefixed with an underscore.
86 ;
87 %ifidn   __OUTPUT_FORMAT__,elf32
88 %define sym(x) x
89 %elifidn __OUTPUT_FORMAT__,elf64
90 %define sym(x) x
91 %elifidn __OUTPUT_FORMAT__,x64
92 %define sym(x) x
93 %else
94 %define sym(x) _ %+ x
95 %endif
96
97 ;  PRIVATE
98 ;  Macro for the attribute to hide a global symbol for the target ABI.
99 ;  This is only active if CHROMIUM is defined.
100 ;
101 ;  Chromium doesn't like exported global symbols due to symbol clashing with
102 ;  plugins among other things.
103 ;
104 ;  Requires Chromium's patched copy of yasm:
105 ;    http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
106 ;    http://www.tortall.net/projects/yasm/ticket/236
107 ;
108 %ifdef CHROMIUM
109   %ifidn   __OUTPUT_FORMAT__,elf32
110     %define PRIVATE :hidden
111   %elifidn __OUTPUT_FORMAT__,elf64
112     %define PRIVATE :hidden
113   %elifidn __OUTPUT_FORMAT__,x64
114     %define PRIVATE
115   %else
116     %define PRIVATE :private_extern
117   %endif
118 %else
119   %define PRIVATE
120 %endif
121
122 ; arg()
123 ; Return the address specification of the given argument
124 ;
125 %if ABI_IS_32BIT
126   %define arg(x) [ebp+8+4*x]
127 %else
128   ; 64 bit ABI passes arguments in registers. This is a workaround to get up
129   ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
130   %ifidn __OUTPUT_FORMAT__,x64
131     %define arg(x) [rbp+16+8*x]
132   %else
133     %define arg(x) [rbp-8-8*x]
134   %endif
135 %endif
136
137 ; REG_SZ_BYTES, REG_SZ_BITS
138 ; Size of a register
139 %if ABI_IS_32BIT
140 %define REG_SZ_BYTES 4
141 %define REG_SZ_BITS  32
142 %else
143 %define REG_SZ_BYTES 8
144 %define REG_SZ_BITS  64
145 %endif
146
147
148 ; ALIGN_STACK <alignment> <register>
149 ; This macro aligns the stack to the given alignment (in bytes). The stack
150 ; is left such that the previous value of the stack pointer is the first
151 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
152 ; This macro uses one temporary register, which is not preserved, and thus
153 ; must be specified as an argument.
154 %macro ALIGN_STACK 2
155     mov         %2, rsp
156     and         rsp, -%1
157     lea         rsp, [rsp - (%1 - REG_SZ_BYTES)]
158     push        %2
159 %endmacro
160
161
162 ;
163 ; The Microsoft assembler tries to impose a certain amount of type safety in
164 ; its register usage. YASM doesn't recognize these directives, so we just
165 ; %define them away to maintain as much compatibility as possible with the
166 ; original inline assembler we're porting from.
167 ;
168 %idefine PTR
169 %idefine XMMWORD
170 %idefine MMWORD
171
172 ; PIC macros
173 ;
174 %if ABI_IS_32BIT
175   %if CONFIG_PIC=1
176   %ifidn __OUTPUT_FORMAT__,elf32
177     %define GET_GOT_SAVE_ARG 1
178     %define WRT_PLT wrt ..plt
179     %macro GET_GOT 1
180       extern _GLOBAL_OFFSET_TABLE_
181       push %1
182       call %%get_got
183       %%sub_offset:
184       jmp %%exitGG
185       %%get_got:
186       mov %1, [esp]
187       add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc
188       ret
189       %%exitGG:
190       %undef GLOBAL
191       %define GLOBAL(x) x + %1 wrt ..gotoff
192       %undef RESTORE_GOT
193       %define RESTORE_GOT pop %1
194     %endmacro
195   %elifidn __OUTPUT_FORMAT__,macho32
196     %define GET_GOT_SAVE_ARG 1
197     %macro GET_GOT 1
198       push %1
199       call %%get_got
200       %%get_got:
201       pop  %1
202       %undef GLOBAL
203       %define GLOBAL(x) x + %1 - %%get_got
204       %undef RESTORE_GOT
205       %define RESTORE_GOT pop %1
206     %endmacro
207   %endif
208   %endif
209
210   %ifdef CHROMIUM
211     %ifidn __OUTPUT_FORMAT__,macho32
212       %define HIDDEN_DATA(x) x:private_extern
213     %else
214       %define HIDDEN_DATA(x) x
215     %endif
216   %else
217     %define HIDDEN_DATA(x) x
218   %endif
219 %else
220   %macro GET_GOT 1
221   %endmacro
222   %define GLOBAL(x) rel x
223   %ifidn __OUTPUT_FORMAT__,elf64
224     %define WRT_PLT wrt ..plt
225     %define HIDDEN_DATA(x) x:data hidden
226   %else
227     %define HIDDEN_DATA(x) x
228   %endif
229 %endif
230 %ifnmacro GET_GOT
231     %macro GET_GOT 1
232     %endmacro
233     %define GLOBAL(x) x
234 %endif
235 %ifndef RESTORE_GOT
236 %define RESTORE_GOT
237 %endif
238 %ifndef WRT_PLT
239 %define WRT_PLT
240 %endif
241
242 %if ABI_IS_32BIT
243   %macro SHADOW_ARGS_TO_STACK 1
244   %endm
245   %define UNSHADOW_ARGS
246 %else
247 %ifidn __OUTPUT_FORMAT__,x64
248   %macro SHADOW_ARGS_TO_STACK 1 ; argc
249     %if %1 > 0
250         mov arg(0),rcx
251     %endif
252     %if %1 > 1
253         mov arg(1),rdx
254     %endif
255     %if %1 > 2
256         mov arg(2),r8
257     %endif
258     %if %1 > 3
259         mov arg(3),r9
260     %endif
261   %endm
262 %else
263   %macro SHADOW_ARGS_TO_STACK 1 ; argc
264     %if %1 > 0
265         push rdi
266     %endif
267     %if %1 > 1
268         push rsi
269     %endif
270     %if %1 > 2
271         push rdx
272     %endif
273     %if %1 > 3
274         push rcx
275     %endif
276     %if %1 > 4
277         push r8
278     %endif
279     %if %1 > 5
280         push r9
281     %endif
282     %if %1 > 6
283       %assign i %1-6
284       %assign off 16
285       %rep i
286         mov rax,[rbp+off]
287         push rax
288         %assign off off+8
289       %endrep
290     %endif
291   %endm
292 %endif
293   %define UNSHADOW_ARGS mov rsp, rbp
294 %endif
295
296 ; Win64 ABI requires that XMM6:XMM15 are callee saved
297 ; SAVE_XMM n, [u]
298 ; store registers 6-n on the stack
299 ; if u is specified, use unaligned movs.
300 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
301 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
302 ; but in some cases this is not done and unaligned movs must be used.
303 %ifidn __OUTPUT_FORMAT__,x64
304 %macro SAVE_XMM 1-2 a
305   %if %1 < 6
306     %error Only xmm registers 6-15 must be preserved
307   %else
308     %assign last_xmm %1
309     %define movxmm movdq %+ %2
310     %assign xmm_stack_space ((last_xmm - 5) * 16)
311     sub rsp, xmm_stack_space
312     %assign i 6
313     %rep (last_xmm - 5)
314       movxmm [rsp + ((i - 6) * 16)], xmm %+ i
315       %assign i i+1
316     %endrep
317   %endif
318 %endmacro
319 %macro RESTORE_XMM 0
320   %ifndef last_xmm
321     %error RESTORE_XMM must be paired with SAVE_XMM n
322   %else
323     %assign i last_xmm
324     %rep (last_xmm - 5)
325       movxmm xmm %+ i, [rsp +((i - 6) * 16)]
326       %assign i i-1
327     %endrep
328     add rsp, xmm_stack_space
329     ; there are a couple functions which return from multiple places.
330     ; otherwise, we could uncomment these:
331     ; %undef last_xmm
332     ; %undef xmm_stack_space
333     ; %undef movxmm
334   %endif
335 %endmacro
336 %else
337 %macro SAVE_XMM 1-2
338 %endmacro
339 %macro RESTORE_XMM 0
340 %endmacro
341 %endif
342
343 ; Name of the rodata section
344 ;
345 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
346 ;
347 %ifidn __OUTPUT_FORMAT__,macho64
348 %define SECTION_RODATA section .text
349 %elifidn __OUTPUT_FORMAT__,macho32
350 %macro SECTION_RODATA 0
351 section .text
352 %endmacro
353 %elifidn __OUTPUT_FORMAT__,aout
354 %define SECTION_RODATA section .data
355 %else
356 %define SECTION_RODATA section .rodata
357 %endif
358
359
360 ; Tell GNU ld that we don't require an executable stack.
361 %ifidn __OUTPUT_FORMAT__,elf32
362 section .note.GNU-stack noalloc noexec nowrite progbits
363 section .text
364 %elifidn __OUTPUT_FORMAT__,elf64
365 section .note.GNU-stack noalloc noexec nowrite progbits
366 section .text
367 %endif
368