3 # (C) Copyright IBM Corporation 2004
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>
28 from xml
.sax
import saxutils
29 from xml
.sax
import make_parser
30 from xml
.sax
.handler
import feature_namespaces
36 class PrintGenericStubs(gl_XML
.FilterGLAPISpecBase
):
37 name
= "gl_x86_asm.py (from Mesa)"
40 gl_XML
.FilterGLAPISpecBase
.__init
__(self
)
41 self
.license
= license
.bsd_license_template
% ( \
42 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
43 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
46 def get_stack_size(self
, f
):
48 for p
in f
.parameterIterator():
51 if p
.is_array() or t
.size
!= 8:
58 def printRealHeader(self
):
59 print '#include "assyntax.h"'
60 print '#include "glapioffsets.h"'
62 print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change"
63 print "* the symbol visibility mode to 'default'."
65 print '#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303'
66 print '#pragma GCC visibility push(default)'
69 print '#ifndef __WIN32__'
71 print '#if defined(STDCALL_API)'
72 print '# if defined(USE_MGL_NAMESPACE)'
73 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
75 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
78 print '# if defined(USE_MGL_NAMESPACE)'
79 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
81 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
85 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
87 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
88 print '#define GLOBL_FN(x) GLOBL x ; .type x, function'
90 print '#define GLOBL_FN(x) GLOBL x'
93 print '#if defined(PTHREADS) || defined(XTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
94 print '# define THREADS'
97 print '#if defined(PTHREADS)'
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 '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
103 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
104 print '\tJE(1f) ;\t\t\t\t\t\\'
105 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
106 print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
107 print '\tJMP(GL_OFFSET(off))'
108 print '#elif defined(THREADS)'
109 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
110 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
111 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
112 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
113 print '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
114 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
115 print '\tJE(1f) ;\t\t\t\t\t\\'
116 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
117 print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
118 print '\tJMP(GL_OFFSET(off))'
119 print '#else /* Non-threaded version. */'
120 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
121 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
122 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
123 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
124 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
125 print '\tJMP(GL_OFFSET(off))'
130 print '#ifdef PTHREADS'
131 print 'EXTERN GLNAME(_glapi_Dispatch)'
132 print 'EXTERN GLNAME(_gl_DispatchTSD)'
133 print 'EXTERN GLNAME(pthread_getspecific)'
136 print 'GLNAME(_x86_get_dispatch):'
137 print '\tSUB_L(CONST(24), ESP)'
138 print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
139 print '\tCALL(GLNAME(pthread_getspecific))'
140 print '\tADD_L(CONST(28), ESP)'
142 print '#elif defined(THREADS)'
143 print 'EXTERN GLNAME(_glapi_get_dispatch)'
146 print '\t\tALIGNTEXT16 ; GLOBL GLNAME(gl_dispatch_functions_start)'
147 print 'GLNAME(gl_dispatch_functions_start):'
151 def printRealFooter(self
):
153 print '#endif /* __WIN32__ */'
156 def printFunction(self
, f
):
157 stack
= self
.get_stack_size(f
)
159 alt
= "%s@%u" % (f
.name
, stack
)
160 print '\tGL_STUB(%s, _gloffset_%s, %s)' % (f
.name
, f
.real_name
, alt
)
164 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys
.argv
[0]
167 if __name__
== '__main__':
168 file_name
= "gl_API.xml"
172 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "m:f:")
176 for (arg
,val
) in args
:
182 if mode
== "generic":
183 dh
= PrintGenericStubs()
185 print "ERROR: Invalid mode \"%s\" specified." % mode
188 parser
= make_parser()
189 parser
.setFeature(feature_namespaces
, 0)
190 parser
.setContentHandler(dh
)