3 # (C) Copyright IBM Corporation 2004, 2005
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:
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
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
26 # Ian Romanick <idr@us.ibm.com>
32 class PrintGenericStubs(gl_XML
.FilterGLAPISpecBase
):
33 name
= "gl_x86_asm.py (from Mesa)"
36 gl_XML
.FilterGLAPISpecBase
.__init
__(self
)
37 self
.license
= license
.bsd_license_template
% ( \
38 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
39 (C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM")
42 def get_stack_size(self
, f
):
44 for p
in f
.parameterIterator():
47 if p
.is_array() or t
.size
!= 8:
54 def printRealHeader(self
):
55 print '#include "assyntax.h"'
56 print '#include "glapioffsets.h"'
58 print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change"
59 print "* the symbol visibility mode to 'default'."
61 print '#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303'
62 print '# pragma GCC visibility push(default)'
63 print '# define HIDDEN(x) .hidden x'
65 print '# define HIDDEN(x)'
68 print '#ifndef __WIN32__'
70 print '#if defined(STDCALL_API)'
71 print '# if defined(USE_MGL_NAMESPACE)'
72 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
74 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
77 print '# if defined(USE_MGL_NAMESPACE)'
78 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
80 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
84 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
86 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
87 print '#define GLOBL_FN(x) GLOBL x ; .type x, function'
89 print '#define GLOBL_FN(x) GLOBL x'
92 print '#if defined(PTHREADS) || defined(XTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
93 print '# define THREADS'
96 print '#ifdef GLX_USE_TLS'
98 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
99 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
100 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
101 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
102 print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
103 print '\tNOP ;\t\t\t\t\t\t\\'
104 print '\tJMP(GL_OFFSET(off))'
106 print '#elif defined(PTHREADS)'
107 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
108 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
109 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
110 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
111 print '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
112 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
113 print '\tJE(1f) ;\t\t\t\t\t\\'
114 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
115 print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
116 print '\tJMP(GL_OFFSET(off))'
117 print '#elif defined(THREADS)'
118 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
119 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
120 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
121 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
122 print '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
123 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
124 print '\tJE(1f) ;\t\t\t\t\t\\'
125 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
126 print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
127 print '\tJMP(GL_OFFSET(off))'
128 print '#else /* Non-threaded version. */'
129 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
130 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
131 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
132 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
133 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
134 print '\tJMP(GL_OFFSET(off))'
137 print '#ifdef HAVE_ALIAS'
138 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
139 print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
140 print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
142 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
143 print ' GL_STUB(fn, off, fn_alt)'
148 print '#ifdef GLX_USE_TLS'
150 print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
151 print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
153 print 'GLNAME(_x86_get_dispatch):'
154 print '\tmovl\t%gs:_glapi_tls_Dispatch@NTPOFF, %eax'
157 print '#elif defined(PTHREADS)'
158 print 'EXTERN GLNAME(_glapi_Dispatch)'
159 print 'EXTERN GLNAME(_gl_DispatchTSD)'
160 print 'EXTERN GLNAME(pthread_getspecific)'
163 print 'GLNAME(_x86_get_dispatch):'
164 print '\tSUB_L(CONST(24), ESP)'
165 print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
166 print '\tCALL(GLNAME(pthread_getspecific))'
167 print '\tADD_L(CONST(28), ESP)'
169 print '#elif defined(THREADS)'
170 print 'EXTERN GLNAME(_glapi_get_dispatch)'
174 print '#if defined( GLX_USE_TLS )'
175 print '\t\t.section\twtext, "awx", @progbits'
176 print '#endif /* defined( GLX_USE_TLS ) */'
179 print '\t\tALIGNTEXT16'
180 print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
181 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
182 print 'GLNAME(gl_dispatch_functions_start):'
186 def printRealFooter(self
):
188 print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
189 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
190 print '\t\tALIGNTEXT16'
191 print 'GLNAME(gl_dispatch_functions_end):'
193 print '#if defined(GLX_USE_TLS) && defined(__linux__)'
194 print ' .section ".note.ABI-tag", "a"'
196 print ' .long 1f - 0f /* name length */'
197 print ' .long 3f - 2f /* data length */'
198 print ' .long 1 /* note length */'
199 print '0: .asciz "GNU" /* vendor name */'
200 print '1: .p2align 2'
201 print '2: .long 0 /* note data: the ABI tag */'
202 print ' .long 2,4,20 /* Minimum kernel version w/TLS */'
203 print '3: .p2align 2 /* pad out section */'
204 print '#endif /* GLX_USE_TLS */'
206 print '#endif /* __WIN32__ */'
209 def printFunction(self
, f
):
210 stack
= self
.get_stack_size(f
)
212 alt
= "%s@%u" % (f
.name
, stack
)
213 if f
.fn_alias
== None:
214 print '\tGL_STUB(%s, _gloffset_%s, %s)' % (f
.name
, f
.real_name
, alt
)
216 alias_alt
= "%s@%u" % (f
.real_name
, stack
)
217 print '\tGL_STUB_ALIAS(%s, _gloffset_%s, %s, %s, %s)' % \
218 (f
.name
, f
.real_name
, alt
, f
.real_name
, alias_alt
)
222 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys
.argv
[0]
225 if __name__
== '__main__':
226 file_name
= "gl_API.xml"
230 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "m:f:")
234 for (arg
,val
) in args
:
240 if mode
== "generic":
241 dh
= PrintGenericStubs()
243 print "ERROR: Invalid mode \"%s\" specified." % mode
246 gl_XML
.parse_GL_API( dh
, file_name
)