nv10 has alpha color mask
[mesa.git] / src / mesa / glapi / gl_x86_asm.py
1 #!/usr/bin/env python
2
3 # (C) Copyright IBM Corporation 2004, 2005
4 # All Rights Reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
15 # Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24 #
25 # Authors:
26 # Ian Romanick <idr@us.ibm.com>
27
28 import license
29 import gl_XML, glX_XML
30 import sys, getopt
31
32 class PrintGenericStubs(gl_XML.gl_print_base):
33
34 def __init__(self):
35 gl_XML.gl_print_base.__init__(self)
36
37 self.name = "gl_x86_asm.py (from Mesa)"
38 self.license = license.bsd_license_template % ( \
39 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
40 (C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM")
41 return
42
43
44 def get_stack_size(self, f):
45 size = 0
46 for p in f.parameterIterator():
47 size += p.get_stack_size()
48
49 return size
50
51
52 def printRealHeader(self):
53 print '#include "assyntax.h"'
54 print '#include "glapioffsets.h"'
55 print ''
56 print '#if defined(STDCALL_API)'
57 print '# if defined(USE_MGL_NAMESPACE)'
58 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
59 print '# else'
60 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
61 print '# endif'
62 print '#else'
63 print '# if defined(USE_MGL_NAMESPACE)'
64 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
65 print '# define _glapi_Dispatch _mglapi_Dispatch'
66 print '# else'
67 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
68 print '# endif'
69 print '#endif'
70 print ''
71 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
72 print ''
73 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
74 print '#define GLOBL_FN(x) GLOBL x ; .type x, function'
75 print '#else'
76 print '#define GLOBL_FN(x) GLOBL x'
77 print '#endif'
78 print ''
79 print '#if defined(PTHREADS) || defined(USE_XTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
80 print '# define THREADS'
81 print '#endif'
82 print ''
83 print '#ifdef GLX_USE_TLS'
84 print ''
85 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
86 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
87 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
88 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
89 print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
90 print '\tNOP ;\t\t\t\t\t\t\\'
91 print '\tJMP(GL_OFFSET(off))'
92 print ''
93 print '#elif defined(PTHREADS)'
94 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
95 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
96 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
97 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
98 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
99 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
100 print '\tJE(1f) ;\t\t\t\t\t\\'
101 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
102 print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
103 print '\tJMP(GL_OFFSET(off))'
104 print '#elif defined(THREADS)'
105 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
106 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
107 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
108 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
109 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
110 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
111 print '\tJE(1f) ;\t\t\t\t\t\\'
112 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
113 print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
114 print '\tJMP(GL_OFFSET(off))'
115 print '#else /* Non-threaded version. */'
116 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
117 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
118 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
119 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
120 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
121 print '\tJMP(GL_OFFSET(off))'
122 print '#endif'
123 print ''
124 print '#ifdef HAVE_ALIAS'
125 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
126 print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
127 print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
128 print '#else'
129 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
130 print ' GL_STUB(fn, off, fn_alt)'
131 print '#endif'
132 print ''
133 print 'SEG_TEXT'
134 print ''
135 print '#ifdef GLX_USE_TLS'
136 print ''
137 print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
138 print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
139 print 'ALIGNTEXT16'
140 print 'GLNAME(_x86_get_dispatch):'
141 print '\tmovl\t%gs:_glapi_tls_Dispatch@NTPOFF, %eax'
142 print '\tret'
143 print ''
144 print '#elif defined(PTHREADS)'
145 print 'EXTERN GLNAME(_glapi_Dispatch)'
146 print 'EXTERN GLNAME(_gl_DispatchTSD)'
147 print 'EXTERN GLNAME(pthread_getspecific)'
148 print ''
149 print 'ALIGNTEXT16'
150 print 'GLNAME(_x86_get_dispatch):'
151 print '\tSUB_L(CONST(24), ESP)'
152 print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
153 print '\tCALL(GLNAME(pthread_getspecific))'
154 print '\tADD_L(CONST(28), ESP)'
155 print '\tRET'
156 print '#elif defined(THREADS)'
157 print 'EXTERN GLNAME(_glapi_get_dispatch)'
158 print '#endif'
159 print ''
160
161 print '#if defined( GLX_USE_TLS )'
162 print '\t\t.section\twtext, "awx", @progbits'
163 print '#endif /* defined( GLX_USE_TLS ) */'
164
165 print ''
166 print '\t\tALIGNTEXT16'
167 print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
168 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
169 print 'GLNAME(gl_dispatch_functions_start):'
170 print ''
171 return
172
173
174 def printRealFooter(self):
175 print ''
176 print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
177 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
178 print '\t\tALIGNTEXT16'
179 print 'GLNAME(gl_dispatch_functions_end):'
180 print ''
181 print '#if defined(GLX_USE_TLS) && defined(__linux__)'
182 print ' .section ".note.ABI-tag", "a"'
183 print ' .p2align 2'
184 print ' .long 1f - 0f /* name length */'
185 print ' .long 3f - 2f /* data length */'
186 print ' .long 1 /* note length */'
187 print '0: .asciz "GNU" /* vendor name */'
188 print '1: .p2align 2'
189 print '2: .long 0 /* note data: the ABI tag */'
190 print ' .long 2,4,20 /* Minimum kernel version w/TLS */'
191 print '3: .p2align 2 /* pad out section */'
192 print '#endif /* GLX_USE_TLS */'
193 print ''
194 print '#if defined (__ELF__) && defined (__linux__)'
195 print ' .section .note.GNU-stack,"",%progbits'
196 print '#endif'
197 return
198
199
200 def printBody(self, api):
201 for f in api.functionIterateByOffset():
202 name = f.dispatch_name()
203 stack = self.get_stack_size(f)
204 alt = "%s@%u" % (name, stack)
205
206 print '\tGL_STUB(%s, _gloffset_%s, %s)' % (name, f.name, alt)
207
208 if not f.is_static_entry_point(f.name):
209 print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt)
210
211
212 for f in api.functionIterateByOffset():
213 name = f.dispatch_name()
214 stack = self.get_stack_size(f)
215 alt = "%s@%u" % (name, stack)
216
217 if f.is_static_entry_point(f.name):
218 for n in f.entry_points:
219 if n != f.name:
220 alt2 = "%s@%u" % (n, stack)
221 text = '\tGL_STUB_ALIAS(%s, _gloffset_%s, %s, %s, %s)' % (n, f.name, alt2, f.name, alt)
222
223 if f.has_different_protocol(n):
224 print '#ifndef GLX_INDIRECT_RENDERING'
225 print text
226 print '#endif'
227 else:
228 print text
229
230 return
231
232 def show_usage():
233 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
234 sys.exit(1)
235
236 if __name__ == '__main__':
237 file_name = "gl_API.xml"
238 mode = "generic"
239
240 try:
241 (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
242 except Exception,e:
243 show_usage()
244
245 for (arg,val) in args:
246 if arg == '-m':
247 mode = val
248 elif arg == "-f":
249 file_name = val
250
251 if mode == "generic":
252 printer = PrintGenericStubs()
253 else:
254 print "ERROR: Invalid mode \"%s\" specified." % mode
255 show_usage()
256
257 api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
258 printer.Print(api)