]> git.sesse.net Git - x264/blob - common/x86/x86inc-32.asm
Update file headers throughout x264
[x264] / common / x86 / x86inc-32.asm
1 ;*****************************************************************************
2 ;* x86inc-32.asm: h264 encoder library
3 ;*****************************************************************************
4 ;* Copyright (C) 2006-2008 x264 project
5 ;*
6 ;* Authors: Sam Hocevar <sam@zoy.org>
7 ;*          Loren Merritt <lorenm@u.washington.edu>
8 ;*
9 ;* This program is free software; you can redistribute it and/or modify
10 ;* it under the terms of the GNU General Public License as published by
11 ;* the Free Software Foundation; either version 2 of the License, or
12 ;* (at your option) any later version.
13 ;*
14 ;* This program is distributed in the hope that it will be useful,
15 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;* GNU General Public License for more details.
18 ;*
19 ;* You should have received a copy of the GNU General Public License
20 ;* along with this program; if not, write to the Free Software
21 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
22 ;*****************************************************************************
23
24 BITS 32
25
26 ; Name of the .rodata section. On OS X we cannot use .rodata because NASM
27 ; is unable to compute address offsets outside of .text so we use the .text
28 ; section instead until NASM is fixed.
29 %macro SECTION_RODATA 0
30     %ifidn __OUTPUT_FORMAT__,macho
31         SECTION .text align=16
32         fakegot:
33     %else
34         SECTION .rodata align=16
35     %endif
36 %endmacro
37
38 ; PIC support macros. All these macros are totally harmless when __PIC__ is
39 ; not defined but can ruin everything if misused in PIC mode. On x86, shared
40 ; objects cannot directly access global variables by address, they need to
41 ; go through the GOT (global offset table). Most OSes do not care about it
42 ; and let you load non-shared .so objects (Linux, Win32...). However, OS X
43 ; requires PIC code in its .dylib objects.
44 ;
45 ; - GLOBAL should be used as a suffix for global addressing, eg.
46 ;     picgetgot ebx
47 ;     mov eax, [foo GLOBAL]
48 ;   instead of
49 ;     mov eax, [foo]
50 ;
51 ; - picgetgot computes the GOT address into the given register in PIC
52 ;   mode, otherwise does nothing. You need to do this before using GLOBAL.
53 ;   Before in both execution order and compiled code order (so GLOBAL knows
54 ;   which register the GOT is in).
55 ;
56 ; - picpush and picpop respectively push and pop the given register
57 ;   in PIC mode, otherwise do nothing. You should always use them around
58 ;   picgetgot except when sure that the register is no longer used and is
59 ;   being restored later by other means.
60 ;
61 ; - picesp is defined to compensate the changing of esp when pushing
62 ;   a register into the stack, eg.
63 ;     mov eax, [esp + 8]
64 ;     pushpic  ebx
65 ;     mov eax, [picesp + 12]
66 ;   instead of
67 ;     mov eax, [esp + 8]
68 ;     pushpic  ebx
69 ;     mov eax, [esp + 12]
70 ;
71 %ifdef __PIC__
72     %define PIC32
73     %ifidn __OUTPUT_FORMAT__,macho
74         ; There is no real global offset table on OS X, but we still
75         ; need to reference our variables by offset.
76         %define GOT_reg(x) - fakegot + x
77         %macro picgetgot 1
78             call %%getgot 
79           %%getgot: 
80             pop %1 
81             add %1, $$ - %%getgot
82             %undef GLOBAL
83             %define GLOBAL GOT_reg(%1)
84         %endmacro
85     %else
86         %ifidn __OUTPUT_FORMAT__,elf
87             %define GOT _GLOBAL_OFFSET_TABLE_
88         %else ; for a.out
89             %define GOT __GLOBAL_OFFSET_TABLE_
90         %endif
91         extern GOT
92         %define GOT_reg(x) + x wrt ..gotoff
93         %macro picgetgot 1
94             call %%getgot 
95           %%getgot: 
96             pop %1 
97             add %1, GOT + $$ - %%getgot wrt ..gotpc 
98             %undef GLOBAL
99             %define GLOBAL GOT_reg(%1)
100         %endmacro
101     %endif
102     %macro picpush 1
103         push %1
104     %endmacro
105     %macro picpop 1
106         pop %1
107     %endmacro
108     %define picesp esp+4
109 %else
110     %define GLOBAL
111     %macro picgetgot 1
112     %endmacro
113     %macro picpush 1
114     %endmacro
115     %macro picpop 1
116     %endmacro
117     %define picesp esp
118 %endif
119