]> git.sesse.net Git - x264/blob - common/i386/i386inc.asm
deda859188fcf5a6895cf14fc125b2f15fa68829
[x264] / common / i386 / i386inc.asm
1 ;*****************************************************************************
2 ;* i386inc.asm: h264 encoder library
3 ;*****************************************************************************
4 ;* Copyright (C) 2006 x264 project
5 ;*
6 ;* Author: Sam Hocevar <sam@zoy.org>
7 ;*
8 ;* This program is free software; you can redistribute it and/or modify
9 ;* it under the terms of the GNU General Public License as published by
10 ;* the Free Software Foundation; either version 2 of the License, or
11 ;* (at your option) any later version.
12 ;*
13 ;* This program is distributed in the hope that it will be useful,
14 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;* GNU General Public License for more details.
17 ;*
18 ;* You should have received a copy of the GNU General Public License
19 ;* along with this program; if not, write to the Free Software
20 ;* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21 ;*****************************************************************************
22
23 BITS 32
24
25 ;=============================================================================
26 ; Macros and other preprocessor constants
27 ;=============================================================================
28
29 ; Symbol prefix for C linkage
30 %macro cglobal 1
31     %ifdef PREFIX
32         global _%1
33         %define %1 _%1
34     %else
35         global %1
36     %endif
37     align 16
38     %1:
39 %endmacro
40
41 ; Name of the .rodata section. On OS X we cannot use .rodata because NASM
42 ; is unable to compute address offsets outside of .text so we use the .text
43 ; section instead until NASM is fixed.
44 %macro SECTION_RODATA 0
45     %ifidn __OUTPUT_FORMAT__,macho
46         SECTION .text align=16
47         fakegot:
48     %else
49         SECTION .rodata data align=16
50     %endif
51 %endmacro
52
53 ; PIC support macros. All these macros are totally harmless when __PIC__ is
54 ; not defined but can ruin everything if misused in PIC mode. On x86, shared
55 ; objects cannot directly access global variables by address, they need to
56 ; go through the GOT (global offset table). Most OSes do not care about it
57 ; and let you load non-shared .so objects (Linux, Win32...). However, OS X
58 ; requires PIC code in its .dylib objects.
59 ;
60 ; - GOT_* should be used as a suffix for global addressing, eg.
61 ;     picgetgot ebx
62 ;     mov eax, [foo GOT_ebx]
63 ;   instead of
64 ;     mov eax, [foo]
65 ;
66 ; - picgetgot computes the GOT address into the given register in PIC
67 ;   mode, otherwise does nothing. You need to do this before using GOT_*.
68 ;
69 ; - picpush and picpop respectively push and pop the given register
70 ;   in PIC mode, otherwise do nothing. You should always use them around
71 ;   picgetgot except when sure that the register is no longer used and is
72 ;   being restored later by other means.
73 ;
74 ; - picesp is defined to compensate the changing of esp when pushing
75 ;   a register into the stack, eg.
76 ;     mov eax, [esp + 8]
77 ;     pushpic  ebx
78 ;     mov eax, [picesp + 12]
79 ;   instead of
80 ;     mov eax, [esp + 8]
81 ;     pushpic  ebx
82 ;     mov eax, [esp + 12]
83 ;
84 %ifdef __PIC__
85     %ifidn __OUTPUT_FORMAT__,macho
86         ; There is no real global offset table on OS X, but we still
87         ; need to reference our variables by offset.
88         %define GOT_eax - fakegot + eax
89         %define GOT_ebx - fakegot + ebx
90         %define GOT_ecx - fakegot + ecx
91         %define GOT_edx - fakegot + edx
92         %macro picgetgot 1
93             call %%getgot 
94           %%getgot: 
95             pop %1 
96             add %1, $$ - %%getgot
97         %endmacro
98     %else
99         %ifidn __OUTPUT_FORMAT__,elf
100             %define GOT _GLOBAL_OFFSET_TABLE_
101         %else ; for a.out
102             %define GOT __GLOBAL_OFFSET_TABLE_
103         %endif
104         extern GOT
105         %define GOT_eax + eax wrt ..gotoff
106         %define GOT_ebx + ebx wrt ..gotoff
107         %define GOT_ecx + ecx wrt ..gotoff
108         %define GOT_edx + edx wrt ..gotoff
109         %macro picgetgot 1
110             call %%getgot 
111           %%getgot: 
112             pop %1 
113             add %1, GOT + $$ - %%getgot wrt ..gotpc 
114         %endmacro
115     %endif
116     %macro picpush 1
117         push %1
118     %endmacro
119     %macro picpop 1
120         pop %1
121     %endmacro
122     %define picesp esp+4
123 %else
124     %define GOT_eax
125     %define GOT_ebx
126     %define GOT_ecx
127     %define GOT_edx
128     %macro picgetgot 1
129     %endmacro
130     %macro picpush 1
131     %endmacro
132     %macro picpop 1
133     %endmacro
134     %define picesp esp
135 %endif
136
137 %assign FENC_STRIDE 16
138 %assign FDEC_STRIDE 32
139
140 ; This is needed for ELF, otherwise the GNU linker assumes the stack is
141 ; executable by default.
142 %ifidn __OUTPUT_FORMAT__,elf
143 SECTION .note.GNU-stack noalloc noexec nowrite progbits
144 %endif
145